|
1 | 1 | import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime"; |
| 2 | +import { |
| 3 | +asDateTimestampMs, |
| 4 | +resolveExpiresAtMsFromDurationMs, |
| 5 | +} from "openclaw/plugin-sdk/number-runtime"; |
2 | 6 | import { raceWithTimeoutAndAbort } from "./async.js"; |
3 | 7 | import { createFeishuClient, type FeishuClientCredentials } from "./client.js"; |
4 | 8 | import type { FeishuProbeResult } from "./types.js"; |
@@ -38,7 +42,12 @@ function setCachedProbeResult(
|
38 | 42 | result: FeishuProbeResult, |
39 | 43 | ttlMs: number, |
40 | 44 | ): FeishuProbeResult { |
41 | | -probeCache.set(cacheKey, { result, expiresAt: Date.now() + ttlMs }); |
| 45 | +const expiresAt = resolveExpiresAtMsFromDurationMs(ttlMs); |
| 46 | +if (expiresAt === undefined) { |
| 47 | +probeCache.delete(cacheKey); |
| 48 | +return result; |
| 49 | +} |
| 50 | +probeCache.set(cacheKey, { result, expiresAt }); |
42 | 51 | if (probeCache.size > MAX_PROBE_CACHE_SIZE) { |
43 | 52 | const oldest = probeCache.keys().next().value; |
44 | 53 | if (oldest !== undefined) { |
@@ -74,8 +83,13 @@ export async function probeFeishu(
|
74 | 83 | // pollute each other's cache entry. |
75 | 84 | const cacheKey = creds.accountId ?? `${creds.appId}:${creds.appSecret.slice(0, 8)}`; |
76 | 85 | const cached = probeCache.get(cacheKey); |
77 | | -if (cached && cached.expiresAt > Date.now()) { |
78 | | -return cached.result; |
| 86 | +if (cached) { |
| 87 | +const now = asDateTimestampMs(Date.now()); |
| 88 | +const expiresAt = asDateTimestampMs(cached.expiresAt); |
| 89 | +if (now !== undefined && expiresAt !== undefined && expiresAt > now) { |
| 90 | +return cached.result; |
| 91 | +} |
| 92 | +probeCache.delete(cacheKey); |
79 | 93 | } |
80 | 94 | |
81 | 95 | try { |
|