@adhdev/mesh-shared 1.0.82-rc.1 → 1.0.82-rc.11
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.d.ts +1 -0
- package/dist/index.js +57 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -6
- package/dist/index.mjs.map +1 -1
- package/dist/node-facts.d.ts +14 -0
- package/dist/path-ownership.d.ts +1 -1
- package/dist/quota-freshness.d.ts +65 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/keyed-doc-delta.ts +9 -1
- package/src/node-facts.ts +14 -0
- package/src/path-ownership.ts +4 -6
- package/src/quota-freshness.ts +123 -0
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export * from './git-normalize';
|
|
|
15
15
|
export * from './session-normalize';
|
|
16
16
|
export * from './node-normalize';
|
|
17
17
|
export * from './node-facts';
|
|
18
|
+
export * from './quota-freshness';
|
|
18
19
|
export * from './workspace-normalize';
|
|
19
20
|
export * from './daemon-normalize';
|
|
20
21
|
export * from './git-summarize';
|
package/dist/index.js
CHANGED
|
@@ -97,6 +97,8 @@ __export(index_exports, {
|
|
|
97
97
|
OUTBOUND_MESSAGE_ORIGINS: () => OUTBOUND_MESSAGE_ORIGINS,
|
|
98
98
|
P2P_SIGNAL_TYPES: () => P2P_SIGNAL_TYPES,
|
|
99
99
|
PROVIDER_FAILURES: () => PROVIDER_FAILURES,
|
|
100
|
+
QUOTA_BACKFILL_HORIZON_MS: () => QUOTA_BACKFILL_HORIZON_MS,
|
|
101
|
+
QUOTA_RETRY_INFLIGHT_GRACE_MS: () => QUOTA_RETRY_INFLIGHT_GRACE_MS,
|
|
100
102
|
QUOTA_SUPPORTED_PROVIDERS: () => QUOTA_SUPPORTED_PROVIDERS,
|
|
101
103
|
RECENT_SESSION_BUCKETS: () => RECENT_SESSION_BUCKETS,
|
|
102
104
|
RECLAIMING_SEND_REFUSALS: () => RECLAIMING_SEND_REFUSALS,
|
|
@@ -145,6 +147,7 @@ __export(index_exports, {
|
|
|
145
147
|
WORKER_TOOLS: () => WORKER_TOOLS,
|
|
146
148
|
appendWorkerProtocolFooter: () => appendWorkerProtocolFooter,
|
|
147
149
|
argsCarryStatusProbeMarker: () => argsCarryStatusProbeMarker,
|
|
150
|
+
assessQuotaFreshness: () => assessQuotaFreshness,
|
|
148
151
|
buildSlotProposal: () => buildSlotProposal,
|
|
149
152
|
canonicalDaemonId: () => canonicalDaemonId,
|
|
150
153
|
classifySessionStatus: () => classifySessionStatus,
|
|
@@ -303,6 +306,7 @@ __export(index_exports, {
|
|
|
303
306
|
meshUtf8ByteLength: () => meshUtf8ByteLength,
|
|
304
307
|
meshWorkspacesEquivalent: () => meshWorkspacesEquivalent,
|
|
305
308
|
mintMessageId: () => mintMessageId,
|
|
309
|
+
minutesUntilQuotaCheck: () => minutesUntilQuotaCheck,
|
|
306
310
|
normalizeAuthOkLimits: () => normalizeAuthOkLimits,
|
|
307
311
|
normalizeBrainSlot: () => normalizeBrainSlot,
|
|
308
312
|
normalizeDifficultyBrainMap: () => normalizeDifficultyBrainMap,
|
|
@@ -656,6 +660,44 @@ function defaultProviderPriorityFromNodeFacts(facts) {
|
|
|
656
660
|
return orderProvidersByBuiltinPreference(detected.length ? detected : enabled);
|
|
657
661
|
}
|
|
658
662
|
|
|
663
|
+
// src/quota-freshness.ts
|
|
664
|
+
var QUOTA_RETRY_INFLIGHT_GRACE_MS = 6e4;
|
|
665
|
+
var QUOTA_BACKFILL_HORIZON_MS = 60 * 60 * 1e3;
|
|
666
|
+
function hasUsableWindow(window) {
|
|
667
|
+
return !!window && typeof window.usedPercent === "number" && Number.isFinite(window.usedPercent);
|
|
668
|
+
}
|
|
669
|
+
function hasReading(quota) {
|
|
670
|
+
if (hasUsableWindow(quota.session) || hasUsableWindow(quota.weekly)) return true;
|
|
671
|
+
return Array.isArray(quota.buckets) && quota.buckets.some((b) => !!b && typeof b.usedPercent === "number" && Number.isFinite(b.usedPercent));
|
|
672
|
+
}
|
|
673
|
+
function finiteMs(value) {
|
|
674
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : void 0;
|
|
675
|
+
}
|
|
676
|
+
function backfillCheckAt(quota, now) {
|
|
677
|
+
const dataDue = finiteMs(quota.updatedAt);
|
|
678
|
+
const attempted = finiteMs(quota.metadata?.fetchedAt);
|
|
679
|
+
const dueAt = Math.max(
|
|
680
|
+
dataDue === void 0 ? Number.NEGATIVE_INFINITY : dataDue + QUOTA_BACKFILL_HORIZON_MS,
|
|
681
|
+
attempted === void 0 ? Number.NEGATIVE_INFINITY : attempted + QUOTA_BACKFILL_HORIZON_MS
|
|
682
|
+
);
|
|
683
|
+
return Number.isFinite(dueAt) && dueAt > now ? dueAt : void 0;
|
|
684
|
+
}
|
|
685
|
+
function assessQuotaFreshness(quota, now = Date.now()) {
|
|
686
|
+
const meta = quota.metadata;
|
|
687
|
+
const kind = meta?.failureKind;
|
|
688
|
+
const userMustAct = kind === "no-data" && quota.provider !== "codex-cli" || kind === "expired-token" && quota.provider === "antigravity-cli";
|
|
689
|
+
if (userMustAct && hasReading(quota)) return { cue: "stale", userMustAct: true };
|
|
690
|
+
if (meta?.lastGoodWindows !== true) return { userMustAct };
|
|
691
|
+
const retryAtMs = finiteMs(meta?.retryAtMs);
|
|
692
|
+
const retryStopped = meta?.retryExhausted === true || retryAtMs !== void 0 && retryAtMs + QUOTA_RETRY_INFLIGHT_GRACE_MS < now;
|
|
693
|
+
if (kind !== "no-data" && !retryStopped) return { cue: "refreshing", userMustAct: false };
|
|
694
|
+
const nextCheckAt = backfillCheckAt(quota, now);
|
|
695
|
+
return nextCheckAt === void 0 ? { cue: "stale", userMustAct: false } : { cue: "stale", userMustAct: false, nextCheckAt };
|
|
696
|
+
}
|
|
697
|
+
function minutesUntilQuotaCheck(nextCheckAt, now = Date.now()) {
|
|
698
|
+
return Math.max(1, Math.round((nextCheckAt - now) / 6e4));
|
|
699
|
+
}
|
|
700
|
+
|
|
659
701
|
// src/workspace-normalize.ts
|
|
660
702
|
function normalizeMeshWorkspaceForCompare(dir) {
|
|
661
703
|
if (typeof dir !== "string") return "";
|
|
@@ -3406,14 +3448,11 @@ function normalizeOwnedPaths(input) {
|
|
|
3406
3448
|
}
|
|
3407
3449
|
function entryContains(base, path) {
|
|
3408
3450
|
if (path === base.path) return true;
|
|
3409
|
-
if (base.subtree && (path ===
|
|
3451
|
+
if (base.subtree && (base.path === "" || path.startsWith(`${base.path}/`))) return true;
|
|
3410
3452
|
return false;
|
|
3411
3453
|
}
|
|
3412
3454
|
function entriesOverlap(a, b) {
|
|
3413
|
-
|
|
3414
|
-
if (a.subtree && (b.path === a.path || b.path.startsWith(`${a.path}/`))) return true;
|
|
3415
|
-
if (b.subtree && (a.path === b.path || a.path.startsWith(`${b.path}/`))) return true;
|
|
3416
|
-
return false;
|
|
3455
|
+
return entryContains(a, b.path) || entryContains(b, a.path);
|
|
3417
3456
|
}
|
|
3418
3457
|
function pathsOverlap(a, b) {
|
|
3419
3458
|
if (a.paths.length === 0 || b.paths.length === 0) return false;
|
|
@@ -3685,7 +3724,15 @@ function foldKeyedDoc(held, delta, spec) {
|
|
|
3685
3724
|
const heldList = heldCollections.get(path);
|
|
3686
3725
|
if (change?.absent) {
|
|
3687
3726
|
const [head2, tail2] = splitPath(path);
|
|
3688
|
-
if (!tail2)
|
|
3727
|
+
if (!tail2) {
|
|
3728
|
+
delete next[head2];
|
|
3729
|
+
continue;
|
|
3730
|
+
}
|
|
3731
|
+
const parent2 = next[head2];
|
|
3732
|
+
if (!isRecord3(parent2) || !(tail2 in parent2)) continue;
|
|
3733
|
+
const copy = { ...parent2 };
|
|
3734
|
+
delete copy[tail2];
|
|
3735
|
+
next[head2] = copy;
|
|
3689
3736
|
continue;
|
|
3690
3737
|
}
|
|
3691
3738
|
if (!change && heldList === void 0) continue;
|
|
@@ -3828,6 +3875,8 @@ function stableMeshNodeRow(row) {
|
|
|
3828
3875
|
OUTBOUND_MESSAGE_ORIGINS,
|
|
3829
3876
|
P2P_SIGNAL_TYPES,
|
|
3830
3877
|
PROVIDER_FAILURES,
|
|
3878
|
+
QUOTA_BACKFILL_HORIZON_MS,
|
|
3879
|
+
QUOTA_RETRY_INFLIGHT_GRACE_MS,
|
|
3831
3880
|
QUOTA_SUPPORTED_PROVIDERS,
|
|
3832
3881
|
RECENT_SESSION_BUCKETS,
|
|
3833
3882
|
RECLAIMING_SEND_REFUSALS,
|
|
@@ -3876,6 +3925,7 @@ function stableMeshNodeRow(row) {
|
|
|
3876
3925
|
WORKER_TOOLS,
|
|
3877
3926
|
appendWorkerProtocolFooter,
|
|
3878
3927
|
argsCarryStatusProbeMarker,
|
|
3928
|
+
assessQuotaFreshness,
|
|
3879
3929
|
buildSlotProposal,
|
|
3880
3930
|
canonicalDaemonId,
|
|
3881
3931
|
classifySessionStatus,
|
|
@@ -4034,6 +4084,7 @@ function stableMeshNodeRow(row) {
|
|
|
4034
4084
|
meshUtf8ByteLength,
|
|
4035
4085
|
meshWorkspacesEquivalent,
|
|
4036
4086
|
mintMessageId,
|
|
4087
|
+
minutesUntilQuotaCheck,
|
|
4037
4088
|
normalizeAuthOkLimits,
|
|
4038
4089
|
normalizeBrainSlot,
|
|
4039
4090
|
normalizeDifficultyBrainMap,
|