@cortexkit/opencode-openai-auth 1.8.3 → 1.8.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.
Files changed (59) hide show
  1. package/dist/bin.js +8 -8
  2. package/dist/{codex-request-GJkvxv4S.d.ts → codex-request-By530v1D.d.ts} +3 -2
  3. package/dist/{index-c50p5mem.js → index-5wgxt362.js} +1 -1
  4. package/dist/{index-rw932qm9.js → index-8x42xzxb.js} +20 -20
  5. package/dist/{index-g556s1mz.js → index-95s2mw9w.js} +2 -2
  6. package/dist/{index-bej7x30p.js → index-a7xv52hy.js} +7 -7
  7. package/dist/{index-hpnj460b.js → index-byz2j6hz.js} +1 -1
  8. package/dist/{index-z81cged1.js → index-g5hv0tda.js} +2 -2
  9. package/dist/{index-yt52fztj.js → index-jh90fx7y.js} +2 -2
  10. package/dist/{index-p8m4yh73.js → index-kphzmgq6.js} +1 -1
  11. package/dist/index-n12zjwh9.js +8 -0
  12. package/dist/{index-0v7ar02e.js → index-rmc6hwg6.js} +1 -1
  13. package/dist/index-zah8t2d2.js +2 -0
  14. package/dist/{index-dw6yd976.js → index-zf649dj2.js} +2 -2
  15. package/dist/index-zne9tzy9.js +91 -0
  16. package/dist/index.d.ts +2 -2
  17. package/dist/index.js +1 -1
  18. package/dist/rpc/port-file.js +1 -1
  19. package/dist/rpc/protocol.js +1 -1
  20. package/dist/rpc/rpc-client.js +1 -1
  21. package/dist/rpc/rpc-dir.js +1 -1
  22. package/dist/{sidebar-state-DkNebAiC.d.ts → sidebar-state-CrRiE9hw.d.ts} +3 -1
  23. package/dist/sidebar-state.d.ts +1 -1
  24. package/dist/sidebar-state.js +1 -1
  25. package/dist/{token-3vtr29vt.js → token-j2jmx8k7.js} +1 -1
  26. package/dist/token-util-7n2nfbyc.js +1 -0
  27. package/dist/tui-preferences.js +1 -1
  28. package/dist/tui.d.ts +2 -21
  29. package/dist/v2/server.d.ts +1 -1
  30. package/dist/v2/server.js +2 -2
  31. package/package.json +2 -2
  32. package/src/tui-compiled/raw/shared/0f77ebc3c914c9c6-custody.js +20 -6
  33. package/src/tui-compiled/raw/shared/169b2b4bf30909bc-consumer.js +25 -0
  34. package/src/tui-compiled/raw/shared/30f5bc480f31f51c-roster.js +1 -1
  35. package/src/tui-compiled/raw/shared/352d228be2832bd4-hub.js +55 -5
  36. package/src/tui-compiled/raw/shared/4825e03209d6ae3e-with-lock.js +1 -1
  37. package/src/tui-compiled/raw/shared/549daf371622c304-index.tsx +497 -0
  38. package/src/tui-compiled/raw/shared/7c97ac0cec074ae7-format.js +208 -0
  39. package/src/tui-compiled/raw/shared/b4ad0d49429f0096-map.js +98 -0
  40. package/src/tui-compiled/raw/shared/b717cdcce3966455-projection.js +90 -0
  41. package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +3 -1
  42. package/src/tui-compiled/raw/sidebar-state.js +10 -6
  43. package/src/tui-compiled/raw/tui.tsx +232 -623
  44. package/src/tui-compiled/runtime/shared/0f77ebc3c914c9c6-custody.js +20 -6
  45. package/src/tui-compiled/runtime/shared/169b2b4bf30909bc-consumer.js +25 -0
  46. package/src/tui-compiled/runtime/shared/30f5bc480f31f51c-roster.js +1 -1
  47. package/src/tui-compiled/runtime/shared/352d228be2832bd4-hub.js +55 -5
  48. package/src/tui-compiled/runtime/shared/4825e03209d6ae3e-with-lock.js +1 -1
  49. package/src/tui-compiled/runtime/shared/549daf371622c304-index.js +550 -0
  50. package/src/tui-compiled/runtime/shared/7c97ac0cec074ae7-format.js +208 -0
  51. package/src/tui-compiled/runtime/shared/b4ad0d49429f0096-map.js +98 -0
  52. package/src/tui-compiled/runtime/shared/b717cdcce3966455-projection.js +90 -0
  53. package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +3 -1
  54. package/src/tui-compiled/runtime/sidebar-state.js +10 -6
  55. package/src/tui-compiled/runtime/tui.js +256 -893
  56. package/dist/index-03hs0rq7.js +0 -2
  57. package/dist/index-b0s5cty6.js +0 -91
  58. package/dist/index-fyrgwfx3.js +0 -8
  59. package/dist/token-util-erhrf24m.js +0 -1
@@ -0,0 +1,208 @@
1
+ import { ALL_SCOPE } from "./b4ad0d49429f0096-map.js";
2
+ export const QUOTA_STALE_AFTER_MS = 900000, NO_QUOTA_READING = "no quota reading yet", NO_LIMITS_REPORTED = "no limits reported";
3
+ function shortSpan(ms) {
4
+ const minutes = Math.max(1, Math.floor(ms / 60000));
5
+ if (minutes < 60)
6
+ return `${minutes}m`;
7
+ if (minutes < 1440) {
8
+ const hours = Math.floor(minutes / 60), rest = minutes % 60;
9
+ return rest === 0 ? `${hours}h` : `${hours}h${rest}m`;
10
+ }
11
+ const days = Math.floor(minutes / 1440), hours = Math.floor(minutes % 1440 / 60);
12
+ return hours === 0 ? `${days}d` : `${days}d${hours}h`;
13
+ }
14
+ function lengthName(minutes) {
15
+ if (minutes % 1440 === 0)
16
+ return `${minutes / 1440}d`;
17
+ if (minutes % 60 === 0)
18
+ return `${minutes / 60}h`;
19
+ return `${minutes}m`;
20
+ }
21
+ export function quotaWindowName(limit) {
22
+ if (limit.scope !== ALL_SCOPE || limit.windowMinutes === void 0)
23
+ return limit.label;
24
+ return lengthName(limit.windowMinutes);
25
+ }
26
+ function clampPercent(remaining) {
27
+ return Math.min(100, Math.max(0, remaining));
28
+ }
29
+ function wholePercent(remaining) {
30
+ return Math.round(clampPercent(remaining));
31
+ }
32
+ function percentLeft(remaining) {
33
+ return `${wholePercent(remaining)}% left`;
34
+ }
35
+ function resetDetails(resetsAt, checkedAt, now) {
36
+ const at = resetsAt === void 0 ? Number.NaN : Date.parse(resetsAt);
37
+ return {
38
+ ...Number.isFinite(at) && at > now ? { resetIn: shortSpan(at - now) } : {},
39
+ resetSinceReading: Number.isFinite(at) && at > checkedAt && at <= now
40
+ };
41
+ }
42
+ function displayOrder(left, right) {
43
+ const l = left.windowMinutes, r = right.windowMinutes;
44
+ if (l !== void 0 && r !== void 0 && l !== r)
45
+ return l - r;
46
+ if (l === void 0 !== (r === void 0))
47
+ return l === void 0 ? 1 : -1;
48
+ if (left.scope !== right.scope) {
49
+ if (left.scope === ALL_SCOPE)
50
+ return -1;
51
+ if (right.scope === ALL_SCOPE)
52
+ return 1;
53
+ return left.scope < right.scope ? -1 : 1;
54
+ }
55
+ return left.label < right.label ? -1 : left.label > right.label ? 1 : 0;
56
+ }
57
+ export function quotaWindowParts(quota, options) {
58
+ const { windows, age } = scopedWindowParts(quota, options), parts = windows.map(({ part }) => part);
59
+ return age === void 0 ? { windows: parts } : { windows: parts, age };
60
+ }
61
+ function withShortNames(windows) {
62
+ const abbreviations = scopeAbbreviations(windows.filter(({ part, scope }) => part.kind === "window" && scope !== ALL_SCOPE).map(({ scope }) => scope));
63
+ for (const window of windows)
64
+ window.part.short = window.part.kind === "budget" ? "cr" : window.scope === ALL_SCOPE ? window.part.name : abbreviations.get(window.scope) ?? window.scope;
65
+ return windows;
66
+ }
67
+ function scopedWindowParts(quota, options) {
68
+ if (!quota)
69
+ return { windows: [] };
70
+ const { now } = options, windows = quota.limits.filter((limit) => limit.kind === "reading" && limit.remainingPercent !== void 0).sort(displayOrder).map((limit) => {
71
+ const remainingPercent = clampPercent(limit.remainingPercent ?? 0);
72
+ return {
73
+ scope: limit.scope,
74
+ ...limit.windowMinutes === void 0 ? {} : { windowMinutes: limit.windowMinutes },
75
+ part: {
76
+ kind: "window",
77
+ name: quotaWindowName(limit),
78
+ short: "",
79
+ figure: percentLeft(limit.remainingPercent ?? 0),
80
+ remainingPercent,
81
+ checkedAt: limit.checkedAt,
82
+ ...resetDetails(limit.resetsAt, limit.checkedAt, now)
83
+ }
84
+ };
85
+ }), budget = quota.budget;
86
+ if (budget) {
87
+ const remainingPercent = budget.remainingPercent, figure = budget.reached ? "credits spent" : remainingPercent !== void 0 ? `credits ${percentLeft(remainingPercent)}` : "credits available";
88
+ windows.push({
89
+ scope: ALL_SCOPE,
90
+ spent: budget.reached,
91
+ part: {
92
+ kind: "budget",
93
+ name: "credits",
94
+ short: "",
95
+ figure,
96
+ ...remainingPercent === void 0 ? {} : { remainingPercent: clampPercent(remainingPercent) },
97
+ checkedAt: budget.checkedAt,
98
+ ...resetDetails(budget.resetsAt, budget.checkedAt, now)
99
+ }
100
+ });
101
+ }
102
+ withShortNames(windows);
103
+ if (windows.length > 0) {
104
+ const age = now - Math.min(...windows.map(({ part }) => part.checkedAt));
105
+ if (age > (options.staleAfterMs ?? QUOTA_STALE_AFTER_MS))
106
+ return { windows, age: `checked ${shortSpan(age)} ago` };
107
+ }
108
+ return { windows };
109
+ }
110
+ export function isQuotaStale(quota, options) {
111
+ return scopedWindowParts(quota, options).age !== void 0;
112
+ }
113
+ function scopeDisplayName(scope) {
114
+ const model = scope.slice(scope.indexOf(":") + 1);
115
+ return model.charAt(0).toUpperCase() + model.slice(1);
116
+ }
117
+ function scopeAbbreviations(scopes) {
118
+ const names = [...new Set(scopes.map(scopeDisplayName))], lengths = new Map(names.map((name) => [name, 2])), short = (name) => name.slice(0, lengths.get(name));
119
+ for (;; ) {
120
+ const byShort = new Map;
121
+ for (const name of names)
122
+ byShort.set(short(name), [...byShort.get(short(name)) ?? [], name]);
123
+ let extended = !1;
124
+ for (const group of byShort.values()) {
125
+ if (group.length < 2)
126
+ continue;
127
+ for (const name of group) {
128
+ const length = lengths.get(name) ?? 2;
129
+ if (length < name.length) {
130
+ lengths.set(name, length + 1);
131
+ extended = !0;
132
+ }
133
+ }
134
+ }
135
+ if (!extended)
136
+ break;
137
+ }
138
+ return new Map(scopes.map((scope) => [scope, short(scopeDisplayName(scope))]));
139
+ }
140
+ const NARROW_GROUP_LIMIT = 2;
141
+ function groupShortNames(groups) {
142
+ const labels = groups.map((group) => group.label.trim() || group.scope), short = scopeAbbreviations(labels);
143
+ return labels.map((label) => short.get(label) ?? label);
144
+ }
145
+ function groupedNarrowPieces(groups, windows) {
146
+ if (!groups || groups.length === 0)
147
+ return;
148
+ const reported = windows.filter(({ part }) => part.kind === "window");
149
+ if (reported.some(({ scope }) => scope === ALL_SCOPE))
150
+ return;
151
+ const candidates = groups.flatMap((group, listed) => {
152
+ const groupTightest = reported.filter(({ scope }) => scope === group.scope).reduce((least, window) => least === void 0 || (window.part.remainingPercent ?? 0) < (least.part.remainingPercent ?? 0) ? window : least, void 0);
153
+ return groupTightest ? [{ group, listed, window: groupTightest }] : [];
154
+ });
155
+ if (candidates.length === 0)
156
+ return;
157
+ const names = groupShortNames(groups), left = (candidate) => candidate.window.part.remainingPercent ?? 0, shown = [...candidates].sort((a, b) => left(a) - left(b) || a.listed - b.listed).slice(0, NARROW_GROUP_LIMIT).sort((a, b) => a.listed - b.listed);
158
+ return shown.map((candidate, index) => {
159
+ const { windowMinutes } = candidate.window, piece = [
160
+ names[candidate.listed] ?? candidate.group.scope,
161
+ ...windowMinutes === void 0 ? [] : [lengthName(windowMinutes)],
162
+ `${wholePercent(left(candidate))}%`
163
+ ].join(" ");
164
+ return index === shown.length - 1 ? `${piece} left` : piece;
165
+ });
166
+ }
167
+ function narrowTextParts(quota, options) {
168
+ const { windows } = scopedWindowParts(quota, options), grouped = groupedNarrowPieces(quota?.groups, windows);
169
+ if (grouped)
170
+ return grouped;
171
+ const general = windows.filter(({ part, scope }) => part.kind === "window" && scope === ALL_SCOPE), scoped = windows.filter(({ part, scope }) => part.kind === "window" && scope !== ALL_SCOPE), budget = windows.find(({ part }) => part.kind === "budget"), budgetLeft = budget?.spent ? 0 : budget?.part.remainingPercent, tightest = [
172
+ ...scoped.map(({ part }) => ({
173
+ label: part.short,
174
+ remaining: part.remainingPercent ?? 0
175
+ })),
176
+ ...budgetLeft === void 0 || budget === void 0 ? [] : [{ label: budget.part.short, remaining: budgetLeft }]
177
+ ].reduce((best, item) => best === void 0 || item.remaining < best.remaining ? item : best, void 0), pieces = general.map(({ part }) => `${part.name} ${wholePercent(part.remainingPercent ?? 0)}%`);
178
+ if (tightest)
179
+ pieces.push(`${tightest.label} ${wholePercent(tightest.remaining)}%`);
180
+ if (pieces.length === 0)
181
+ return windows.map(({ part }) => part.figure);
182
+ return pieces.map((piece, index) => index === pieces.length - 1 ? `${piece} left` : piece);
183
+ }
184
+ export function quotaTextParts(quota, options) {
185
+ if (options.form === "narrow")
186
+ return narrowTextParts(quota, options);
187
+ const parts = quotaWindowParts(quota, options), full = (options.form ?? "full") === "full", text = parts.windows.map((part) => {
188
+ const reset = full && part.resetIn ? `, resets ${part.resetIn}` : "";
189
+ return `${part.kind === "budget" ? "" : `${part.name} `}${part.figure}${reset}`;
190
+ });
191
+ return parts.age === void 0 ? text : [...text, parts.age];
192
+ }
193
+ export function formatQuota(quota, options) {
194
+ const parts = quotaTextParts(quota, options);
195
+ if (parts.length > 0)
196
+ return parts.join(" \xB7 ");
197
+ return quota && quota.limits.length > 0 ? NO_LIMITS_REPORTED : NO_QUOTA_READING;
198
+ }
199
+ export function quotaCreditsText(credits) {
200
+ if (credits === void 0)
201
+ return;
202
+ if (credits.unlimited)
203
+ return "Unlimited";
204
+ if (!credits.hasCredits)
205
+ return;
206
+ const { balance } = credits;
207
+ return typeof balance === "number" && Number.isFinite(balance) && balance > 0 ? `${Math.round(balance)} credits` : "Available";
208
+ }
@@ -0,0 +1,98 @@
1
+ export const ALL_SCOPE = "all", DEFAULT_REQUIRED_LABELS = Object.freeze([
2
+ "primary"
3
+ ]);
4
+ export function emptyQuotaMap() {
5
+ return { limits: [] };
6
+ }
7
+ export function entryTime(entry) {
8
+ return entry.kind === "retired" ? entry.retiredAt : entry.checkedAt;
9
+ }
10
+ export function limitKey(scope, label) {
11
+ return JSON.stringify([scope, label]);
12
+ }
13
+ function isRecord(value) {
14
+ return typeof value === "object" && value !== null && !Array.isArray(value);
15
+ }
16
+ function isFiniteNumber(value) {
17
+ return typeof value === "number" && Number.isFinite(value);
18
+ }
19
+ function isName(value) {
20
+ return typeof value === "string" && value.length > 0;
21
+ }
22
+ function optional(record, key, check) {
23
+ return record[key] === void 0 || check(record[key]);
24
+ }
25
+ function isPositiveFinite(value) {
26
+ return isFiniteNumber(value) && value > 0;
27
+ }
28
+ function isString(value) {
29
+ return typeof value === "string";
30
+ }
31
+ function isQuotaEntry(value) {
32
+ if (!isRecord(value) || !isName(value.scope) || !isName(value.label))
33
+ return !1;
34
+ switch (value.kind) {
35
+ case "reading":
36
+ return isFiniteNumber(value.checkedAt) && isFiniteNumber(value.usedPercent) && optional(value, "resetsAt", isString) && optional(value, "windowMinutes", isPositiveFinite);
37
+ case "retired":
38
+ return isFiniteNumber(value.retiredAt);
39
+ case "absent":
40
+ return isFiniteNumber(value.checkedAt);
41
+ default:
42
+ return !1;
43
+ }
44
+ }
45
+ export function isCreditBudgetEntry(value) {
46
+ if (!isRecord(value) || !isFiniteNumber(value.checkedAt))
47
+ return !1;
48
+ if (value.kind === "cleared")
49
+ return !0;
50
+ return value.kind === "reading" && typeof value.reached === "boolean" && optional(value, "remainingPercent", isFiniteNumber) && optional(value, "usedPercent", isFiniteNumber) && optional(value, "resetsAt", isString) && optional(value, "limit", isFiniteNumber) && optional(value, "used", isFiniteNumber) && optional(value, "remaining", isFiniteNumber) && optional(value, "unit", isString);
51
+ }
52
+ function isQuotaCounter(value) {
53
+ return isRecord(value) && isFiniteNumber(value.value) && Number.isInteger(value.value) && value.value >= 0 && isFiniteNumber(value.checkedAt);
54
+ }
55
+ export function isQuotaCounters(value) {
56
+ return isRecord(value) && Object.values(value).every(isQuotaCounter);
57
+ }
58
+ function isBoolean(value) {
59
+ return typeof value === "boolean";
60
+ }
61
+ export function isQuotaCredits(value) {
62
+ return isRecord(value) && typeof value.hasCredits === "boolean" && typeof value.unlimited === "boolean" && optional(value, "balance", isFiniteNumber) && optional(value, "overageLimitReached", isBoolean) && isFiniteNumber(value.checkedAt);
63
+ }
64
+ export function readQuotaCounters(value) {
65
+ if (!isRecord(value))
66
+ return;
67
+ const entries = Object.entries(value).filter(([, entry]) => isQuotaCounter(entry));
68
+ return entries.length === 0 ? void 0 : Object.fromEntries(entries);
69
+ }
70
+ export function decodeQuotaMap(value) {
71
+ if (isQuotaMap(value))
72
+ return value;
73
+ if (!isRecord(value))
74
+ return;
75
+ const { counters: rawCounters, credits: rawCredits, ...rest } = value;
76
+ if (!isQuotaMap(rest))
77
+ return;
78
+ const counters = readQuotaCounters(rawCounters), credits = isQuotaCredits(rawCredits) ? rawCredits : void 0;
79
+ return {
80
+ ...rest,
81
+ ...counters === void 0 ? {} : { counters },
82
+ ...credits === void 0 ? {} : { credits }
83
+ };
84
+ }
85
+ export function isQuotaMap(value) {
86
+ if (!isRecord(value) || !Array.isArray(value.limits))
87
+ return !1;
88
+ const seen = new Set;
89
+ for (const entry of value.limits) {
90
+ if (!isQuotaEntry(entry))
91
+ return !1;
92
+ const key = limitKey(entry.scope, entry.label);
93
+ if (seen.has(key))
94
+ return !1;
95
+ seen.add(key);
96
+ }
97
+ return optional(value, "budget", isCreditBudgetEntry) && optional(value, "counters", isQuotaCounters) && optional(value, "credits", isQuotaCredits);
98
+ }
@@ -0,0 +1,90 @@
1
+ import {
2
+ ALL_SCOPE,
3
+ isQuotaCredits,
4
+ readQuotaCounters
5
+ } from "./b4ad0d49429f0096-map.js";
6
+ function project(entry) {
7
+ if (entry.kind === "retired")
8
+ return {
9
+ scope: entry.scope,
10
+ label: entry.label,
11
+ kind: "retired",
12
+ checkedAt: entry.retiredAt
13
+ };
14
+ if (entry.kind === "absent")
15
+ return {
16
+ scope: entry.scope,
17
+ label: entry.label,
18
+ kind: "absent",
19
+ checkedAt: entry.checkedAt
20
+ };
21
+ return {
22
+ scope: entry.scope,
23
+ label: entry.label,
24
+ kind: "reading",
25
+ checkedAt: entry.checkedAt,
26
+ usedPercent: entry.usedPercent,
27
+ remainingPercent: 100 - entry.usedPercent,
28
+ ...entry.windowMinutes === void 0 ? {} : { windowMinutes: entry.windowMinutes },
29
+ ...entry.resetsAt === void 0 ? {} : { resetsAt: entry.resetsAt }
30
+ };
31
+ }
32
+ function compareLimits(left, right) {
33
+ const leftKnown = left.windowMinutes !== void 0, rightKnown = right.windowMinutes !== void 0;
34
+ if (leftKnown !== rightKnown)
35
+ return leftKnown ? -1 : 1;
36
+ if (leftKnown && rightKnown && left.windowMinutes !== right.windowMinutes)
37
+ return (right.windowMinutes ?? 0) - (left.windowMinutes ?? 0);
38
+ if (left.label !== right.label)
39
+ return left.label < right.label ? -1 : 1;
40
+ return 0;
41
+ }
42
+ function projectBudget(budget) {
43
+ return {
44
+ checkedAt: budget.checkedAt,
45
+ reached: budget.reached,
46
+ ...budget.remainingPercent === void 0 ? {} : { remainingPercent: budget.remainingPercent },
47
+ ...budget.resetsAt === void 0 ? {} : { resetsAt: budget.resetsAt }
48
+ };
49
+ }
50
+ export function projectQuota(map, scope = ALL_SCOPE) {
51
+ const byLabel = new Map;
52
+ for (const entry of map?.limits ?? []) {
53
+ if (entry.scope !== scope && entry.scope !== ALL_SCOPE)
54
+ continue;
55
+ const current = byLabel.get(entry.label);
56
+ if (current === void 0) {
57
+ byLabel.set(entry.label, entry);
58
+ continue;
59
+ }
60
+ const family = entry.scope === ALL_SCOPE ? current : entry, general = entry.scope === ALL_SCOPE ? entry : current;
61
+ byLabel.set(entry.label, family.kind === "reading" ? family : general);
62
+ }
63
+ const limits = [...byLabel.values()].map(project).sort(compareLimits), readings = limits.filter((limit) => limit.kind === "reading"), stamped = readings.length > 0 ? readings : limits, checkedAt = stamped.length > 0 ? Math.min(...stamped.map((limit) => limit.checkedAt)) : void 0, budget = map?.budget?.kind === "reading" ? projectBudget(map.budget) : void 0, counters = readQuotaCounters(map?.counters), credits = isQuotaCredits(map?.credits) ? map.credits : void 0;
64
+ return {
65
+ scope,
66
+ limits,
67
+ ...checkedAt === void 0 ? {} : { checkedAt },
68
+ ...budget === void 0 ? {} : { budget },
69
+ ...counters === void 0 ? {} : { counters },
70
+ ...credits === void 0 ? {} : { credits }
71
+ };
72
+ }
73
+ export function budgetExhaustedResetAt(quota, now) {
74
+ const budget = quota?.budget;
75
+ if (budget?.reached !== !0 || typeof budget.resetsAt !== "string")
76
+ return;
77
+ const resetAtMs = Date.parse(budget.resetsAt);
78
+ if (!Number.isFinite(resetAtMs) || resetAtMs <= now)
79
+ return;
80
+ return { resetsAt: budget.resetsAt, resetAtMs };
81
+ }
82
+ export function readsExhausted(limit) {
83
+ return limit.kind === "reading" && typeof limit.usedPercent === "number" && Number.isFinite(limit.usedPercent) && limit.usedPercent >= 100;
84
+ }
85
+ export function futureResetAt(limit, now) {
86
+ if (typeof limit.resetsAt !== "string")
87
+ return;
88
+ const resetAtMs = Date.parse(limit.resetsAt);
89
+ return Number.isFinite(resetAtMs) && resetAtMs > now ? resetAtMs : void 0;
90
+ }
@@ -836,7 +836,7 @@ export async function acquireRefreshFileLockWithClock(options) {
836
836
  : {}),
837
837
  });
838
838
  },
839
- release: async () => {
839
+ release: async (signal) => {
840
840
  if (windowsPrivateFiles && releaseConfirmed)
841
841
  return;
842
842
  released = true;
@@ -882,6 +882,8 @@ export async function acquireRefreshFileLockWithClock(options) {
882
882
  releaseConfirmed = removalConfirmed;
883
883
  return;
884
884
  }
885
+ if (signal?.aborted)
886
+ return;
885
887
  await recoverStaleEvictionMarker();
886
888
  }
887
889
  catch (error) {
@@ -452,7 +452,11 @@ function writeMergedSidebarState(file, merge, hooks) {
452
452
  const next = merge(latest);
453
453
  if (next === void 0)
454
454
  return;
455
- if (next.vaultAccounts !== void 0) {
455
+ if (hooks?.vaultMode === !1) {
456
+ next.vaultAccounts = void 0;
457
+ next.vaultDiscovered = void 0;
458
+ }
459
+ if (hooks?.vaultMode ?? next.vaultAccounts !== void 0) {
456
460
  next.activeId = next.activeId?.startsWith("vault:") ? next.activeId : void 0;
457
461
  next.activeRouting = Object.fromEntries(Object.entries(next.activeRouting ?? {}).filter(([, entry]) => entry.activeId.startsWith("vault:")));
458
462
  next.stickyAssignments = Object.fromEntries(Object.entries(next.stickyAssignments ?? {}).filter(([, pin]) => pin.accountId.startsWith("vault:") && !next.vaultAccounts?.some((account) => account.id === pin.accountId && account.killed)));
@@ -589,7 +593,7 @@ export function upsertSidebarActiveRouting(input, accounts, file = getSidebarSta
589
593
  route: input.route,
590
594
  updatedAt: input.updatedAt
591
595
  }
592
- }, accounts, Date.now()), stickyAssignments = pruneStickyAssignments(latest.stickyAssignments, latest.vaultAccounts !== void 0 ? void 0 : usableRoutingAccountIds(accounts), Date.now());
596
+ }, accounts, Date.now()), stickyAssignments = pruneStickyAssignments(latest.stickyAssignments, hooks?.vaultMode ?? latest.vaultAccounts !== void 0 ? void 0 : usableRoutingAccountIds(accounts), Date.now());
593
597
  return {
594
598
  ...latest,
595
599
  activeId: input.activeId,
@@ -614,7 +618,7 @@ export function setSidebarLegacyRouting(input, file = getSidebarStateFile(), hoo
614
618
  export function removeSidebarActiveRouting(sessionId, accounts, file = getSidebarStateFile(), hooks) {
615
619
  return enqueueSidebarWrite(async () => {
616
620
  await writeMergedSidebarState(file, (latest) => {
617
- const now = Date.now(), activeRouting = pruneActiveRouting(latest.activeRouting, accounts, now, sessionId), stickyAssignments = pruneStickyAssignments(latest.stickyAssignments, latest.vaultAccounts !== void 0 ? void 0 : usableRoutingAccountIds(accounts), now, hashSidebarSessionId(sessionId));
621
+ const now = Date.now(), activeRouting = pruneActiveRouting(latest.activeRouting, accounts, now, sessionId), stickyAssignments = pruneStickyAssignments(latest.stickyAssignments, hooks?.vaultMode ?? latest.vaultAccounts !== void 0 ? void 0 : usableRoutingAccountIds(accounts), now, hashSidebarSessionId(sessionId));
618
622
  return {
619
623
  ...latest,
620
624
  activeRouting,
@@ -707,11 +711,11 @@ export function planSidebarStickyAssignmentFromSnapshot(state, input) {
707
711
  return { assignment: existing, next: void 0 };
708
712
  return planSidebarStickyAssignment(state, input);
709
713
  }
710
- export function persistSidebarStickyAssignment(input, file = getSidebarStateFile()) {
714
+ export function persistSidebarStickyAssignment(input, file = getSidebarStateFile(), hooks) {
711
715
  const sessionHash = hashSidebarSessionId(input.sessionId), validPinnedAccountIds = new Set(input.validPinnedAccountIds);
712
716
  return enqueueSidebarWrite(async () => {
713
717
  await writeMergedSidebarState(file, (latest) => {
714
- const now = Date.now(), stickyAssignments = pruneStickyAssignments(latest.stickyAssignments, latest.vaultAccounts !== void 0 ? void 0 : validPinnedAccountIds, now), current = stickyAssignments?.[sessionHash];
718
+ const now = Date.now(), stickyAssignments = pruneStickyAssignments(latest.stickyAssignments, hooks?.vaultMode ?? latest.vaultAccounts !== void 0 ? void 0 : validPinnedAccountIds, now), current = stickyAssignments?.[sessionHash];
715
719
  if (current && current.assignedAt > input.assignment.assignedAt) {
716
720
  if (stickyAssignmentsEqual(latest.stickyAssignments, stickyAssignments))
717
721
  return;
@@ -731,7 +735,7 @@ export function persistSidebarStickyAssignment(input, file = getSidebarStateFile
731
735
  stickyAssignments: limitStickyAssignments({ ...stickyAssignments, [sessionHash]: assignment }, sessionHash),
732
736
  lastUpdated: Math.max(now, latest.lastUpdated + 1)
733
737
  };
734
- });
738
+ }, hooks);
735
739
  });
736
740
  }
737
741
  export async function clearSidebarStickyAssignment(sessionId, file = getSidebarStateFile()) {