@mulingai-npm/redis 3.40.1 → 3.40.2
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.
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Enhancer Manager
|
|
3
|
+
*
|
|
4
|
+
* Stores user-provided context text (sermon scripts, presentation notes) in Redis.
|
|
5
|
+
* The text is injected into the SmartTranslation LLM prompt (Block 8) during streaming
|
|
6
|
+
* to improve translation quality and transcription correction.
|
|
7
|
+
*
|
|
8
|
+
* Redis key: smarttranslate:context-enhancer:{roomId}
|
|
9
|
+
* Type: String (raw text, up to 15,000 chars)
|
|
10
|
+
* TTL: 36 hours (covers "prep day before" use case)
|
|
11
|
+
*/
|
|
12
|
+
import { RedisClient } from '../redis-client';
|
|
13
|
+
export declare class ContextEnhancerManager {
|
|
14
|
+
private redisClient;
|
|
15
|
+
constructor(redisClient: RedisClient);
|
|
16
|
+
private key;
|
|
17
|
+
/** Save context text for a room. Truncates to MAX_CHARS. */
|
|
18
|
+
saveContext(roomId: string | number, text: string): Promise<void>;
|
|
19
|
+
/** Get context text for a room. Returns null if expired or not set. */
|
|
20
|
+
getContext(roomId: string | number): Promise<string | null>;
|
|
21
|
+
/** Delete context text for a room. */
|
|
22
|
+
deleteContext(roomId: string | number): Promise<void>;
|
|
23
|
+
/** Check if context text exists for a room (not expired). */
|
|
24
|
+
hasContext(roomId: string | number): Promise<boolean>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Context Enhancer Manager
|
|
4
|
+
*
|
|
5
|
+
* Stores user-provided context text (sermon scripts, presentation notes) in Redis.
|
|
6
|
+
* The text is injected into the SmartTranslation LLM prompt (Block 8) during streaming
|
|
7
|
+
* to improve translation quality and transcription correction.
|
|
8
|
+
*
|
|
9
|
+
* Redis key: smarttranslate:context-enhancer:{roomId}
|
|
10
|
+
* Type: String (raw text, up to 15,000 chars)
|
|
11
|
+
* TTL: 36 hours (covers "prep day before" use case)
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.ContextEnhancerManager = void 0;
|
|
15
|
+
const CONTEXT_ENHANCER_TTL = 36 * 60 * 60; // 36 hours
|
|
16
|
+
const MAX_CHARS = 15000;
|
|
17
|
+
class ContextEnhancerManager {
|
|
18
|
+
constructor(redisClient) {
|
|
19
|
+
this.redisClient = redisClient;
|
|
20
|
+
}
|
|
21
|
+
key(roomId) {
|
|
22
|
+
return `smarttranslate:context-enhancer:${roomId}`;
|
|
23
|
+
}
|
|
24
|
+
/** Save context text for a room. Truncates to MAX_CHARS. */
|
|
25
|
+
async saveContext(roomId, text) {
|
|
26
|
+
const truncated = text.slice(0, MAX_CHARS);
|
|
27
|
+
const key = this.key(roomId);
|
|
28
|
+
await this.redisClient.set(key, truncated);
|
|
29
|
+
await this.redisClient.expire(key, CONTEXT_ENHANCER_TTL);
|
|
30
|
+
}
|
|
31
|
+
/** Get context text for a room. Returns null if expired or not set. */
|
|
32
|
+
async getContext(roomId) {
|
|
33
|
+
return this.redisClient.get(this.key(roomId));
|
|
34
|
+
}
|
|
35
|
+
/** Delete context text for a room. */
|
|
36
|
+
async deleteContext(roomId) {
|
|
37
|
+
await this.redisClient.del(this.key(roomId));
|
|
38
|
+
}
|
|
39
|
+
/** Check if context text exists for a room (not expired). */
|
|
40
|
+
async hasContext(roomId) {
|
|
41
|
+
const exists = await this.redisClient.exists(this.key(roomId));
|
|
42
|
+
return exists === 1;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.ContextEnhancerManager = ContextEnhancerManager;
|