@mulingai-npm/redis 3.29.2 → 3.29.4

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.
@@ -18,6 +18,7 @@ export type StreamingChunkData = {
18
18
  export type MulingstreamChunkData = {
19
19
  chunkId: string;
20
20
  roomId: string;
21
+ userId: string;
21
22
  chunkNumber: number;
22
23
  language: string;
23
24
  targetLanguages: string[];
@@ -39,6 +40,8 @@ export type MulingstreamChunkData = {
39
40
  duration?: number;
40
41
  };
41
42
  };
43
+ isComplete: boolean;
44
+ isSaved: boolean;
42
45
  };
43
46
  export declare class MulingstreamChunkManager {
44
47
  private redisClient;
@@ -60,6 +63,7 @@ export declare class MulingstreamChunkManager {
60
63
  */
61
64
  addStreamingChunk(params: {
62
65
  roomId: string;
66
+ userId: string;
63
67
  chunkNumber: number;
64
68
  language: string;
65
69
  transcription: string;
@@ -96,6 +100,26 @@ export declare class MulingstreamChunkManager {
96
100
  duration?: number;
97
101
  }): Promise<MulingstreamChunkData | null>;
98
102
  areTranslationsProcessed(roomId: string, n: number): Promise<boolean>;
103
+ /**
104
+ * Check if all TTS for all target languages are done (READY, USED, or DISCARDED - not INIT)
105
+ */
106
+ isChunkComplete(roomId: string, n: number): Promise<boolean>;
107
+ /**
108
+ * Mark a chunk as complete (all TTS finished for all target languages)
109
+ */
110
+ markChunkComplete(roomId: string, n: number): Promise<MulingstreamChunkData | null>;
111
+ /**
112
+ * Mark a chunk as saved to database
113
+ */
114
+ markChunkSaved(roomId: string, n: number): Promise<MulingstreamChunkData | null>;
115
+ /**
116
+ * Get all complete but unsaved chunks for a room
117
+ */
118
+ getCompleteUnsavedChunks(roomId: string): Promise<MulingstreamChunkData[]>;
119
+ /**
120
+ * Mark multiple chunks as saved in batch
121
+ */
122
+ markChunksSaved(roomId: string, chunkNumbers: number[]): Promise<void>;
99
123
  /**
100
124
  * @deprecated This function is replaced by ChunkSequencer (5-sequencer-handler.ts)
101
125
  *
@@ -27,6 +27,7 @@ class MulingstreamChunkManager {
27
27
  return {
28
28
  chunkId: h.chunkId,
29
29
  roomId: h.roomId,
30
+ userId: h.userId,
30
31
  chunkNumber: parseInt(h.chunkNumber, 10),
31
32
  language: h.language,
32
33
  targetLanguages: this.deserialize(h.targetLanguages),
@@ -35,7 +36,9 @@ class MulingstreamChunkManager {
35
36
  createdAt: parseInt(h.createdAt, 10),
36
37
  streamingChunk: this.deserialize(h.streamingChunk),
37
38
  translation: this.deserialize(h.translation),
38
- tts: this.deserialize(h.tts)
39
+ tts: this.deserialize(h.tts),
40
+ isComplete: h.isComplete === 'true',
41
+ isSaved: h.isSaved === 'true'
39
42
  };
40
43
  }
41
44
  getTimeout() {
@@ -72,7 +75,7 @@ class MulingstreamChunkManager {
72
75
  */
73
76
  async addStreamingChunk(params) {
74
77
  var _a, _b;
75
- const { roomId, chunkNumber, language, transcription, sttProvider, targetLanguages, shortCodeTargetLanguages, streamingData } = params;
78
+ const { roomId, userId, chunkNumber, language, transcription, sttProvider, targetLanguages, shortCodeTargetLanguages, streamingData } = params;
76
79
  // Clear room if this is first chunk (new session)
77
80
  if (chunkNumber === 1) {
78
81
  const old = await this.redisClient.zrange(this.roomZsetKey(roomId), 0, -1);
@@ -116,6 +119,7 @@ class MulingstreamChunkManager {
116
119
  const chunk = {
117
120
  chunkId,
118
121
  roomId,
122
+ userId,
119
123
  chunkNumber,
120
124
  language,
121
125
  targetLanguages,
@@ -124,11 +128,14 @@ class MulingstreamChunkManager {
124
128
  createdAt,
125
129
  streamingChunk,
126
130
  translation,
127
- tts
131
+ tts,
132
+ isComplete: false,
133
+ isSaved: false
128
134
  };
129
135
  const hash = {
130
136
  chunkId,
131
137
  roomId,
138
+ userId,
132
139
  chunkNumber: String(chunkNumber),
133
140
  language,
134
141
  targetLanguages: this.serialize(targetLanguages),
@@ -137,7 +144,9 @@ class MulingstreamChunkManager {
137
144
  createdAt: String(createdAt),
138
145
  streamingChunk: this.serialize(streamingChunk),
139
146
  translation: this.serialize(translation),
140
- tts: this.serialize(tts)
147
+ tts: this.serialize(tts),
148
+ isComplete: 'false',
149
+ isSaved: 'false'
141
150
  };
142
151
  const pipe = this.redisClient.pipeline();
143
152
  pipe.hset(this.chunkHashKey(chunkId), hash);
@@ -185,7 +194,9 @@ class MulingstreamChunkManager {
185
194
  finalTranscription: chunk.finalTranscription,
186
195
  translation: this.serialize(chunk.translation),
187
196
  tts: this.serialize(chunk.tts),
188
- streamingChunk: this.serialize(chunk.streamingChunk)
197
+ streamingChunk: this.serialize(chunk.streamingChunk),
198
+ isComplete: String(chunk.isComplete),
199
+ isSaved: String(chunk.isSaved)
189
200
  });
190
201
  p.expire(key, EXPIRATION);
191
202
  await p.exec();
@@ -259,6 +270,47 @@ class MulingstreamChunkManager {
259
270
  const c = await this.getMulingstreamChunkById(roomId, n);
260
271
  return !!c && Object.values(c.translation).every((t) => t.status !== 'INIT');
261
272
  }
273
+ /**
274
+ * Check if all TTS for all target languages are done (READY, USED, or DISCARDED - not INIT)
275
+ */
276
+ async isChunkComplete(roomId, n) {
277
+ const c = await this.getMulingstreamChunkById(roomId, n);
278
+ if (!c)
279
+ return false;
280
+ return Object.values(c.tts).every((t) => t.status !== 'INIT');
281
+ }
282
+ /**
283
+ * Mark a chunk as complete (all TTS finished for all target languages)
284
+ */
285
+ async markChunkComplete(roomId, n) {
286
+ return this.withChunk(roomId, n, (c) => {
287
+ c.isComplete = true;
288
+ });
289
+ }
290
+ /**
291
+ * Mark a chunk as saved to database
292
+ */
293
+ async markChunkSaved(roomId, n) {
294
+ return this.withChunk(roomId, n, (c) => {
295
+ c.isSaved = true;
296
+ });
297
+ }
298
+ /**
299
+ * Get all complete but unsaved chunks for a room
300
+ */
301
+ async getCompleteUnsavedChunks(roomId) {
302
+ var _a;
303
+ const chunks = (_a = (await this.getMulingstreamChunksByRoom(roomId))) !== null && _a !== void 0 ? _a : [];
304
+ return chunks.filter((c) => c.isComplete && !c.isSaved);
305
+ }
306
+ /**
307
+ * Mark multiple chunks as saved in batch
308
+ */
309
+ async markChunksSaved(roomId, chunkNumbers) {
310
+ for (const n of chunkNumbers) {
311
+ await this.markChunkSaved(roomId, n);
312
+ }
313
+ }
262
314
  /**
263
315
  * @deprecated This function is replaced by ChunkSequencer (5-sequencer-handler.ts)
264
316
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "3.29.2",
3
+ "version": "3.29.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {