@mulingai-npm/redis 2.9.0 → 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,
@@ -260,7 +261,7 @@ class MulingstreamChunkManager {
260
261
  return true;
261
262
  }
262
263
  async discardLanguages(roomId, chunkNumber, options) {
263
- // 1) fetch the room’s chunks
264
+ // 1) fetch room’s chunks
264
265
  const chunks = await this.getMulingstreamChunksByRoom(roomId);
265
266
  if (!chunks)
266
267
  return null;
@@ -269,19 +270,21 @@ class MulingstreamChunkManager {
269
270
  if (idx === -1)
270
271
  return null;
271
272
  const chunk = chunks[idx];
272
- // 3) discard the requested translation languages
273
+ // 3) discard translation languages still in INIT
273
274
  if (options.translation) {
274
275
  for (const lang of options.translation) {
275
- if (chunk.translation[lang]) {
276
- chunk.translation[lang].status = 'DISCARDED';
276
+ const entry = chunk.translation[lang];
277
+ if (entry && entry.status === 'INIT') {
278
+ entry.status = 'DISCARDED';
277
279
  }
278
280
  }
279
281
  }
280
- // 4) discard the requested TTS languages
282
+ // 4) discard TTS languages still in INIT
281
283
  if (options.tts) {
282
284
  for (const lang of options.tts) {
283
- if (chunk.tts[lang]) {
284
- chunk.tts[lang].status = 'DISCARDED';
285
+ const entry = chunk.tts[lang];
286
+ if (entry && entry.status === 'INIT') {
287
+ entry.status = 'DISCARDED';
285
288
  }
286
289
  }
287
290
  }
@@ -396,5 +399,64 @@ class MulingstreamChunkManager {
396
399
  }
397
400
  return Object.values(chunk.translation).every((t) => t.status !== 'INIT');
398
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
+ }
399
461
  }
400
462
  exports.MulingstreamChunkManager = MulingstreamChunkManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "2.9.0",
3
+ "version": "2.10.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {