@cortexkit/opencode-openai-auth 0.11.1 → 1.0.0

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 (204) hide show
  1. package/README.md +15 -26
  2. package/dist/index-766sfrh5.js +1 -0
  3. package/dist/index-8kj7sa1p.js +12 -0
  4. package/dist/index-8rqfbhfw.js +221 -0
  5. package/dist/index-b3q3j39x.js +2 -0
  6. package/dist/index-bmd7x5aq.js +2 -0
  7. package/dist/index-eqh53k8v.js +2 -0
  8. package/dist/{index-sdt2d2ra.js → index-hy9030jh.js} +1 -1
  9. package/dist/index-jyr8y8k4.js +7 -0
  10. package/dist/index-rv08jmd4.js +2 -0
  11. package/dist/index.d.ts +578 -145
  12. package/dist/index.js +1 -110
  13. package/dist/pool-lifecycle-DbDmgabd.d.ts +2430 -0
  14. package/dist/port-file-Do3lQIEk.d.ts +29 -0
  15. package/dist/protocol-BOBdkqqm.d.ts +198 -0
  16. package/dist/rpc/port-file.d.ts +4 -17
  17. package/dist/rpc/port-file.js +1 -1
  18. package/dist/rpc/protocol.d.ts +2 -2
  19. package/dist/rpc/protocol.js +1 -0
  20. package/dist/rpc/rpc-client.d.ts +5 -4
  21. package/dist/rpc/rpc-client.js +1 -1
  22. package/dist/rpc/rpc-dir.d.ts +2 -0
  23. package/dist/rpc/rpc-dir.js +1 -1
  24. package/dist/sidebar-state-D6cUKgkm.d.ts +385 -0
  25. package/dist/sidebar-state.d.ts +2 -2
  26. package/dist/sidebar-state.js +1 -1
  27. package/dist/token-util-wdza526f.js +1 -0
  28. package/dist/{token-9823y0pc.js → token-ypk61xj0.js} +1 -1
  29. package/dist/tui-preferences.js +5 -2
  30. package/dist/tui.d.ts +9 -4
  31. package/dist/v2/server.d.ts +54 -0
  32. package/dist/v2/server.js +4 -0
  33. package/package.json +21 -9
  34. package/src/tui/entry.mjs +26 -25
  35. package/src/tui-compiled/raw/logger.js +24 -0
  36. package/src/tui-compiled/raw/rpc/protocol.js +3 -0
  37. package/src/tui-compiled/raw/rpc/rpc-client.js +7 -0
  38. package/src/tui-compiled/raw/rpc/rpc-dir.js +27 -0
  39. package/src/tui-compiled/raw/selector.js +21 -0
  40. package/src/tui-compiled/raw/shared/0332701351b3eeec-format.js +138 -0
  41. package/src/tui-compiled/raw/shared/04a6357627de5ed0-errors.js +38 -0
  42. package/src/tui-compiled/raw/shared/053cc17b5419261e-codec.js +12 -0
  43. package/src/tui-compiled/raw/shared/0766d78c6f481f18-watcher.js +157 -0
  44. package/src/tui-compiled/raw/shared/08eef45626a94992-reserved.js +13 -0
  45. package/src/tui-compiled/raw/shared/39c3cb05738fcf6d-projection.js +134 -0
  46. package/src/tui-compiled/raw/shared/3c2d4169d00f907e-tui-support.js +5 -0
  47. package/src/tui-compiled/raw/shared/3e7d45a77c6ad4d5-index.js +4 -0
  48. package/src/tui-compiled/raw/shared/415792e85d80819e-capture-sink.js +13 -0
  49. package/src/tui-compiled/raw/shared/42ae93ab554fcec2-open-url.js +28 -0
  50. package/src/tui-compiled/raw/shared/43fc9e6b994519c7-refresh-lock.js +136 -0
  51. package/src/tui-compiled/raw/shared/458b934e92490331-mutate.js +500 -0
  52. package/src/tui-compiled/raw/shared/45bf5343bbbf9add-admission.js +142 -0
  53. package/src/tui-compiled/raw/shared/46f3dff1266160e8-client.js +2 -0
  54. package/src/tui-compiled/raw/shared/4825e03209d6ae3e-with-lock.js +48 -0
  55. package/src/tui-compiled/raw/shared/4f36d333d081d040-merge.js +162 -0
  56. package/src/tui-compiled/raw/shared/54eba94fd64c8c3c-index.js +7 -0
  57. package/src/tui-compiled/raw/shared/7211cfec06a298bc-atomic-write.js +80 -0
  58. package/src/tui-compiled/raw/shared/754d6017f8e419cf-builtins.js +534 -0
  59. package/src/tui-compiled/raw/shared/75bd8c3bd63b315f-identity.js +79 -0
  60. package/src/tui-compiled/raw/shared/7a91bb630e6f4804-index.js +1 -0
  61. package/src/tui-compiled/raw/shared/826342a4b6a8b89b-model.js +16 -0
  62. package/src/tui-compiled/raw/shared/83068c0dbe8a6f13-publication.js +304 -0
  63. package/src/tui-compiled/raw/shared/836fc615de6afbd9-settings.js +120 -0
  64. package/src/tui-compiled/raw/shared/83bc3ba9d0fe2761-runtime.js +68 -0
  65. package/src/tui-compiled/raw/shared/8a18abe4fa2977c8-menu.js +300 -0
  66. package/src/tui-compiled/raw/shared/901e149c5a0dbbff-sticky.js +339 -0
  67. package/src/tui-compiled/raw/shared/9020c407ce64f672-ordered.js +58 -0
  68. package/src/tui-compiled/raw/shared/905bffc0220f43d0-map.js +105 -0
  69. package/src/tui-compiled/raw/shared/94820e324f2b4c09-seam.js +301 -0
  70. package/src/tui-compiled/raw/shared/97484d9bb98c705b-provider-state.js +226 -0
  71. package/src/tui-compiled/raw/shared/9968e3cade6969a1-index.js +2 -0
  72. package/src/tui-compiled/raw/shared/9b4da614c45f9cd0-lock-constants.js +14 -0
  73. package/src/tui-compiled/raw/shared/9d3fc9e37456504e-refresh.js +225 -0
  74. package/src/tui-compiled/raw/shared/9deae3c4da4fd63b-hooks.js +34 -0
  75. package/src/tui-compiled/raw/shared/a09b6a533c11858f-tui-preferences.js +77 -0
  76. package/src/tui-compiled/raw/shared/a62a27a204266acd-attribution.js +60 -0
  77. package/src/tui-compiled/raw/shared/a910277ac43a8626-pull.js +143 -0
  78. package/src/tui-compiled/raw/shared/b85c5301fddcb98a-paths.js +5 -0
  79. package/src/tui-compiled/raw/shared/c14988621dc60a75-port-file.js +217 -0
  80. package/src/tui-compiled/raw/shared/c64d7afbc14ca125-sidebar-file.js +157 -0
  81. package/src/tui-compiled/raw/shared/c6b176708c446d6d-pins.js +34 -0
  82. package/src/tui-compiled/raw/shared/c7d252bedee01600-pi.js +206 -0
  83. package/src/tui-compiled/raw/shared/c852a15cfe489d12-pool.js +120 -0
  84. package/src/tui-compiled/raw/shared/cc9e0702a752cea7-index.js +3 -0
  85. package/src/tui-compiled/raw/shared/cd94316a888b0a8e-schema.js +754 -0
  86. package/src/tui-compiled/raw/shared/d319517e3ea6ad70-redact.js +83 -0
  87. package/src/tui-compiled/raw/shared/d5a8f1061ee2f114-index.js +5 -0
  88. package/src/tui-compiled/raw/shared/d669d72c40e9e116-logger.js +19 -0
  89. package/src/tui-compiled/raw/shared/d7dcba96fea1685c-engine.js +246 -0
  90. package/src/tui-compiled/raw/shared/dbef697d1df1cd84-index.js +5 -0
  91. package/src/tui-compiled/raw/shared/e4acc4cb713f300c-protocol.js +3 -0
  92. package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +501 -0
  93. package/src/tui-compiled/raw/shared/ec971142548df90e-index.js +6 -0
  94. package/src/tui-compiled/raw/shared/f37fcefc7aedbf25-error.js +11 -0
  95. package/src/tui-compiled/raw/shared/fbcdcd0f925e74c0-rpc-client.js +253 -0
  96. package/src/tui-compiled/raw/shared/fd45e82f2f9c0a0d-torn.js +294 -0
  97. package/src/tui-compiled/raw/shared/fe02abeadc535f77-rows.js +1258 -0
  98. package/src/tui-compiled/raw/sidebar-state.js +960 -0
  99. package/src/tui-compiled/raw/tui/command-dialogs.tsx +424 -0
  100. package/src/tui-compiled/raw/tui-preferences.js +135 -0
  101. package/src/tui-compiled/raw/tui.tsx +135 -143
  102. package/src/tui-compiled/runtime/logger.js +24 -0
  103. package/src/tui-compiled/runtime/rpc/protocol.js +3 -0
  104. package/src/tui-compiled/runtime/rpc/rpc-client.js +7 -0
  105. package/src/tui-compiled/runtime/rpc/rpc-dir.js +27 -0
  106. package/src/tui-compiled/runtime/selector.js +21 -0
  107. package/src/tui-compiled/runtime/shared/0332701351b3eeec-format.js +138 -0
  108. package/src/tui-compiled/runtime/shared/04a6357627de5ed0-errors.js +38 -0
  109. package/src/tui-compiled/runtime/shared/053cc17b5419261e-codec.js +12 -0
  110. package/src/tui-compiled/runtime/shared/0766d78c6f481f18-watcher.js +157 -0
  111. package/src/tui-compiled/runtime/shared/08eef45626a94992-reserved.js +13 -0
  112. package/src/tui-compiled/runtime/shared/39c3cb05738fcf6d-projection.js +134 -0
  113. package/src/tui-compiled/runtime/shared/3c2d4169d00f907e-tui-support.js +5 -0
  114. package/src/tui-compiled/runtime/shared/3e7d45a77c6ad4d5-index.js +4 -0
  115. package/src/tui-compiled/runtime/shared/415792e85d80819e-capture-sink.js +13 -0
  116. package/src/tui-compiled/runtime/shared/42ae93ab554fcec2-open-url.js +28 -0
  117. package/src/tui-compiled/runtime/shared/43fc9e6b994519c7-refresh-lock.js +136 -0
  118. package/src/tui-compiled/runtime/shared/458b934e92490331-mutate.js +500 -0
  119. package/src/tui-compiled/runtime/shared/45bf5343bbbf9add-admission.js +142 -0
  120. package/src/tui-compiled/runtime/shared/46f3dff1266160e8-client.js +2 -0
  121. package/src/tui-compiled/runtime/shared/4825e03209d6ae3e-with-lock.js +48 -0
  122. package/src/tui-compiled/runtime/shared/4f36d333d081d040-merge.js +162 -0
  123. package/src/tui-compiled/runtime/shared/54eba94fd64c8c3c-index.js +7 -0
  124. package/src/tui-compiled/runtime/shared/7211cfec06a298bc-atomic-write.js +80 -0
  125. package/src/tui-compiled/runtime/shared/754d6017f8e419cf-builtins.js +534 -0
  126. package/src/tui-compiled/runtime/shared/75bd8c3bd63b315f-identity.js +79 -0
  127. package/src/tui-compiled/runtime/shared/7a91bb630e6f4804-index.js +1 -0
  128. package/src/tui-compiled/runtime/shared/826342a4b6a8b89b-model.js +16 -0
  129. package/src/tui-compiled/runtime/shared/83068c0dbe8a6f13-publication.js +304 -0
  130. package/src/tui-compiled/runtime/shared/836fc615de6afbd9-settings.js +120 -0
  131. package/src/tui-compiled/runtime/shared/83bc3ba9d0fe2761-runtime.js +68 -0
  132. package/src/tui-compiled/runtime/shared/8a18abe4fa2977c8-menu.js +300 -0
  133. package/src/tui-compiled/runtime/shared/901e149c5a0dbbff-sticky.js +339 -0
  134. package/src/tui-compiled/runtime/shared/9020c407ce64f672-ordered.js +58 -0
  135. package/src/tui-compiled/runtime/shared/905bffc0220f43d0-map.js +105 -0
  136. package/src/tui-compiled/runtime/shared/94820e324f2b4c09-seam.js +301 -0
  137. package/src/tui-compiled/runtime/shared/97484d9bb98c705b-provider-state.js +226 -0
  138. package/src/tui-compiled/runtime/shared/9968e3cade6969a1-index.js +2 -0
  139. package/src/tui-compiled/runtime/shared/9b4da614c45f9cd0-lock-constants.js +14 -0
  140. package/src/tui-compiled/runtime/shared/9d3fc9e37456504e-refresh.js +225 -0
  141. package/src/tui-compiled/runtime/shared/9deae3c4da4fd63b-hooks.js +34 -0
  142. package/src/tui-compiled/runtime/shared/a09b6a533c11858f-tui-preferences.js +77 -0
  143. package/src/tui-compiled/runtime/shared/a62a27a204266acd-attribution.js +60 -0
  144. package/src/tui-compiled/runtime/shared/a910277ac43a8626-pull.js +143 -0
  145. package/src/tui-compiled/runtime/shared/b85c5301fddcb98a-paths.js +5 -0
  146. package/src/tui-compiled/runtime/shared/c14988621dc60a75-port-file.js +217 -0
  147. package/src/tui-compiled/runtime/shared/c64d7afbc14ca125-sidebar-file.js +157 -0
  148. package/src/tui-compiled/runtime/shared/c6b176708c446d6d-pins.js +34 -0
  149. package/src/tui-compiled/runtime/shared/c7d252bedee01600-pi.js +206 -0
  150. package/src/tui-compiled/runtime/shared/c852a15cfe489d12-pool.js +120 -0
  151. package/src/tui-compiled/runtime/shared/cc9e0702a752cea7-index.js +3 -0
  152. package/src/tui-compiled/runtime/shared/cd94316a888b0a8e-schema.js +754 -0
  153. package/src/tui-compiled/runtime/shared/d319517e3ea6ad70-redact.js +83 -0
  154. package/src/tui-compiled/runtime/shared/d5a8f1061ee2f114-index.js +5 -0
  155. package/src/tui-compiled/runtime/shared/d669d72c40e9e116-logger.js +19 -0
  156. package/src/tui-compiled/runtime/shared/d7dcba96fea1685c-engine.js +246 -0
  157. package/src/tui-compiled/runtime/shared/dbef697d1df1cd84-index.js +5 -0
  158. package/src/tui-compiled/runtime/shared/e4acc4cb713f300c-protocol.js +3 -0
  159. package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +501 -0
  160. package/src/tui-compiled/runtime/shared/ec971142548df90e-index.js +6 -0
  161. package/src/tui-compiled/runtime/shared/f37fcefc7aedbf25-error.js +11 -0
  162. package/src/tui-compiled/runtime/shared/fbcdcd0f925e74c0-rpc-client.js +253 -0
  163. package/src/tui-compiled/runtime/shared/fd45e82f2f9c0a0d-torn.js +294 -0
  164. package/src/tui-compiled/runtime/shared/fe02abeadc535f77-rows.js +1258 -0
  165. package/src/tui-compiled/runtime/sidebar-state.js +960 -0
  166. package/src/tui-compiled/runtime/tui/command-dialogs.js +378 -0
  167. package/src/tui-compiled/runtime/tui-preferences.js +135 -0
  168. package/src/tui-compiled/runtime/{tui.tsx → tui.js} +288 -316
  169. package/dist/index-4effjmr6.js +0 -2
  170. package/dist/index-9ehhb051.js +0 -2
  171. package/dist/index-g3hsdjh4.js +0 -2
  172. package/dist/index-hh52v8sb.js +0 -2
  173. package/dist/index-jwn4r3sw.js +0 -1
  174. package/dist/index-sq36b120.js +0 -211
  175. package/dist/internal-BTndPmW2.d.ts +0 -914
  176. package/dist/quota-normalize-08hpp51v.js +0 -1
  177. package/dist/sidebar-state-CoKYKcLn.d.ts +0 -220
  178. package/dist/token-util-ypgz7rge.js +0 -1
  179. package/src/tui-compiled/raw/core-account-paths.ts +0 -114
  180. package/src/tui-compiled/raw/core-custody-state.ts +0 -243
  181. package/src/tui-compiled/raw/logger.ts +0 -53
  182. package/src/tui-compiled/raw/rpc-port-file.ts +0 -177
  183. package/src/tui-compiled/raw/rpc-protocol.ts +0 -12
  184. package/src/tui-compiled/raw/rpc-rpc-client.ts +0 -82
  185. package/src/tui-compiled/raw/rpc-rpc-dir.ts +0 -46
  186. package/src/tui-compiled/raw/sidebar-state.ts +0 -1659
  187. package/src/tui-compiled/raw/tui-command-dialogs.tsx +0 -1096
  188. package/src/tui-compiled/raw/tui-preferences.ts +0 -328
  189. package/src/tui-compiled/runtime/core-account-paths.ts +0 -114
  190. package/src/tui-compiled/runtime/core-custody-state.ts +0 -243
  191. package/src/tui-compiled/runtime/logger.ts +0 -53
  192. package/src/tui-compiled/runtime/rpc-port-file.ts +0 -177
  193. package/src/tui-compiled/runtime/rpc-protocol.ts +0 -12
  194. package/src/tui-compiled/runtime/rpc-rpc-client.ts +0 -82
  195. package/src/tui-compiled/runtime/rpc-rpc-dir.ts +0 -46
  196. package/src/tui-compiled/runtime/sidebar-state.ts +0 -1659
  197. package/src/tui-compiled/runtime/tui-command-dialogs.tsx +0 -855
  198. package/src/tui-compiled/runtime/tui-preferences.ts +0 -328
  199. package/src/tui-compiled/shared/internal.ts +0 -6
  200. package/src/tui-compiled/shared/logger.ts +0 -264
  201. package/src/tui-compiled/shared/paths.ts +0 -33
  202. package/src/tui-compiled/shared/refresh-file-lock.ts +0 -384
  203. package/src/tui-compiled/shared/util/error.ts +0 -9
  204. package/src/tui-compiled/shared/util/open-url.ts +0 -30
@@ -0,0 +1,162 @@
1
+ // Merging one observation into a stored quota map.
2
+ //
3
+ // One freshness rule applies everywhere: an observation applies to a key when
4
+ // it is not older than what the key holds, so an equal time applies and the
5
+ // observation applied last wins, as openai-auth's `freshestWindow` does.
6
+ //
7
+ // An observation carries readings plus a coverage list: the (scope, label)
8
+ // pairs it speaks for with authority. Every reading is implicitly covered. A
9
+ // covered pair the observation carries no reading for is reported as having
10
+ // no limit: an existing reading becomes a retirement tombstone, and a key with
11
+ // no entry gets an absence record. A pair outside the coverage is never
12
+ // touched, so a header-shaped partial observation (which covers only what it
13
+ // carries) cannot erase a family limit or the budget.
14
+ import { ALL_SCOPE, entryTime, isQuotaMap, limitKey, } from "./905bffc0220f43d0-map.js";
15
+ /** Thrown by `mergeQuotaObservation` when either argument is malformed. */
16
+ export class QuotaCodecError extends TypeError {
17
+ constructor(message) {
18
+ super(message);
19
+ this.name = 'QuotaCodecError';
20
+ }
21
+ }
22
+ function isRecord(value) {
23
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
24
+ }
25
+ function isFiniteNumber(value) {
26
+ return typeof value === 'number' && Number.isFinite(value);
27
+ }
28
+ function isScope(value) {
29
+ return value === undefined || (typeof value === 'string' && value !== '');
30
+ }
31
+ function isLabel(value) {
32
+ return typeof value === 'string' && value !== '';
33
+ }
34
+ function optionalFinite(record, key) {
35
+ return record[key] === undefined || isFiniteNumber(record[key]);
36
+ }
37
+ function optionalString(record, key) {
38
+ return record[key] === undefined || typeof record[key] === 'string';
39
+ }
40
+ function isObservedReading(value) {
41
+ return (isRecord(value) &&
42
+ isScope(value.scope) &&
43
+ isLabel(value.label) &&
44
+ isFiniteNumber(value.usedPercent) &&
45
+ optionalString(value, 'resetsAt') &&
46
+ (value.windowMinutes === undefined ||
47
+ (isFiniteNumber(value.windowMinutes) && value.windowMinutes > 0)));
48
+ }
49
+ function isObservedPair(value) {
50
+ return isRecord(value) && isScope(value.scope) && isLabel(value.label);
51
+ }
52
+ function isObservedBudget(value) {
53
+ if (!isRecord(value))
54
+ return false;
55
+ if (value.kind === 'cleared')
56
+ return true;
57
+ return (value.kind === 'reading' &&
58
+ typeof value.reached === 'boolean' &&
59
+ optionalFinite(value, 'remainingPercent') &&
60
+ optionalFinite(value, 'usedPercent') &&
61
+ optionalString(value, 'resetsAt') &&
62
+ optionalFinite(value, 'limit') &&
63
+ optionalFinite(value, 'used') &&
64
+ optionalFinite(value, 'remaining') &&
65
+ optionalString(value, 'unit'));
66
+ }
67
+ /** True when `value` is a well-formed observation; a pair read twice is not. */
68
+ export function isQuotaObservation(value) {
69
+ if (!isRecord(value) || !isFiniteNumber(value.checkedAt))
70
+ return false;
71
+ const readings = value.readings ?? [];
72
+ const coverage = value.coverage ?? [];
73
+ if (!Array.isArray(readings) || !Array.isArray(coverage))
74
+ return false;
75
+ const read = new Set();
76
+ for (const reading of readings) {
77
+ if (!isObservedReading(reading))
78
+ return false;
79
+ const key = limitKey(reading.scope ?? ALL_SCOPE, reading.label);
80
+ if (read.has(key))
81
+ return false;
82
+ read.add(key);
83
+ }
84
+ if (!coverage.every(isObservedPair))
85
+ return false;
86
+ return value.budget === undefined || isObservedBudget(value.budget);
87
+ }
88
+ function compareEntries(left, right) {
89
+ if (left.scope !== right.scope)
90
+ return left.scope < right.scope ? -1 : 1;
91
+ if (left.label !== right.label)
92
+ return left.label < right.label ? -1 : 1;
93
+ return 0;
94
+ }
95
+ function mergeBudget(stored, observed, checkedAt) {
96
+ if (observed === undefined)
97
+ return stored;
98
+ if (stored !== undefined && checkedAt < stored.checkedAt)
99
+ return stored;
100
+ return { ...observed, checkedAt };
101
+ }
102
+ /**
103
+ * Applies `observation` to `stored` (undefined for a row with no map yet) and
104
+ * returns the new map. Pure: neither argument is modified. Throws
105
+ * `QuotaCodecError` when either argument is malformed, so a store refuses the
106
+ * write rather than persisting a map it could not read back.
107
+ */
108
+ export function mergeQuotaObservation(stored, observation) {
109
+ if (stored !== undefined && !isQuotaMap(stored)) {
110
+ throw new QuotaCodecError('stored quota map is malformed');
111
+ }
112
+ if (!isQuotaObservation(observation)) {
113
+ throw new QuotaCodecError('quota observation is malformed');
114
+ }
115
+ const base = stored ?? { limits: [] };
116
+ const at = observation.checkedAt;
117
+ const entries = new Map();
118
+ for (const entry of base.limits) {
119
+ entries.set(limitKey(entry.scope, entry.label), entry);
120
+ }
121
+ const applies = (key) => {
122
+ const existing = entries.get(key);
123
+ return existing === undefined || at >= entryTime(existing);
124
+ };
125
+ const carried = new Set();
126
+ for (const reading of observation.readings ?? []) {
127
+ const scope = reading.scope ?? ALL_SCOPE;
128
+ const key = limitKey(scope, reading.label);
129
+ carried.add(key);
130
+ if (!applies(key))
131
+ continue;
132
+ entries.set(key, {
133
+ scope,
134
+ label: reading.label,
135
+ kind: 'reading',
136
+ checkedAt: at,
137
+ usedPercent: reading.usedPercent,
138
+ ...(reading.resetsAt === undefined ? {} : { resetsAt: reading.resetsAt }),
139
+ ...(reading.windowMinutes === undefined
140
+ ? {}
141
+ : { windowMinutes: reading.windowMinutes }),
142
+ });
143
+ }
144
+ for (const pair of observation.coverage ?? []) {
145
+ const scope = pair.scope ?? ALL_SCOPE;
146
+ const key = limitKey(scope, pair.label);
147
+ if (carried.has(key) || !applies(key))
148
+ continue;
149
+ const existing = entries.get(key);
150
+ entries.set(key, existing === undefined || existing.kind === 'absent'
151
+ ? { scope, label: pair.label, kind: 'absent', checkedAt: at }
152
+ : { scope, label: pair.label, kind: 'retired', retiredAt: at });
153
+ }
154
+ // Keys this module does not recognise are carried over untouched.
155
+ const { limits: _limits, budget: _budget, ...unknownKeys } = base;
156
+ const budget = mergeBudget(base.budget, observation.budget, at);
157
+ return {
158
+ ...unknownKeys,
159
+ limits: [...entries.values()].sort(compareEntries),
160
+ ...(budget === undefined ? {} : { budget }),
161
+ };
162
+ }
@@ -0,0 +1,7 @@
1
+ export { PoolOperationError, PoolReentryError } from "./04a6357627de5ed0-errors.js";
2
+ export { countUnknownIdentityRows, DUPLICATE_IDENTITY_REASON, } from "./75bd8c3bd63b315f-identity.js";
3
+ export { openPoolStore } from "./c852a15cfe489d12-pool.js";
4
+ export { DECLINE_TRANSITION } from "./97484d9bb98c705b-provider-state.js";
5
+ export { POOL_LOCK_DEFAULTS } from "./43fc9e6b994519c7-refresh-lock.js";
6
+ export { fingerprintOf, LEGACY_STORE_VERSION, POOL_KEY, POOL_ROWS_KEY, POOL_SCHEMA_VERSION, PROVIDER_STATE_KEY, REFRESH_STAMP_TOLERANCE_MS, rowLockKey, } from "./cd94316a888b0a8e-schema.js";
7
+ export { POOL_OWNED_KEYS } from "./836fc615de6afbd9-settings.js";
@@ -0,0 +1,80 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { mkdir, open, rename, rm } from "node:fs/promises";
3
+ import { dirname } from "node:path";
4
+ /** Internal classification of fsync failures, including a failure after rename. */
5
+ export class AtomicSyncError extends Error {
6
+ constructor(cause) {
7
+ super('file or directory sync failed', { cause });
8
+ this.name = 'AtomicSyncError';
9
+ }
10
+ }
11
+ export async function writeJsonAtomic(path, value, options = {}) {
12
+ await writeJsonAtomicTracked(path, value, options);
13
+ }
14
+ /**
15
+ * Notify internal callers at the rename. The store records committed writes
16
+ * and removed ids here, because a later directory sync cannot undo the rename.
17
+ */
18
+ export async function writeJsonAtomicTracked(path, value, options, onRenamed) {
19
+ await mkdir(dirname(path), { recursive: true });
20
+ const tempPath = `${path}.${(options.stageName ?? randomUUID)()}.tmp`;
21
+ let handle;
22
+ let created = false;
23
+ try {
24
+ handle = await open(tempPath, 'wx', 0o600);
25
+ created = true;
26
+ await handle.writeFile(options.serialize
27
+ ? options.serialize(value)
28
+ : `${JSON.stringify(value, null, 2)}\n`, 'utf8');
29
+ await handle.chmod(0o600);
30
+ if (options.durable) {
31
+ try {
32
+ await handle.sync();
33
+ }
34
+ catch (cause) {
35
+ throw new AtomicSyncError(cause);
36
+ }
37
+ }
38
+ await handle.close();
39
+ handle = undefined;
40
+ await options.beforeRename?.();
41
+ await rename(tempPath, path);
42
+ created = false;
43
+ onRenamed?.();
44
+ if (options.durable) {
45
+ const directory = await open(dirname(path), 'r');
46
+ try {
47
+ await directory.sync();
48
+ }
49
+ catch (cause) {
50
+ throw new AtomicSyncError(cause);
51
+ }
52
+ finally {
53
+ await directory.close();
54
+ }
55
+ }
56
+ }
57
+ finally {
58
+ await handle?.close().catch(() => { });
59
+ // A failed write can leave partial bytes, but a collision is not ours to remove.
60
+ if (created)
61
+ await rm(tempPath, { force: true }).catch(() => { });
62
+ }
63
+ }
64
+ /** Make an already renamed file and its directory durable without rewriting bytes. */
65
+ export async function syncJsonFile(path) {
66
+ const file = await open(path, 'r');
67
+ try {
68
+ await file.sync();
69
+ }
70
+ finally {
71
+ await file.close();
72
+ }
73
+ const directory = await open(dirname(path), 'r');
74
+ try {
75
+ await directory.sync();
76
+ }
77
+ finally {
78
+ await directory.close();
79
+ }
80
+ }