@mulingai-npm/redis 2.5.6 → 2.7.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.
@@ -92,7 +92,10 @@ export declare class MulingstreamChunkManager {
92
92
  status: StepStatus;
93
93
  }>): Promise<boolean>;
94
94
  discardStt(roomId: string, chunkNumber: number): Promise<boolean>;
95
- updateFinalTranscription(roomId: string, chunkNumber: number, transcription: string, sttStatus: StepStatus): Promise<MulingstreamChunkData | null>;
95
+ updateFinalTranscription(roomId: string, chunkNumber: number, options: {
96
+ transcription?: string;
97
+ sttStatus?: StepStatus;
98
+ }): Promise<MulingstreamChunkData | null>;
96
99
  /**
97
100
  * Discards all post-STT steps for a given chunk:
98
101
  * sets all translation[].status & tts[].status to "DISCARDED".
@@ -105,6 +108,12 @@ export declare class MulingstreamChunkManager {
105
108
  updateTranslation(roomId: string, chunkNumber: number, language: string, options: {
106
109
  translation?: string;
107
110
  status?: StepStatus;
108
- }): Promise<boolean>;
111
+ }): Promise<MulingstreamChunkData | null>;
109
112
  updateTranslationInBulk(roomId: string, chunkNumber: number, translations: Record<string, string>, status?: StepStatus): Promise<MulingstreamChunkData | null>;
113
+ updateTts(roomId: string, chunkNumber: number, language: string, options: {
114
+ ttsAudioPath?: string;
115
+ status?: StepStatus;
116
+ isEmitted?: boolean;
117
+ }): Promise<MulingstreamChunkData | null>;
118
+ areTranslationsProcessed(roomId: string, chunkNumber: number): Promise<boolean>;
110
119
  }
@@ -193,19 +193,23 @@ class MulingstreamChunkManager {
193
193
  await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
194
194
  return true;
195
195
  }
196
- async updateFinalTranscription(roomId, chunkNumber, transcription, sttStatus) {
196
+ async updateFinalTranscription(roomId, chunkNumber, options) {
197
+ // 1) fetch room’s chunks
197
198
  const chunks = await this.getMulingstreamChunksByRoom(roomId);
198
- if (!chunks) {
199
+ if (!chunks)
199
200
  return null;
200
- }
201
- // locate the chunk
201
+ // 2) locate the chunk
202
202
  const idx = chunks.findIndex((c) => c.chunkNumber === chunkNumber);
203
- if (idx === -1) {
203
+ if (idx === -1)
204
204
  return null;
205
+ // 3) apply updates only when the key is present
206
+ if (options.transcription !== undefined) {
207
+ chunks[idx].finalTranscription = options.transcription;
208
+ }
209
+ if (options.sttStatus !== undefined) {
210
+ chunks[idx].sttStatus = options.sttStatus;
205
211
  }
206
- // update fields
207
- chunks[idx].finalTranscription = transcription;
208
- chunks[idx].sttStatus = sttStatus;
212
+ // 4) persist and return
209
213
  await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
210
214
  return chunks[idx];
211
215
  }
@@ -255,29 +259,29 @@ class MulingstreamChunkManager {
255
259
  return true;
256
260
  }
257
261
  async updateTranslation(roomId, chunkNumber, language, options) {
258
- // Fetch all chunks for this room
262
+ // 1) fetch the room’s chunks
259
263
  const chunks = await this.getMulingstreamChunksByRoom(roomId);
260
264
  if (!chunks)
261
- return false;
262
- // Locate the target chunk
263
- const chunkIndex = chunks.findIndex((c) => c.chunkNumber === chunkNumber);
264
- if (chunkIndex === -1)
265
- return false;
266
- const chunk = chunks[chunkIndex];
267
- // Make sure the requested language exists in this chunk
268
- if (!chunk.translation[language]) {
269
- return false;
270
- }
265
+ return null;
266
+ // 2) locate the chunk
267
+ const idx = chunks.findIndex((c) => c.chunkNumber === chunkNumber);
268
+ if (idx === -1)
269
+ return null;
270
+ const chunk = chunks[idx];
271
+ // 3) ensure the requested language exists
272
+ if (!chunk.translation[language])
273
+ return null;
274
+ // 4) apply updates only for provided keys
271
275
  if (options.translation !== undefined) {
272
276
  chunk.translation[language].translation = options.translation;
273
277
  }
274
278
  if (options.status !== undefined) {
275
279
  chunk.translation[language].status = options.status;
276
280
  }
277
- // Persist the whole array back to Redis
278
- chunks[chunkIndex] = chunk;
281
+ // 5) persist and return
282
+ chunks[idx] = chunk;
279
283
  await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
280
- return true;
284
+ return chunk;
281
285
  }
282
286
  async updateTranslationInBulk(roomId, chunkNumber, translations, status = 'READY') {
283
287
  // 1) fetch the room array
@@ -304,5 +308,40 @@ class MulingstreamChunkManager {
304
308
  await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
305
309
  return chunk;
306
310
  }
311
+ async updateTts(roomId, chunkNumber, language, options) {
312
+ // 1) fetch the room’s chunks
313
+ const chunks = await this.getMulingstreamChunksByRoom(roomId);
314
+ if (!chunks)
315
+ return null;
316
+ // 2) locate the chunk
317
+ const idx = chunks.findIndex((c) => c.chunkNumber === chunkNumber);
318
+ if (idx === -1)
319
+ return null;
320
+ const chunk = chunks[idx];
321
+ // 3) ensure the language exists in the TTS map
322
+ if (!chunk.tts[language])
323
+ return null;
324
+ // 4) apply only the provided keys
325
+ if (options.ttsAudioPath !== undefined) {
326
+ chunk.tts[language].ttsAudioPath = options.ttsAudioPath;
327
+ }
328
+ if (options.status !== undefined) {
329
+ chunk.tts[language].status = options.status;
330
+ }
331
+ if (options.isEmitted !== undefined) {
332
+ chunk.tts[language].isEmitted = options.isEmitted;
333
+ }
334
+ // 5) persist and return the updated chunk
335
+ chunks[idx] = chunk;
336
+ await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
337
+ return chunk;
338
+ }
339
+ async areTranslationsProcessed(roomId, chunkNumber) {
340
+ const chunk = await this.getMulingstreamChunkById(roomId, chunkNumber);
341
+ if (!chunk) {
342
+ return false;
343
+ }
344
+ return Object.values(chunk.translation).every((t) => t.status !== 'INIT');
345
+ }
307
346
  }
308
347
  exports.MulingstreamChunkManager = MulingstreamChunkManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "2.5.6",
3
+ "version": "2.7.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {