@@ -5,6 +5,10 @@ import {
|
5 | 5 | } from "@aws-sdk/client-bedrock"; |
6 | 6 | import { createSubsystemLogger } from "openclaw/plugin-sdk/core"; |
7 | 7 | import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime"; |
| 8 | +import { |
| 9 | +isFutureDateTimestampMs, |
| 10 | +resolveExpiresAtMsFromDurationSeconds, |
| 11 | +} from "openclaw/plugin-sdk/number-runtime"; |
8 | 12 | import type { |
9 | 13 | BedrockDiscoveryConfig, |
10 | 14 | ModelDefinitionConfig, |
@@ -503,11 +507,16 @@ export async function discoverBedrockModels(params: {
|
503 | 507 | |
504 | 508 | if (refreshIntervalSeconds > 0) { |
505 | 509 | const cached = discoveryCache.get(cacheKey); |
506 | | -if (cached?.value && cached.expiresAt > now) { |
507 | | -return cached.value; |
| 510 | +if (cached && isFutureDateTimestampMs(cached.expiresAt, { nowMs: now })) { |
| 511 | +if (cached.value) { |
| 512 | +return cached.value; |
| 513 | +} |
| 514 | +if (cached.inFlight) { |
| 515 | +return cached.inFlight; |
| 516 | +} |
508 | 517 | } |
509 | | -if (cached?.inFlight) { |
510 | | -return cached.inFlight; |
| 518 | +if (cached) { |
| 519 | +discoveryCache.delete(cacheKey); |
511 | 520 | } |
512 | 521 | } |
513 | 522 | |
@@ -581,19 +590,27 @@ export async function discoverBedrockModels(params: {
|
581 | 590 | })(); |
582 | 591 | |
583 | 592 | if (refreshIntervalSeconds > 0) { |
584 | | -discoveryCache.set(cacheKey, { |
585 | | -expiresAt: now + refreshIntervalSeconds * 1000, |
586 | | -inFlight: discoveryPromise, |
587 | | -}); |
| 593 | +const expiresAt = resolveExpiresAtMsFromDurationSeconds(refreshIntervalSeconds, { nowMs: now }); |
| 594 | +if (expiresAt !== undefined) { |
| 595 | +discoveryCache.set(cacheKey, { |
| 596 | + expiresAt, |
| 597 | +inFlight: discoveryPromise, |
| 598 | +}); |
| 599 | +} |
588 | 600 | } |
589 | 601 | |
590 | 602 | try { |
591 | 603 | const value = await discoveryPromise; |
592 | 604 | if (refreshIntervalSeconds > 0) { |
593 | | -discoveryCache.set(cacheKey, { |
594 | | -expiresAt: now + refreshIntervalSeconds * 1000, |
595 | | - value, |
| 605 | +const expiresAt = resolveExpiresAtMsFromDurationSeconds(refreshIntervalSeconds, { |
| 606 | +nowMs: now, |
596 | 607 | }); |
| 608 | +if (expiresAt !== undefined) { |
| 609 | +discoveryCache.set(cacheKey, { |
| 610 | + expiresAt, |
| 611 | + value, |
| 612 | +}); |
| 613 | +} |
597 | 614 | } |
598 | 615 | return value; |
599 | 616 | } catch (error) { |
|