@clef-sh/agent 0.1.24-beta.166 → 0.1.24-beta.169

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.
package/dist/agent.cjs CHANGED
@@ -190837,6 +190837,11 @@ function resolveConfig(env = process.env) {
190837
190837
  // ../runtime/src/secrets-cache.ts
190838
190838
  var SecretsCache = class {
190839
190839
  snapshot = null;
190840
+ // Tracks the last successful refresh attempt, including no-op refreshes
190841
+ // where the source returned identical content. TTL is measured against
190842
+ // this — not against `swappedAt` — so a stable artifact doesn't cause
190843
+ // the cache to "expire" while polling is healthy.
190844
+ lastRefreshAt = null;
190840
190845
  /** Replace the cached secrets in a single reference assignment. */
190841
190846
  swap(values, revision) {
190842
190847
  if (this.snapshot) {
@@ -190848,12 +190853,23 @@ var SecretsCache = class {
190848
190853
  for (const [ns, bucket] of Object.entries(values)) {
190849
190854
  cloned[ns] = { ...bucket };
190850
190855
  }
190851
- this.snapshot = { values: cloned, revision, swappedAt: Date.now() };
190856
+ const now = Date.now();
190857
+ this.snapshot = { values: cloned, revision, swappedAt: now };
190858
+ this.lastRefreshAt = now;
190852
190859
  }
190853
- /** Whether the cache has exceeded the given TTL (seconds). */
190860
+ /**
190861
+ * Bump the freshness clock without touching cached values. Called by the
190862
+ * poller when a fetch succeeds but the artifact is unchanged (same content
190863
+ * hash or same revision) — proves the source is still reachable and the
190864
+ * cached secrets are still authoritative.
190865
+ */
190866
+ markFresh() {
190867
+ this.lastRefreshAt = Date.now();
190868
+ }
190869
+ /** Whether the last successful refresh has exceeded the given TTL (seconds). */
190854
190870
  isExpired(ttlSeconds) {
190855
- if (!this.snapshot) return false;
190856
- return (Date.now() - this.snapshot.swappedAt) / 1e3 > ttlSeconds;
190871
+ if (this.lastRefreshAt === null) return false;
190872
+ return (Date.now() - this.lastRefreshAt) / 1e3 > ttlSeconds;
190857
190873
  }
190858
190874
  /** Clear the cached snapshot, zeroing values first (best-effort). */
190859
190875
  wipe() {
@@ -190863,11 +190879,16 @@ var SecretsCache = class {
190863
190879
  }
190864
190880
  }
190865
190881
  this.snapshot = null;
190882
+ this.lastRefreshAt = null;
190866
190883
  }
190867
- /** Epoch ms when the cache was last swapped, or null if never loaded. */
190884
+ /** Epoch ms when the cache values last *changed*, or null if never loaded. */
190868
190885
  getSwappedAt() {
190869
190886
  return this.snapshot?.swappedAt ?? null;
190870
190887
  }
190888
+ /** Epoch ms of the last successful refresh attempt (incl. no-op), or null. */
190889
+ getLastRefreshAt() {
190890
+ return this.lastRefreshAt;
190891
+ }
190871
190892
  /**
190872
190893
  * Get a single secret value.
190873
190894
  *
@@ -193536,8 +193557,10 @@ var ArtifactPoller = class {
193536
193557
  */
193537
193558
  async fetchAndDecrypt() {
193538
193559
  const result = await this.fetchRaw();
193539
- if (!result) return;
193540
- await this.validateDecryptAndCache(result.artifact, result.contentHash);
193560
+ if (result) {
193561
+ await this.validateDecryptAndCache(result.artifact, result.contentHash);
193562
+ }
193563
+ this.options.cache.markFresh();
193541
193564
  }
193542
193565
  /**
193543
193566
  * Fetch and validate the artifact without decrypting.
@@ -193546,7 +193569,10 @@ var ArtifactPoller = class {
193546
193569
  */
193547
193570
  async fetchAndValidate() {
193548
193571
  const result = await this.fetchRaw();
193549
- if (!result) return;
193572
+ if (!result) {
193573
+ this.options.cache.markFresh();
193574
+ return;
193575
+ }
193550
193576
  const artifact = this.validateArtifact(result.artifact);
193551
193577
  this.options.encryptedStore.swap(artifact);
193552
193578
  this.lastRevision = artifact.revision;
@@ -194420,7 +194446,7 @@ function healthHandler(cache5, cacheTtl, encryptedStore) {
194420
194446
  status: "ok",
194421
194447
  mode: "cached",
194422
194448
  revision: cache5.getRevision(),
194423
- lastRefreshAt: cache5.getSwappedAt(),
194449
+ lastRefreshAt: cache5.getLastRefreshAt(),
194424
194450
  expired
194425
194451
  });
194426
194452
  }
@@ -194783,7 +194809,7 @@ async function initialFetch(poller, jitMode, encryptedStore, cache5, sourceDesc)
194783
194809
  }
194784
194810
 
194785
194811
  // package.json
194786
- var version5 = "0.1.24-beta.166";
194812
+ var version5 = "0.1.24-beta.169";
194787
194813
 
194788
194814
  // src/main.ts
194789
194815
  var isLambda = !!process.env.AWS_LAMBDA_RUNTIME_API;