@adhdev/mesh-shared 1.0.82-rc.4 → 1.0.82-rc.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.
package/dist/index.mjs CHANGED
@@ -300,6 +300,44 @@ function defaultProviderPriorityFromNodeFacts(facts) {
300
300
  return orderProvidersByBuiltinPreference(detected.length ? detected : enabled);
301
301
  }
302
302
 
303
+ // src/quota-freshness.ts
304
+ var QUOTA_RETRY_INFLIGHT_GRACE_MS = 6e4;
305
+ var QUOTA_BACKFILL_HORIZON_MS = 60 * 60 * 1e3;
306
+ function hasUsableWindow(window) {
307
+ return !!window && typeof window.usedPercent === "number" && Number.isFinite(window.usedPercent);
308
+ }
309
+ function hasReading(quota) {
310
+ if (hasUsableWindow(quota.session) || hasUsableWindow(quota.weekly)) return true;
311
+ return Array.isArray(quota.buckets) && quota.buckets.some((b) => !!b && typeof b.usedPercent === "number" && Number.isFinite(b.usedPercent));
312
+ }
313
+ function finiteMs(value) {
314
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : void 0;
315
+ }
316
+ function backfillCheckAt(quota, now) {
317
+ const dataDue = finiteMs(quota.updatedAt);
318
+ const attempted = finiteMs(quota.metadata?.fetchedAt);
319
+ const dueAt = Math.max(
320
+ dataDue === void 0 ? Number.NEGATIVE_INFINITY : dataDue + QUOTA_BACKFILL_HORIZON_MS,
321
+ attempted === void 0 ? Number.NEGATIVE_INFINITY : attempted + QUOTA_BACKFILL_HORIZON_MS
322
+ );
323
+ return Number.isFinite(dueAt) && dueAt > now ? dueAt : void 0;
324
+ }
325
+ function assessQuotaFreshness(quota, now = Date.now()) {
326
+ const meta = quota.metadata;
327
+ const kind = meta?.failureKind;
328
+ const userMustAct = kind === "no-data" && quota.provider !== "codex-cli" || kind === "expired-token" && quota.provider === "antigravity-cli";
329
+ if (userMustAct && hasReading(quota)) return { cue: "stale", userMustAct: true };
330
+ if (meta?.lastGoodWindows !== true) return { userMustAct };
331
+ const retryAtMs = finiteMs(meta?.retryAtMs);
332
+ const retryStopped = meta?.retryExhausted === true || retryAtMs !== void 0 && retryAtMs + QUOTA_RETRY_INFLIGHT_GRACE_MS < now;
333
+ if (kind !== "no-data" && !retryStopped) return { cue: "refreshing", userMustAct: false };
334
+ const nextCheckAt = backfillCheckAt(quota, now);
335
+ return nextCheckAt === void 0 ? { cue: "stale", userMustAct: false } : { cue: "stale", userMustAct: false, nextCheckAt };
336
+ }
337
+ function minutesUntilQuotaCheck(nextCheckAt, now = Date.now()) {
338
+ return Math.max(1, Math.round((nextCheckAt - now) / 6e4));
339
+ }
340
+
303
341
  // src/workspace-normalize.ts
304
342
  function normalizeMeshWorkspaceForCompare(dir) {
305
343
  if (typeof dir !== "string") return "";
@@ -3471,6 +3509,8 @@ export {
3471
3509
  OUTBOUND_MESSAGE_ORIGINS,
3472
3510
  P2P_SIGNAL_TYPES,
3473
3511
  PROVIDER_FAILURES,
3512
+ QUOTA_BACKFILL_HORIZON_MS,
3513
+ QUOTA_RETRY_INFLIGHT_GRACE_MS,
3474
3514
  QUOTA_SUPPORTED_PROVIDERS,
3475
3515
  RECENT_SESSION_BUCKETS,
3476
3516
  RECLAIMING_SEND_REFUSALS,
@@ -3519,6 +3559,7 @@ export {
3519
3559
  WORKER_TOOLS,
3520
3560
  appendWorkerProtocolFooter,
3521
3561
  argsCarryStatusProbeMarker,
3562
+ assessQuotaFreshness,
3522
3563
  buildSlotProposal,
3523
3564
  canonicalDaemonId,
3524
3565
  classifySessionStatus,
@@ -3677,6 +3718,7 @@ export {
3677
3718
  meshUtf8ByteLength,
3678
3719
  meshWorkspacesEquivalent,
3679
3720
  mintMessageId,
3721
+ minutesUntilQuotaCheck,
3680
3722
  normalizeAuthOkLimits,
3681
3723
  normalizeBrainSlot,
3682
3724
  normalizeDifficultyBrainMap,