@mulingai-npm/redis 3.40.4 → 3.40.6

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.
@@ -19,15 +19,14 @@ export interface ContextEnhancerResult {
19
19
  export declare class ContextEnhancerManager {
20
20
  private redisClient;
21
21
  private ttlSeconds;
22
- constructor(redisClient: RedisClient, environment?: string);
22
+ constructor(redisClient: RedisClient);
23
23
  private key;
24
24
  /** Get TTL configured for this environment (in seconds) */
25
25
  getTtlSeconds(): number;
26
- /** Save context text for a room. Truncates to MAX_CHARS. Returns false if cooldown active. */
27
- saveContext(roomId: string | number, text: string): Promise<{
28
- saved: boolean;
29
- cooldownRemaining?: number;
30
- }>;
26
+ /** Check cooldown. Returns remaining seconds (0 = no cooldown). */
27
+ getCooldownRemaining(roomId: string | number): Promise<number>;
28
+ /** Save context text for a room. Truncates to MAX_CHARS. Call getCooldownRemaining() first. */
29
+ saveContext(roomId: string | number, text: string): Promise<void>;
31
30
  /** Get raw context data (internal). */
32
31
  private getContextData;
33
32
  /** Get context with metadata (text, savedAt, expiresAt, ttlSeconds). */
@@ -14,16 +14,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.ContextEnhancerManager = void 0;
15
15
  const MAX_CHARS = 15000;
16
16
  const COOLDOWN_SECONDS = 60; // 1 minute cooldown between saves
17
- // TTL by environment (seconds)
18
- const TTL_BY_ENV = {
19
- localhost: 15 * 60,
20
- development: 30 * 60,
21
- production: 36 * 60 * 60 // 36 hours
22
- };
17
+ // TTL: 36 hours for all environments (seconds)
18
+ const TTL_SECONDS = 36 * 60 * 60;
23
19
  class ContextEnhancerManager {
24
- constructor(redisClient, environment) {
20
+ constructor(redisClient) {
25
21
  this.redisClient = redisClient;
26
- this.ttlSeconds = TTL_BY_ENV[environment || 'production'] || TTL_BY_ENV.production;
22
+ this.ttlSeconds = TTL_SECONDS;
27
23
  }
28
24
  key(roomId) {
29
25
  return `smarttranslate:context-enhancer:${roomId}`;
@@ -32,25 +28,27 @@ class ContextEnhancerManager {
32
28
  getTtlSeconds() {
33
29
  return this.ttlSeconds;
34
30
  }
35
- /** Save context text for a room. Truncates to MAX_CHARS. Returns false if cooldown active. */
36
- async saveContext(roomId, text) {
37
- const key = this.key(roomId);
38
- // Check cooldown
31
+ /** Check cooldown. Returns remaining seconds (0 = no cooldown). */
32
+ async getCooldownRemaining(roomId) {
39
33
  const existing = await this.getContextData(roomId);
40
- if (existing) {
41
- const elapsedSeconds = (Date.now() - existing.savedAt) / 1000;
42
- if (elapsedSeconds < COOLDOWN_SECONDS) {
43
- return { saved: false, cooldownRemaining: Math.ceil(COOLDOWN_SECONDS - elapsedSeconds) };
44
- }
34
+ if (!existing)
35
+ return 0;
36
+ const elapsedSeconds = (Date.now() - existing.savedAt) / 1000;
37
+ if (elapsedSeconds < COOLDOWN_SECONDS) {
38
+ return Math.ceil(COOLDOWN_SECONDS - elapsedSeconds);
45
39
  }
40
+ return 0;
41
+ }
42
+ /** Save context text for a room. Truncates to MAX_CHARS. Call getCooldownRemaining() first. */
43
+ async saveContext(roomId, text) {
46
44
  const truncated = text.slice(0, MAX_CHARS);
47
45
  const data = {
48
46
  text: truncated,
49
47
  savedAt: Date.now()
50
48
  };
49
+ const key = this.key(roomId);
51
50
  await this.redisClient.set(key, JSON.stringify(data));
52
51
  await this.redisClient.expire(key, this.ttlSeconds);
53
- return { saved: true };
54
52
  }
55
53
  /** Get raw context data (internal). */
56
54
  async getContextData(roomId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "3.40.4",
3
+ "version": "3.40.6",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {