@mulingai-npm/redis 3.40.4 → 3.40.5

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.
@@ -23,11 +23,10 @@ export declare class ContextEnhancerManager {
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). */
@@ -32,25 +32,27 @@ class ContextEnhancerManager {
32
32
  getTtlSeconds() {
33
33
  return this.ttlSeconds;
34
34
  }
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
35
+ /** Check cooldown. Returns remaining seconds (0 = no cooldown). */
36
+ async getCooldownRemaining(roomId) {
39
37
  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
- }
38
+ if (!existing)
39
+ return 0;
40
+ const elapsedSeconds = (Date.now() - existing.savedAt) / 1000;
41
+ if (elapsedSeconds < COOLDOWN_SECONDS) {
42
+ return Math.ceil(COOLDOWN_SECONDS - elapsedSeconds);
45
43
  }
44
+ return 0;
45
+ }
46
+ /** Save context text for a room. Truncates to MAX_CHARS. Call getCooldownRemaining() first. */
47
+ async saveContext(roomId, text) {
46
48
  const truncated = text.slice(0, MAX_CHARS);
47
49
  const data = {
48
50
  text: truncated,
49
51
  savedAt: Date.now()
50
52
  };
53
+ const key = this.key(roomId);
51
54
  await this.redisClient.set(key, JSON.stringify(data));
52
55
  await this.redisClient.expire(key, this.ttlSeconds);
53
- return { saved: true };
54
56
  }
55
57
  /** Get raw context data (internal). */
56
58
  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.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {