@mulingai-npm/redis 2.6.0 → 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 | null, sttStatus: StepStatus | null): 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,7 +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>;
110
118
  areTranslationsProcessed(roomId: string, chunkNumber: number): Promise<boolean>;
111
119
  }
@@ -193,22 +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
+ // 2) locate the chunk
201
202
  const idx = chunks.findIndex((c) => c.chunkNumber === chunkNumber);
202
- if (idx === -1) {
203
+ if (idx === -1)
203
204
  return null;
205
+ // 3) apply updates only when the key is present
206
+ if (options.transcription !== undefined) {
207
+ chunks[idx].finalTranscription = options.transcription;
204
208
  }
205
- // mutate only when a non-null value is supplied
206
- if (transcription !== null) {
207
- chunks[idx].finalTranscription = transcription;
208
- }
209
- if (sttStatus !== null) {
210
- chunks[idx].sttStatus = sttStatus;
209
+ if (options.sttStatus !== undefined) {
210
+ chunks[idx].sttStatus = options.sttStatus;
211
211
  }
212
+ // 4) persist and return
212
213
  await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
213
214
  return chunks[idx];
214
215
  }
@@ -258,29 +259,29 @@ class MulingstreamChunkManager {
258
259
  return true;
259
260
  }
260
261
  async updateTranslation(roomId, chunkNumber, language, options) {
261
- // Fetch all chunks for this room
262
+ // 1) fetch the room’s chunks
262
263
  const chunks = await this.getMulingstreamChunksByRoom(roomId);
263
264
  if (!chunks)
264
- return false;
265
- // Locate the target chunk
266
- const chunkIndex = chunks.findIndex((c) => c.chunkNumber === chunkNumber);
267
- if (chunkIndex === -1)
268
- return false;
269
- const chunk = chunks[chunkIndex];
270
- // Make sure the requested language exists in this chunk
271
- if (!chunk.translation[language]) {
272
- return false;
273
- }
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
274
275
  if (options.translation !== undefined) {
275
276
  chunk.translation[language].translation = options.translation;
276
277
  }
277
278
  if (options.status !== undefined) {
278
279
  chunk.translation[language].status = options.status;
279
280
  }
280
- // Persist the whole array back to Redis
281
- chunks[chunkIndex] = chunk;
281
+ // 5) persist and return
282
+ chunks[idx] = chunk;
282
283
  await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
283
- return true;
284
+ return chunk;
284
285
  }
285
286
  async updateTranslationInBulk(roomId, chunkNumber, translations, status = 'READY') {
286
287
  // 1) fetch the room array
@@ -307,6 +308,34 @@ class MulingstreamChunkManager {
307
308
  await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
308
309
  return chunk;
309
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
+ }
310
339
  async areTranslationsProcessed(roomId, chunkNumber) {
311
340
  const chunk = await this.getMulingstreamChunkById(roomId, chunkNumber);
312
341
  if (!chunk) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {