@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,2 @@
1
+ import{createRequire as u}from"node:module";var l=Object.create;var{getPrototypeOf:m,defineProperty:k,getOwnPropertyNames:n}=Object;var o=Object.prototype.hasOwnProperty;function p(a){return this[a]}var q,r,x=(a,b,c)=>{var e=a!=null&&typeof a==="object";if(e){var h=b?q??=new WeakMap:r??=new WeakMap,g=h.get(a);if(g)return g}c=a!=null?l(m(a)):{};let d=b||!a||!a.__esModule?k(c,"default",{value:a,enumerable:!0}):c;for(let f of n(a))if(!o.call(d,f))k(d,f,{get:p.bind(a,f),enumerable:!0});if(e)h.set(a,d);return d};var y=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports);var s=(a)=>a;function t(a,b){this[a]=s.bind(null,b)}var z=(a,b)=>{for(var c in b)k(a,c,{get:b[c],enumerable:!0,configurable:!0,set:t.bind(b,c)})};var B=u(import.meta.url),v=Symbol.dispose||Symbol.for("Symbol.dispose"),w=Symbol.asyncDispose||Symbol.for("Symbol.asyncDispose"),C=(a,b,c)=>{if(b!=null){if(typeof b!=="object"&&typeof b!=="function")throw TypeError('Object expected to be assigned to "using" declaration');var e;if(c)e=b[w];if(e===void 0)e=b[v];if(typeof e!=="function")throw TypeError("Object not disposable");a.push([c,e,b])}else if(c)a.push([c]);return b},D=(a,b,c)=>{var e=typeof SuppressedError==="function"?SuppressedError:function(d,f,i,j){return j=Error(i),j.name="SuppressedError",j.error=d,j.suppressed=f,j},h=(d)=>b=c?new e(d,b,"An error was suppressed during disposal"):(c=!0,d),g=(d)=>{while(d=a.pop())try{var f=d[1]&&d[1].call(d[2]);if(d[0])return Promise.resolve(f).then(g,(i)=>(h(i),g()))}catch(i){h(i)}if(c)throw b};return g()};
2
+ export{x as sc,y as tc,z as uc,B as vc,C as wc,D as xc};
@@ -0,0 +1,2 @@
1
+ import{appendFileSync as u,chmodSync as c,existsSync as A,renameSync as z,statSync as s}from"node:fs";var y=/^(authorization|x-api-key|cookie|set-cookie|refresh|access|token)$/i,h=/\b(Bearer\s+[\w.-]+|sk-[\w-]+|eyJ[\w.-]+)\b|ckh_[A-Za-z0-9_-]{20,}/g;function v(J){return J instanceof Error||Object.prototype.toString.call(J)==="[object Error]"}function T(J={}){let U=[h,...J.extraValuePatterns??[]].map((q)=>new RegExp(q.source,q.flags.includes("g")?q.flags:`${q.flags}g`));function Z(q){let H=q.toLowerCase().replace(/[-_]/g,"");return y.test(q)||H.includes("apikey")||H.endsWith("secret")||H.endsWith("password")||H.endsWith("token")&&!H.endsWith("tokens")||!!J.extraSecretKeys?.(H)}function W(q){let H=q,Q=[["name",q.name],["message",q.message],["stack",q.stack]];for(let $ of["code","status","cause"])if(H[$]!==void 0)Q.push([$,H[$]]);let I=new Set(Q.map(([$])=>$));for(let $ of Object.entries(q))if(!I.has($[0]))Q.push($);return Q}function j(q,H,Q,I=0){if(typeof q==="string")return U.reduce(($,Y)=>$.replace(Y,"***REDACTED***"),q);if(!q||typeof q!=="object")return q;if(Q.has(q))return"[Circular]";Q.add(q);try{if(Array.isArray(q))return q.map((X)=>j(X,H,Q,I));let $=v(q);if($&&I>=8)return"[Truncated]";let Y=$?I+1:I;return Object.fromEntries(($?W(q):Object.entries(q)).map(([X,C])=>[X,H&&Z(X)?"***REDACTED***":j(C,H,Q,Y)]))}finally{Q.delete(q)}}return{redact:(q)=>j(q,!0,new WeakSet),redactStrings:(q)=>j(q,!1,new WeakSet)}}var K=T(),m=K.redact,f=K.redactStrings;var x={error:0,warn:1,info:2,debug:3,trace:4},d=5242880,o=3;function O(J){try{c(J,384)}catch{}}function i(J){try{if(!(A(J)&&s(J).size>=d))return;for(let Z=o-1;Z>=1;Z--)if(A(`${J}.${Z}`)){let W=`${J}.${Z+1}`;z(`${J}.${Z}`,W),O(W)}let U=`${J}.1`;z(J,U),O(U)}catch{}}function n(J){try{return` ${JSON.stringify(J)}`}catch{return" [unserializable]"}}function t(J){let U,Z,W,j=T(),q,H=[],Q;function I(G){U=G.file,Z=G.level,j=T(G),q=G.captureSink}function $(G){if(G===void 0||G in x)W=G}function Y(){if(U===void 0)return;return(typeof U==="function"?U():U)||void 0}function X(){if(W)return W;let G=typeof Z==="function"?Z():Z;if(G&&G in x)return G;return"info"}function C(){if(Q)clearTimeout(Q),Q=void 0;if(!H.length)return;let G;try{G=Y()}catch{H=[];return}let V=H.join("");if(H=[],!G)return;try{if(i(G),A(G))O(G);u(G,V,{encoding:"utf8",mode:384})}catch{}}function E(){if(!Q)Q=setTimeout(()=>{Q=void 0,C()},500)}function M(G,V,B,P){if(U===void 0&&q===void 0)return;try{if(x[V]>x[X()])return;let F=j.redactStrings(B),w;try{w=j.redact(P)}catch{w="[unserializable]"}let g=`[${new Date().toISOString()}] ${V.toUpperCase()} [${G}] ${F}`+(P===void 0?"":n(w))+`
2
+ `;try{q?.({channel:G,level:V,message:F,data:w})}catch{}if(U===void 0)return;if(H.push(g),H.length>=50)C();else E()}catch{}}function S(G){return{error:(V,B)=>M(G,"error",V,B),warn:(V,B)=>M(G,"warn",V,B),info:(V,B)=>M(G,"info",V,B),debug:(V,B)=>M(G,"debug",V,B),trace:(V,B)=>M(G,"trace",V,B)}}function p(){if(H=[],Q)clearTimeout(Q),Q=void 0;U=void 0,Z=void 0,W=void 0,j=T(),q=void 0}if(J)I(J);return{configure:I,createLogger:S,setLogLevel:$,flushLogs:C,reset:p}}var N=t();function _(J){N.configure(J);let{configure:U,createLogger:Z,setLogLevel:W,flushLogs:j}=N;return{configure:U,createLogger:Z,setLogLevel:W,flushLogs:j}}function D(J){N.setLogLevel(J)}function R(){N.flushLogs()}function b(J){return N.createLogger(J)}function L(J){return J==="chatgptaccountid"||J==="email"||J==="orgname"||J==="organizationname"}var k=T({extraSecretKeys:L}),MJ=k.redact,NJ=k.redactStrings;function wJ(J){_({...J,extraSecretKeys:L})}function OJ(J){if(J instanceof Error)return J.message;if(typeof J==="string")return J;try{return JSON.stringify(J)}catch{return String(J)}}function PJ(J){return"notify"in J}import{basename as a,dirname as e,join as JJ}from"node:path";var qJ="openai-auth.json",GJ="openai-auth-state.json";function zJ(J){return a(J)===qJ?JJ(e(J),GJ):`${J}.state.json`}import{execFileSync as HJ,spawn as QJ}from"node:child_process";function bJ(J,U=process.platform,Z=HJ,W=QJ){try{if(U==="win32"){let j=`Start-Process '${J.replaceAll("'","''")}'`,q=Buffer.from(j,"utf16le").toString("base64"),H=W("powershell.exe",["-NoProfile","-NonInteractive","-WindowStyle","Hidden","-EncodedCommand",q],{stdio:"ignore",windowsHide:!0});return H.on("error",()=>{}),H.unref(),H.pid!==void 0}return Z(U==="darwin"?"open":"xdg-open",[J],{stdio:"ignore",timeout:3000}),!0}catch{return!1}}export{T as dc,D as ec,R as fc,b as gc,NJ as hc,wJ as ic,qJ as jc,zJ as kc,OJ as lc,PJ as mc,bJ as nc};
@@ -0,0 +1,2 @@
1
+ import{Lb as n,Pb as i,Qb as t,Rb as p,Sb as b}from"./index-jyr8y8k4.js";import{fc as ZZ,gc as $Z,ic as xZ}from"./index-bmd7x5aq.js";var L="all",tZ=Object.freeze(["primary"]);function LZ(Z){return Z.kind==="retired"?Z.retiredAt:Z.checkedAt}function q(Z,$){return JSON.stringify([Z,$])}function l(Z){return typeof Z==="object"&&Z!==null&&!Array.isArray(Z)}function N(Z){return typeof Z==="number"&&Number.isFinite(Z)}function HZ(Z){return typeof Z==="string"&&Z.length>0}function T(Z,$,J){return Z[$]===void 0||J(Z[$])}function eZ(Z){return N(Z)&&Z>0}function u(Z){return typeof Z==="string"}function Z1(Z){if(!l(Z)||!HZ(Z.scope)||!HZ(Z.label))return!1;switch(Z.kind){case"reading":return N(Z.checkedAt)&&N(Z.usedPercent)&&T(Z,"resetsAt",u)&&T(Z,"windowMinutes",eZ);case"retired":return N(Z.retiredAt);case"absent":return N(Z.checkedAt);default:return!1}}function $1(Z){if(!l(Z)||!N(Z.checkedAt))return!1;if(Z.kind==="cleared")return!0;return Z.kind==="reading"&&typeof Z.reached==="boolean"&&T(Z,"remainingPercent",N)&&T(Z,"usedPercent",N)&&T(Z,"resetsAt",u)&&T(Z,"limit",N)&&T(Z,"used",N)&&T(Z,"remaining",N)&&T(Z,"unit",u)}function I(Z){if(!l(Z)||!Array.isArray(Z.limits))return!1;let $=new Set;for(let J of Z.limits){if(!Z1(J))return!1;let X=q(J.scope,J.label);if($.has(X))return!1;$.add(X)}return T(Z,"budget",$1)}class w extends TypeError{constructor(Z){super(Z);this.name="QuotaCodecError"}}function v(Z){return typeof Z==="object"&&Z!==null&&!Array.isArray(Z)}function y(Z){return typeof Z==="number"&&Number.isFinite(Z)}function NZ(Z){return Z===void 0||typeof Z==="string"&&Z!==""}function RZ(Z){return typeof Z==="string"&&Z!==""}function S(Z,$){return Z[$]===void 0||y(Z[$])}function r(Z,$){return Z[$]===void 0||typeof Z[$]==="string"}function J1(Z){return v(Z)&&NZ(Z.scope)&&RZ(Z.label)&&y(Z.usedPercent)&&r(Z,"resetsAt")&&(Z.windowMinutes===void 0||y(Z.windowMinutes)&&Z.windowMinutes>0)}function X1(Z){return v(Z)&&NZ(Z.scope)&&RZ(Z.label)}function V1(Z){if(!v(Z))return!1;if(Z.kind==="cleared")return!0;return Z.kind==="reading"&&typeof Z.reached==="boolean"&&S(Z,"remainingPercent")&&S(Z,"usedPercent")&&r(Z,"resetsAt")&&S(Z,"limit")&&S(Z,"used")&&S(Z,"remaining")&&r(Z,"unit")}function TZ(Z){if(!v(Z)||!y(Z.checkedAt))return!1;let $=Z.readings??[],J=Z.coverage??[];if(!Array.isArray($)||!Array.isArray(J))return!1;let X=new Set;for(let V of $){if(!J1(V))return!1;let Y=q(V.scope??L,V.label);if(X.has(Y))return!1;X.add(Y)}if(!J.every(X1))return!1;return Z.budget===void 0||V1(Z.budget)}function Y1(Z,$){if(Z.scope!==$.scope)return Z.scope<$.scope?-1:1;if(Z.label!==$.label)return Z.label<$.label?-1:1;return 0}function z1(Z,$,J){if($===void 0)return Z;if(Z!==void 0&&J<Z.checkedAt)return Z;return{...$,checkedAt:J}}function o(Z,$){if(Z!==void 0&&!I(Z))throw new w("stored quota map is malformed");if(!TZ($))throw new w("quota observation is malformed");let J=Z??{limits:[]},X=$.checkedAt,V=new Map;for(let K of J.limits)V.set(q(K.scope,K.label),K);let Y=(K)=>{let Q=V.get(K);return Q===void 0||X>=LZ(Q)},G=new Set;for(let K of $.readings??[]){let Q=K.scope??L,U=q(Q,K.label);if(G.add(U),!Y(U))continue;V.set(U,{scope:Q,label:K.label,kind:"reading",checkedAt:X,usedPercent:K.usedPercent,...K.resetsAt===void 0?{}:{resetsAt:K.resetsAt},...K.windowMinutes===void 0?{}:{windowMinutes:K.windowMinutes}})}for(let K of $.coverage??[]){let Q=K.scope??L,U=q(Q,K.label);if(G.has(U)||!Y(U))continue;let P=V.get(U);V.set(U,P===void 0||P.kind==="absent"?{scope:Q,label:K.label,kind:"absent",checkedAt:X}:{scope:Q,label:K.label,kind:"retired",retiredAt:X})}let{limits:z,budget:j,...B}=J,D=z1(J.budget,$.budget,X);return{...B,limits:[...V.values()].sort(Y1),...D===void 0?{}:{budget:D}}}var G1=Object.freeze({validate:I,merge:o});var MZ=900000,CZ="no quota reading yet",FZ="no limits reported";function EZ(Z){let $=Math.max(1,Math.round(Z/60000));if($<60)return`${$}m`;let J=Math.round($/60);if(J<24)return`${J}h`;return`${Math.max(1,Math.round($/1440))}d`}function j1(Z){if(Z%1440===0)return`${Z/1440}d`;if(Z%60===0)return`${Z/60}h`;return`${Z}m`}function h(Z){if(Z.scope!==L||Z.windowMinutes===void 0)return Z.label;return j1(Z.windowMinutes)}function OZ(Z){return`${Math.round(Math.min(100,Math.max(0,Z)))}% left`}function _Z(Z,$){if(Z===void 0)return"";let J=Date.parse(Z);if(!Number.isFinite(J)||J<=$)return"";return`, resets ${EZ(J-$)}`}function U1(Z,$){let J=Z.windowMinutes,X=$.windowMinutes;if(J!==void 0&&X!==void 0&&J!==X)return J-X;if(J===void 0!==(X===void 0))return J===void 0?1:-1;if(Z.scope!==$.scope){if(Z.scope===L)return-1;if($.scope===L)return 1;return Z.scope<$.scope?-1:1}return Z.label<$.label?-1:Z.label>$.label?1:0}function qZ(Z,$){if(!Z)return[];let{now:J}=$,X=($.form??"full")==="full",V=[],Y=[],G=Z.limits.filter((j)=>j.kind==="reading"&&j.remainingPercent!==void 0).sort(U1);for(let j of G)Y.push(j.checkedAt),V.push(`${h(j)} ${OZ(j.remainingPercent??0)}${X?_Z(j.resetsAt,J):""}`);let z=Z.budget;if(z){Y.push(z.checkedAt);let j=z.reached?"credits spent":z.remainingPercent!==void 0?`credits ${OZ(z.remainingPercent)}`:"credits available";V.push(`${j}${X?_Z(z.resetsAt,J):""}`)}if(Y.length>0){let j=J-Math.min(...Y);if(j>($.staleAfterMs??MZ))V.push(`checked ${EZ(j)} ago`)}return V}function a(Z,$){let J=qZ(Z,$);if(J.length>0)return J.join(" · ");return Z&&Z.limits.length>0?FZ:CZ}function B1(Z){if(Z.kind==="retired")return{scope:Z.scope,label:Z.label,kind:"retired",checkedAt:Z.retiredAt};if(Z.kind==="absent")return{scope:Z.scope,label:Z.label,kind:"absent",checkedAt:Z.checkedAt};return{scope:Z.scope,label:Z.label,kind:"reading",checkedAt:Z.checkedAt,usedPercent:Z.usedPercent,remainingPercent:100-Z.usedPercent,...Z.windowMinutes===void 0?{}:{windowMinutes:Z.windowMinutes},...Z.resetsAt===void 0?{}:{resetsAt:Z.resetsAt}}}function Q1(Z,$){let J=Z.windowMinutes!==void 0,X=$.windowMinutes!==void 0;if(J!==X)return J?-1:1;if(J&&X&&Z.windowMinutes!==$.windowMinutes)return($.windowMinutes??0)-(Z.windowMinutes??0);if(Z.label!==$.label)return Z.label<$.label?-1:1;return 0}function K1(Z){return{checkedAt:Z.checkedAt,reached:Z.reached,...Z.remainingPercent===void 0?{}:{remainingPercent:Z.remainingPercent},...Z.resetsAt===void 0?{}:{resetsAt:Z.resetsAt}}}function s(Z,$=L){let J=new Map;for(let j of Z?.limits??[]){if(j.scope!==$&&j.scope!==L)continue;let B=J.get(j.label);if(B===void 0){J.set(j.label,j);continue}let D=j.scope===L?B:j,K=j.scope===L?j:B;J.set(j.label,D.kind==="reading"?D:K)}let X=[...J.values()].map(B1).sort(Q1),V=X.filter((j)=>j.kind==="reading"),Y=V.length>0?V:X,G=Y.length>0?Math.min(...Y.map((j)=>j.checkedAt)):void 0,z=Z?.budget?.kind==="reading"?K1(Z.budget):void 0;return{scope:$,limits:X,...G===void 0?{}:{checkedAt:G},...z===void 0?{}:{budget:z}}}function D1(Z,$){let J=Z?.budget;if(J?.reached!==!0||typeof J.resetsAt!=="string")return;let X=Date.parse(J.resetsAt);if(!Number.isFinite(X)||X<=$)return;return{resetsAt:J.resetsAt,resetAtMs:X}}function P1(Z){return Z.kind==="reading"&&typeof Z.usedPercent==="number"&&Number.isFinite(Z.usedPercent)&&Z.usedPercent>=100}function W1(Z,$){if(typeof Z.resetsAt!=="string")return;let J=Date.parse(Z.resetsAt);return Number.isFinite(J)&&J>$?J:void 0}import{createHash as q1}from"node:crypto";import{constants as x1,copyFileSync as I1,mkdirSync as S1,statSync as b1}from"node:fs";import{readFile as f1}from"node:fs/promises";import{homedir as A1,tmpdir as k1}from"node:os";import{dirname as w1,join as XZ}from"node:path";import{chmod as H1,mkdir as L1,readFile as N1}from"node:fs/promises";import{dirname as R1}from"node:path";function e(Z){let{path:$,defaultValue:J,normalize:X}=Z,V=Promise.resolve(),Y=(U)=>{if(U==="")return J;try{return X(JSON.parse(U))}catch{return J}},G=async()=>{try{return await N1($,"utf8")}catch(U){if(U.code==="ENOENT")return"";throw U}},z=async()=>{try{return Y(await G())}catch{return J}},j=(U,P)=>{let W=V.then(U).then((H)=>P?.onResult?.(H));return V=W.catch(()=>{}),W},B={...b.sidebar,name:Z.lockName??b.sidebar.name,timeoutMs:Z.timeoutMs??b.sidebar.timeoutMs},D=async(U,P,W)=>{await n($,P,{serialize:JSON.stringify,beforeRename:async()=>{await W?.beforeCommit?.(),await U.assertOwned()}}),await W?.afterRename?.();try{return await U.assertOwned(),!0}catch(H){if(H instanceof t)return!1;throw H}},K=async(U,P,W)=>{Z.logger?.warn("sidebar lock lost after rename; repairing write",{path:$});try{let H=await p($,B,async(O)=>{let R=U(await z(),P);if(R===void 0)return"skipped";return await D(O,R,W)?"written":"lost-again"});if(H==="lost-again")Z.logger?.warn("sidebar repair lost its lock after rename",{path:$});return{status:"lost-after-rename",repair:H}}catch(H){if(!(H instanceof i))throw H;return Z.logger?.warn("sidebar repair lock unavailable; repair skipped",{path:$}),{status:"lost-after-rename",repair:"lock-unavailable"}}},Q=async(U,P)=>{let W=P,H=R1($),O=Z.secureDir??!0;if(await L1(H,{recursive:!0,mode:448}),O)await H1(H,448).catch((x)=>{Z.logger?.warn("sidebar directory permission remediation failed",{error:x instanceof Error?x.message:String(x)})});let R=await p($,B,async(x)=>{let KZ=async(E)=>({value:E,held:await D(x,E,W)});for(let E=0;E<3;E+=1){let PZ=await G(),WZ=U(Y(PZ));if(WZ===void 0)return;if(E===0)await W?.beforeRecheck?.();if(await G()!==PZ)continue;return await KZ(WZ)}let DZ=U(await z());return DZ===void 0?void 0:await KZ(DZ)});if(R===void 0)return{status:"skipped"};if(R.held)return{status:"written"};let QZ=P?.repair??Z.repair;if(!QZ)return Z.logger?.warn("sidebar lock lost after rename; write not repaired",{path:$}),{status:"lost-after-rename",repair:"none"};return await K(QZ,R.value,W)};return{read:z,write:(U,P)=>j(()=>Q(()=>U,P),P),update:(U,P)=>j(()=>Q(U,P),P)}}import{tmpdir as T1}from"node:os";import{join as O1}from"node:path";var _1=["error","warn","info","debug","trace"];function M1(){return process.env.OPENCODE_OPENAI_AUTH_LOG_FILE??O1(T1(),"opencode-openai-auth.log")}function C1(){let Z=process.env.OPENCODE_OPENAI_AUTH_LOG_LEVEL;return Z&&_1.includes(Z)?Z:void 0}xZ({file:M1,level:C1});process.on("exit",ZZ);var zZ=["primary","secondary"],F1={primary:300,secondary:10080};function E1(Z,$){return h({scope:"all",label:$,windowMinutes:Z})}function c3(Z){if(!Z)return[];let $=[];for(let J of zZ){let X=Z[J];if(!X)continue;let V=X.windowMinutes,Y=V!==void 0&&Number.isFinite(V)&&V>0?V:F1[J];$.push({key:J,label:E1(V,J),window:X,windowMs:Y*60000})}return $}var f=$Z("sidebar"),y1="OPENCODE_OPENAI_AUTH_SIDEBAR_STATE_FILE";function vZ(){let Z=process.env.XDG_STATE_HOME||XZ(A1(),".local","state");return XZ(Z,"cortexkit","openai-auth","sidebar-state.json")}var hZ=XZ(k1(),"opencode-openai-auth","sidebar-state.json");function i3(Z){hZ=Z,VZ.clear()}var v1=/^[a-f0-9]{64}$/,GZ=604800000,pZ=256,mZ=3600000;function C(Z){return q1("sha256").update(Z).digest("hex")}function h1(Z){return typeof Z==="number"&&Number.isFinite(Z)&&Z>=0?Z:void 0}function gZ(Z){let $=h1(Z);return $!==void 0?{resetCredits:$}:{}}function p1(Z){if(Z===null||typeof Z!=="object"||Array.isArray(Z))return;let $={};for(let[J,X]of Object.entries(Z)){if(X===null||typeof X!=="object"||Array.isArray(X))continue;let V=X;if(typeof V.activeId!=="string"||typeof V.route!=="string"||typeof V.updatedAt!=="number"||!Number.isFinite(V.updatedAt))continue;$[J]={activeId:V.activeId,route:V.route,updatedAt:V.updatedAt}}return Object.keys($).length>0?$:void 0}function m1(Z){if(Z===null||typeof Z!=="object"||Array.isArray(Z))return;let $={};for(let[J,X]of Object.entries(Z)){if(!v1.test(J)||X===null||typeof X!=="object"||Array.isArray(X))continue;let V=X;if(typeof V.accountId!=="string"||V.accountId.length===0||typeof V.assignedAt!=="number"||!Number.isFinite(V.assignedAt)||V.assignedAt<0||typeof V.lastSeenAt!=="number"||!Number.isFinite(V.lastSeenAt)||V.lastSeenAt<0||typeof V.inputBytes!=="number"||!Number.isFinite(V.inputBytes)||V.inputBytes<0)continue;let Y=V.quotaCheckedAt;if(Y!==void 0&&(typeof Y!=="number"||!Number.isFinite(Y)||Y<0))continue;let G=V.wireAccountId;$[J]={accountId:V.accountId,assignedAt:V.assignedAt,lastSeenAt:V.lastSeenAt,inputBytes:V.inputBytes,...Y===void 0?{}:{quotaCheckedAt:Y},...typeof G==="string"?{wireAccountId:G}:{}}}return Object.keys($).length>0?$:void 0}function _(){let Z=process.env[y1];if(Z)return Z;let $=vZ();if(!VZ.has($))VZ.add($),g1($,hZ);return $}var VZ=new Set;function g1(Z,$){try{S1(w1(Z),{recursive:!0,mode:448}),I1($,Z,x1.COPYFILE_EXCL)}catch{}}var A={main:{quota:null,killed:!1},fallbacks:[],activeId:void 0,route:"main",lastUpdated:0};function c(Z){if(Z===null||typeof Z!=="object"||Array.isArray(Z))return A;let $=Z,J=$.main,X;if(J!==null&&typeof J==="object"&&!Array.isArray(J)){let U=J;X={quota:"quota"in U?U.quota:null,killed:typeof U.killed==="boolean"?U.killed:!1,...typeof U.mainAccountId==="string"?{mainAccountId:U.mainAccountId}:{},...typeof U.quotaBackedOff==="boolean"?{quotaBackedOff:U.quotaBackedOff}:{},...typeof U.quotaBackoffUntil==="number"?{quotaBackoffUntil:U.quotaBackoffUntil}:{},...typeof U.refreshBackedOff==="boolean"?{refreshBackedOff:U.refreshBackedOff}:{},...typeof U.refreshBackoffUntil==="number"?{refreshBackoffUntil:U.refreshBackoffUntil}:{},...gZ(U.resetCredits)}}else X={quota:null,killed:!1};let V=IZ($.fallbacks),Y=Array.isArray($.vaultAccounts)?IZ($.vaultAccounts):void 0,G=typeof $.activeId==="string"?$.activeId:void 0,z=typeof $.route==="string"?$.route:A.route,j=typeof $.lastUpdated==="number"?$.lastUpdated:0,B=typeof $.planType==="string"?$.planType:void 0,D=typeof $.credits==="number"?$.credits:void 0,K=p1($.activeRouting),Q=m1($.stickyAssignments);return{main:X,fallbacks:V,activeId:G,route:z,lastUpdated:j,...K!==void 0?{activeRouting:K}:{},...Q!==void 0?{stickyAssignments:Q}:{},...B!==void 0?{planType:B}:{},...D!==void 0?{credits:D}:{},...$.accountPool===!0?{accountPool:!0}:{},...Y!==void 0?{vaultAccounts:Y}:{}}}function IZ(Z){if(!Array.isArray(Z))return[];return Z.filter(($)=>$!==null&&typeof $==="object"&&!Array.isArray($)&&typeof $.id==="string").map(($)=>({id:$.id,label:typeof $.label==="string"?$.label:void 0,...typeof $.accountId==="string"?{accountId:$.accountId}:{},quota:"quota"in $?$.quota:null,killed:typeof $.killed==="boolean"?$.killed:!1,enabled:typeof $.enabled==="boolean"?$.enabled:!0,...gZ($.resetCredits)}))}function jZ(Z){return[...Z.fallbacks,...Z.vaultAccounts??[]]}async function d1(Z=_()){try{let $=await f1(Z,"utf8");return c(JSON.parse($))}catch{return A}}var c1=3600000,SZ=128;function dZ(Z,$,J=Date.now()){if(!(Z.updatedAt>=J-c1&&Z.updatedAt<=J))return!1;if($===void 0)return!0;return Z.activeId==="main"||$.some((V)=>V.enabled!==!1&&V.killed!==!0&&V.id===Z.activeId)}function u1(Z,$=Date.now()){let J=Z?.spendControl;if(J?.reached!==!0||typeof J.resetsAt!=="string")return;let X=Date.parse(J.resetsAt);if(!Number.isFinite(X)||X<=$)return;return{resetsAt:J.resetsAt,resetAtMs:X}}function l1(Z,$=Date.now()){let J;for(let V of zZ){let Y=Z?.[V];if(typeof Y?.resetsAt!=="string"||!Number.isFinite(Y.usedPercent)||Y.usedPercent<100)continue;let G=Date.parse(Y.resetsAt);if(!Number.isFinite(G)||G<=$)continue;if(!J||G<J.resetAtMs)J={resetsAt:Y.resetsAt,resetAtMs:G}}let X=u1(Z,$);if(X&&(!J||X.resetAtMs<J.resetAtMs))J=X;return J}function m(Z,$=Date.now()){return l1(Z,$)!==void 0}function r1(Z,$,J=Date.now()){if(!$||Z.route!=="sticky-balanced")return;let X=Z.stickyAssignments?.[C($)];if(!X||X.lastSeenAt<J-GZ)return;if(X.accountId==="main")return Z.main?.killed||m(Z.main?.quota,J)?void 0:"main";let V=jZ(Z).find((Y)=>Y.id===X.accountId);if(!V||V.enabled===!1||V.killed===!0||m(V.quota,J))return;return V.id}function t3(Z,$,J=Date.now()){if(!$)return{activeId:Z.activeId??"main",route:Z.route};let X=$?Z.activeRouting?.[$]:void 0,V=jZ(Z),Y=X?.activeId==="main"?Z.main.quota:V.find((D)=>D.id===X?.activeId)?.quota;if(X&&dZ(X,V,J)&&!m(Y,J))return{activeId:X.activeId,route:X.route};let G=r1(Z,$,J);if(G)return{activeId:G,route:Z.route};let z=Z.vaultAccounts!==void 0,j=(z?Z.vaultAccounts??[]:Z.fallbacks).filter((D)=>D.enabled&&!D.killed),B=j.find((D)=>!m(D.quota,J))??j[0];return{activeId:(z||Z.route==="fallback-first")&&B?B.id:"main",route:Z.route}}function cZ(Z,$,J=Date.now(),X){if(!Z)return;let V=Object.entries(Z).filter(([G,z])=>G!==X&&dZ(z,$,J)),Y=V.length<=SZ?V:V.sort((G,z)=>z[1].updatedAt-G[1].updatedAt).slice(0,SZ);return Y.length>0?Object.fromEntries(Y):void 0}function k(Z,$,J=Date.now(),X){if(!Z)return;let V=0,Y=0,G=0,z=[];for(let[B,D]of Object.entries(Z)){if(B===X){G+=1;continue}if(D.lastSeenAt<J-GZ){Y+=1;continue}if($!==void 0&&!$.has(D.accountId)){V+=1;continue}z.push([B,D])}let j=V+Y+G;if(j>0)f.debug("pruned sticky assignments",{pid:process.pid,removed:j,reasons:{"account-not-in-roster":V,expired:Y,"explicit-removal":G}});return z.length>0?Object.fromEntries(z):void 0}function uZ(Z,$){let J=Object.keys(Z).length-pZ;if(J<=0)return Z;let X=new Set(Object.entries(Z).filter(([V])=>V!==$).sort(([V,Y],[G,z])=>Y.lastSeenAt-z.lastSeenAt||V.localeCompare(G)).slice(0,J).map(([V])=>V));return Object.fromEntries(Object.entries(Z).filter(([V])=>!X.has(V)))}function lZ(Z,$){if(Z===$)return!0;if(!Z||!$)return!1;let J=Object.entries(Z);if(J.length!==Object.keys($).length)return!1;return J.every(([X,V])=>Object.is($[X],V))}function rZ(Z,$,J,X){return Z!==void 0&&$.has(Z.accountId)&&!J.has(Z.accountId)&&Z.lastSeenAt>=X-GZ}function oZ(Z,$,J,X){return $>Z.inputBytes||J-Z.lastSeenAt>=mZ||Z.wireAccountId===void 0&&X!==void 0}function aZ(Z,$){return typeof Z.wireAccountId==="string"&&typeof $==="string"&&Z.wireAccountId!==$}function o1(Z){let $=new Map(Z),J={get size(){return $.size},has:(X)=>$.has(X),get:(X)=>$.get(X),entries:()=>$.entries(),keys:()=>$.keys(),values:()=>$.values(),forEach:(X,V)=>{$.forEach((Y,G)=>{X.call(V,Y,G,J)})},[Symbol.iterator]:()=>$[Symbol.iterator]()};return Object.freeze(J)}function a1(Z,$,J){let X=new Map;for(let[V,Y]of Object.entries(Z??{})){if(V===J)continue;if(Y.quotaCheckedAt!==$[Y.accountId])continue;X.set(Y.accountId,(X.get(Y.accountId)??0)+Y.inputBytes)}return o1(X)}function UZ(Z){if(Z===void 0)return;return new Set(["main",...Z.filter(($)=>$.enabled!==!1&&$.killed!==!0).map(($)=>$.id)])}var YZ=Promise.resolve();function M(Z){let $=YZ.then(Z);return YZ=$.catch(()=>{}),$}var bZ=new Map;function BZ(Z){let $=bZ.get(Z);if(!$)$=e({path:Z,defaultValue:A,normalize:c,secureDir:Z===vZ(),logger:f}),bZ.set(Z,$);return $}var JZ=new Set;async function sZ(Z,$){try{await $}catch(J){let X={pid:process.pid,error:J instanceof Error?J.message:String(J)};if(JZ.has(Z))f.debug("sidebar write failed again",X);else JZ.add(Z),f.warn("sidebar write failed",X);throw J}if(JZ.delete(Z))f.info("sidebar write recovered",{pid:process.pid})}function e3(Z,$=_()){return M(()=>sZ($,BZ($).write(c(Z))))}function s1(Z){return BZ(Z).read()}function F(Z,$,J){let X=Symbol("sidebar authority changed");return sZ(Z,BZ(Z).update((V)=>{if(J?.canWrite&&!J.canWrite())return;let Y=$(V);return Y===void 0?void 0:c(Y)},{beforeRecheck:async(...V)=>{if(await J?.beforeRecheck?.(...V),J?.canWrite&&!J.canWrite())throw X}}).catch((V)=>{if(V!==X)throw V}))}function g(Z){let $;for(let J of[Z?.primary?.checkedAt,Z?.secondary?.checkedAt,Z?.checkedAt])if(typeof J==="number"&&Number.isFinite(J))$=$===void 0?J:Math.max($,J);return $}function fZ(Z,$){let J=g(Z),X=g($);if(X!==void 0&&(J===void 0||X>J))return $;return Z}function AZ(Z,$){return Z!==void 0&&$!==void 0&&Z===$}function d(Z,$){let J=Z?.checkedAt;if(typeof J==="number"&&Number.isFinite(J))return J;if(typeof $==="number"&&Number.isFinite($))return $;return}function kZ(Z,$,J,X,V){if(Z&&$){let Y=d(Z,X),G=d($,V);if(G!==void 0&&(Y===void 0||G>Y))return $;return Z}return J?$:Z}function wZ(Z,$){if(Z.spendControl!==void 0)return Z.spendControl;if(Z.spendControlCleared===!0)return;return $.spendControl}function yZ(Z,$){if(!Z)return $;if(!$)return Z;let J=g(Z),X=g($),V=X!==void 0&&(J===void 0||X>J),Y=kZ(Z.primary,$.primary,V,Z.checkedAt,$.checkedAt),G=kZ(Z.secondary,$.secondary,V,Z.checkedAt,$.checkedAt),z=V?wZ($,Z):wZ(Z,$),j=z===void 0&&(Z.spendControlCleared===!0||$.spendControlCleared===!0),B;for(let U of[d(Y),d(G)])if(U!==void 0)B=B===void 0?U:Math.max(B,U);let{spendControl:D,spendControlCleared:K,...Q}=Z;return{...Q,primary:Y,secondary:G,...z!==void 0?{spendControl:z}:{},...j?{spendControlCleared:!0}:{},checkedAt:B??Z.checkedAt}}function Z4(Z,$=_(),J){return M(async()=>{await F($,(X)=>{let V=new Map(X.fallbacks.map((B)=>[B.id,B])),Y=AZ(Z.main.mainAccountId,X.main.mainAccountId),G=Y?yZ(Z.main.quota,X.main.quota):fZ(Z.main.quota,X.main.quota),z=Date.now(),j=k(X.stickyAssignments,UZ(jZ(Z)),z);return{...X,...Z,main:{...Z.main,quota:G,mainAccountId:Y?Z.main.mainAccountId:G===X.main.quota&&G!==Z.main.quota?X.main.mainAccountId:Z.main.mainAccountId},fallbacks:Z.fallbacks.map((B)=>{let D=V.get(B.id),K=AZ(B.accountId,D?.accountId),Q=K?yZ(B.quota,D?.quota??null):fZ(B.quota,D?.quota??null);return{...B,quota:Q,accountId:K?B.accountId:Q===D?.quota&&Q!==B.quota?D?.accountId:B.accountId}}),activeId:X.activeId,activeRouting:X.activeRouting,stickyAssignments:j,lastUpdated:Math.max(z,X.lastUpdated+1),accountPool:Z.accountPool===!0?!0:void 0,vaultAccounts:Z.vaultAccounts}},J)})}function $4(Z,$,J=_(),X){return M(async()=>{await F(J,(V)=>{let Y=cZ({...V.activeRouting,[Z.sessionId]:{activeId:Z.activeId,route:Z.route,updatedAt:Z.updatedAt}},$,Date.now()),G=k(V.stickyAssignments,UZ($),Date.now());return{...V,activeId:Z.activeId,route:Z.route,activeRouting:Y,stickyAssignments:G,lastUpdated:Math.max(Date.now(),V.lastUpdated+1)}},X)})}function J4(Z,$=_(),J){return M(async()=>{await F($,(X)=>({...X,activeId:Z.activeId,route:Z.route,lastUpdated:Math.max(Date.now(),X.lastUpdated+1)}),J)})}function X4(Z,$,J=_(),X){return M(async()=>{await F(J,(V)=>{let Y=Date.now(),G=cZ(V.activeRouting,$,Y,Z),z=k(V.stickyAssignments,UZ($),Y,C(Z));return{...V,activeRouting:G,stickyAssignments:z,lastUpdated:Math.max(Date.now(),V.lastUpdated+1)}},X)})}function nZ(Z,$){return rZ(Z,new Set($.validPinnedAccountIds),new Set($.excludeAccountIds),$.now)&&!aZ(Z,$.wireAccountIdByAccount?.[Z.accountId])&&!oZ(Z,$.requestBytes,$.now,$.wireAccountIdByAccount?.[Z.accountId])}function iZ(Z,$){let J=C($.sessionId),X=new Set($.validPinnedAccountIds),V=new Set($.excludeAccountIds),Y=k(Z.stickyAssignments,X,$.now),G=!lZ(Z.stickyAssignments,Y),z=Y?.[J],j=z!==void 0&&aZ(z,$.wireAccountIdByAccount?.[z.accountId]);if(rZ(z,X,V,$.now)&&!j){let K=oZ(z,$.requestBytes,$.now,$.wireAccountIdByAccount?.[z.accountId]),Q=K?{...z,inputBytes:Math.max(z.inputBytes,$.requestBytes),...z.wireAccountId===void 0&&$.wireAccountIdByAccount?.[z.accountId]!==void 0?{wireAccountId:$.wireAccountIdByAccount?.[z.accountId]}:{},...$.now-z.lastSeenAt>=mZ?{lastSeenAt:$.now}:{}}:z;if(!G&&!K)return{assignment:Q,next:void 0};return{assignment:Q,next:{...Z,stickyAssignments:{...Y,[J]:Q},lastUpdated:Math.max($.now,Z.lastUpdated+1)}}}let B=$.choose(a1(Y,$.quotaCheckedAtByAccount,j?J:void 0));if(!B){if(!G)return{assignment:void 0,next:void 0};return{assignment:void 0,next:{...Z,stickyAssignments:Y,lastUpdated:Math.max($.now,Z.lastUpdated+1)}}}let D={accountId:B.accountId,assignedAt:$.now,lastSeenAt:$.now,inputBytes:$.requestBytes,...B.quotaCheckedAt===void 0?{}:{quotaCheckedAt:B.quotaCheckedAt},...$.wireAccountIdByAccount?.[B.accountId]===void 0?{}:{wireAccountId:$.wireAccountIdByAccount?.[B.accountId]}};return{assignment:D,next:{...Z,stickyAssignments:uZ({...Y,[J]:D},J),lastUpdated:Math.max($.now,Z.lastUpdated+1)}}}async function V4(Z,$=_(),J){let X=C(Z.sessionId),V=(await s1($)).stickyAssignments?.[X];if(nZ(V,Z))return V;let Y;return await M(async()=>{await F($,(G)=>{let z=iZ(G,Z);return Y=z.assignment,z.next},J)}),Y}function Y4(Z,$){let J=Z.stickyAssignments?.[C($.sessionId)];if(nZ(J,$))return{assignment:J,next:void 0};return iZ(Z,$)}function z4(Z,$=_()){let J=C(Z.sessionId),X=new Set(Z.validPinnedAccountIds);return M(async()=>{await F($,(V)=>{let Y=Date.now(),G=k(V.stickyAssignments,X,Y),z=G?.[J];if(z&&z.assignedAt>Z.assignment.assignedAt){if(lZ(V.stickyAssignments,G))return;return{...V,stickyAssignments:G,lastUpdated:Math.max(Y,V.lastUpdated+1)}}let B=z!==void 0&&z.accountId===Z.assignment.accountId&&z.assignedAt===Z.assignment.assignedAt?{...Z.assignment,inputBytes:Math.max(z.inputBytes,Z.assignment.inputBytes),lastSeenAt:Math.max(z.lastSeenAt,Z.assignment.lastSeenAt)}:Z.assignment;return{...V,stickyAssignments:uZ({...G,[J]:B},J),lastUpdated:Math.max(Y,V.lastUpdated+1)}})})}async function G4(Z,$=_()){let J=C(Z),X=!1;return await M(async()=>{await F($,(V)=>{let Y=V.stickyAssignments;if(Y?.[J]===void 0){X=!1;return}X=!0;let{[J]:G,...z}=Y;return{...V,...Object.keys(z).length>0?{stickyAssignments:z}:{stickyAssignments:void 0},lastUpdated:Math.max(Date.now(),V.lastUpdated+1)}})}),X}function j4(){return YZ}var n1=500;function i1(Z,$,J){return new Promise((X,V)=>{let Y=setTimeout(()=>X(J()),$);Y.unref?.(),Z.then((G)=>{clearTimeout(Y),X(G)},(G)=>{clearTimeout(Y),V(G)})})}function U4(Z,$={}){let J=$.readBudgetMs??n1,X,V,Y=()=>{try{let z=b1(Z);return`${z.ino}:${z.size}:${z.mtimeMs}`}catch{return}},G=(z)=>{if(V&&V.key===z)return V.promise;let j=Date.now(),B=d1(Z).then((Q)=>{if(!X||X.readAt<=j)X={state:Q,readAt:j,key:z};return{state:Q,readAt:j}}),D={key:z,promise:B};V=D;let K=()=>{if(V===D)V=void 0};return B.then(K,K),B};return{get(){let z=Y();if(X&&X.key===z)return Promise.resolve({state:X.state,readAt:X.readAt});return i1(G(z),J,()=>X?{state:X.state,readAt:X.readAt}:{state:A,readAt:0})},read(){return G(Y())},refreshInBackground(){let z=Y();if(X?.key===z)return;G(z)}}}function B4(Z,$,J){let X={assignment:J};Z.delete($),Z.set($,X);while(Z.size>pZ){let V=Z.keys().next().value;if(V===void 0)break;Z.delete(V)}return X}function Q4(Z,$){if($.size===0)return Z.state;let J={...Z.state.stickyAssignments},X=!1;for(let[V,Y]of $){if(Y.persistedAt!==void 0&&Z.readAt>Y.persistedAt){$.delete(V);continue}J[V]=Y.assignment,X=!0}if(!X)return Z.state;return{...Z.state,stickyAssignments:J}}function K4(Z){let $=Z.retryDelayMs??500,J=Z.maxRetryDelayMs??30000,X=new Map,V=new Map,Y=new Set,G=0,z=$,j,B=!1,D=()=>{if(j||B||V.size===0)return;j=setTimeout(()=>{j=void 0;let Q=[...V];V.clear(),z=Math.min(z*2,J);for(let[U,P]of Q){let W=X.get(U);if(W!==void 0)K(U,P.label,P.write,W)}},z),j.unref?.()},K=(Q,U,P,W)=>{let H;try{H=P()}catch(O){H=Promise.reject(O)}H.then(()=>{if(X.get(Q)!==W)return;if(X.delete(Q),Y.delete(Q))Z.logger.info("sidebar bookkeeping write recovered",{pid:process.pid,write:U});if(Y.size===0)z=$;Z.onWritten?.()},(O)=>{if(X.get(Q)!==W)return;let R={pid:process.pid,write:U,error:O instanceof Error?O.message:String(O)};if(B){X.delete(Q),Z.logger.debug("sidebar bookkeeping write dropped",R);return}if(Y.has(Q))Z.logger.debug("sidebar bookkeeping write failed again",R);else Y.add(Q),Z.logger.warn("sidebar bookkeeping write failed; retrying in the background",R);V.set(Q,{label:U,write:P}),D()})};return{enqueue(Q,U,P){G+=1,X.set(Q,G),V.delete(Q),K(Q,U,P,G)},cancel(Q){X.delete(Q),V.delete(Q),Y.delete(Q)},stop(){if(B=!0,j)clearTimeout(j);j=void 0,V.clear()}}}function D4(Z){let $=Z.activeId;if(Z.vaultAccounts!==void 0){let J=Z.vaultAccounts.filter((V)=>V.enabled),X=J.find((V)=>V.id===$)??J[0];return X?{id:X.id,name:X.label??X.id,quota:X.quota,killed:X.killed}:{id:"vault",name:"vault",quota:null,killed:!1}}if($&&$!=="main"){let J=Z.fallbacks.find((X)=>X.enabled&&X.id===$);if(J)return{id:J.id,name:J.label??J.id,quota:J.quota,killed:J.killed}}return{id:"main",name:"main",quota:Z.main.quota,killed:Z.main.killed}}function t1(Z,$=Date.now()){if(!Z)return;return s({limits:zZ.flatMap((J)=>{let X=Z[J];return X?[{kind:"reading",scope:"all",label:J,usedPercent:X.usedPercent,checkedAt:X.checkedAt??Z.checkedAt??$,windowMinutes:X.windowMinutes,resetsAt:X.resetsAt}]:[]}),...Z.spendControl?{budget:{...Z.spendControl,kind:"reading",checkedAt:Z.checkedAt??$}}:{}})}function P4(Z,$=Date.now()){let J=Z?.primary?.usedPercent??null,X=Z?.secondary?.usedPercent??null,V=t1(Z,$);return{primaryUsedPercent:J,secondaryUsedPercent:X,text:!V||V.limits.length===0&&!V.budget?null:a(V,{now:$,form:"compact"})}}var e1=300000,Z3=0.01,$3=1;function W4(Z,$,J){if(!Z.resetsAt)return null;let X=new Date(Z.resetsAt).getTime();if(!Number.isFinite(X))return null;let V=X-$,Y=J-V;if(Y<e1)return null;if(Y<$*Z3)return null;if(Y>=$)return null;let G=Z.usedPercent,z=Math.min(Math.max(Y/$*100,0),100),j=G-z,B=Math.abs(j)<$3?"on-pace":j>0?"deficit":"reserve",D=null;if(G>0){let K=Y*100/G,Q=V+K;if(Q<X)D=new Date(Q).toISOString()}return{pacePercent:z,deltaPercent:j,state:B,runsOutAt:D}}
2
+ export{L as La,tZ as Ma,I as Na,o as Oa,G1 as Pa,h as Qa,qZ as Ra,a as Sa,s as Ta,D1 as Ua,P1 as Va,W1 as Wa,E1 as Xa,c3 as Ya,i3 as Za,GZ as _a,pZ as $a,C as ab,_ as bb,A as cb,c as db,d1 as eb,c1 as fb,SZ as gb,dZ as hb,u1 as ib,l1 as jb,m as kb,r1 as lb,t3 as mb,cZ as nb,k as ob,e3 as pb,Z4 as qb,$4 as rb,J4 as sb,X4 as tb,iZ as ub,V4 as vb,Y4 as wb,z4 as xb,G4 as yb,j4 as zb,n1 as Ab,i1 as Bb,U4 as Cb,B4 as Db,Q4 as Eb,K4 as Fb,D4 as Gb,t1 as Hb,P4 as Ib,W4 as Jb};
@@ -1,2 +1,2 @@
1
- import{rb as Z,tb as W}from"./index-9ehhb051.js";var R=Z(($G,E)=>{var{defineProperty:N,getOwnPropertyDescriptor:Kz,getOwnPropertyNames:Qz}=Object,Wz=Object.prototype.hasOwnProperty,Xz=(z,G)=>{for(var H in G)N(z,H,{get:G[H],enumerable:!0})},Yz=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of Qz(G))if(!Wz.call(z,K)&&K!==H)N(z,K,{get:()=>G[K],enumerable:!(Q=Kz(G,K))||Q.enumerable})}return z},Zz=(z)=>Yz(N({},"__esModule",{value:!0}),z),O={};Xz(O,{VercelOidcTokenError:()=>S});E.exports=Zz(O);class S extends Error{constructor(z,G){super(z);this.name="VercelOidcTokenError",this.cause=G}toString(){if(this.cause)return`${this.name}: ${this.message}: ${this.cause}`;return`${this.name}: ${this.message}`}}});var P=Z((qG,y)=>{var{create:$z,defineProperty:L,getOwnPropertyDescriptor:qz,getOwnPropertyNames:vz,getPrototypeOf:Bz}=Object,Fz=Object.prototype.hasOwnProperty,Uz=(z,G)=>{for(var H in G)L(z,H,{get:G[H],enumerable:!0})},C=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of vz(G))if(!Fz.call(z,K)&&K!==H)L(z,K,{get:()=>G[K],enumerable:!(Q=qz(G,K))||Q.enumerable})}return z},I=(z,G,H)=>(H=z!=null?$z(Bz(z)):{},C(G||!z||!z.__esModule?L(H,"default",{value:z,enumerable:!0}):H,z)),Lz=(z)=>C(L({},"__esModule",{value:!0}),z),x={};Uz(x,{findRootDir:()=>Jz,getUserDataDir:()=>Nz});y.exports=Lz(x);var B=I(W("path")),bz=I(W("fs")),A=I(W("os")),Vz=R();function Jz(){try{let z=process.cwd();while(z!==B.default.dirname(z)){let G=B.default.join(z,".vercel");if(bz.default.existsSync(G))return z;z=B.default.dirname(z)}}catch(z){throw new Vz.VercelOidcTokenError("Token refresh only supported in node server environments")}return null}function Nz(){if(process.env.XDG_DATA_HOME)return process.env.XDG_DATA_HOME;switch(A.default.platform()){case"darwin":return B.default.join(A.default.homedir(),"Library/Application Support");case"linux":return B.default.join(A.default.homedir(),".local/share");case"win32":if(process.env.LOCALAPPDATA)return process.env.LOCALAPPDATA;return null;default:return null}}});var i=Z((vG,c)=>{var{create:Rz,defineProperty:b,getOwnPropertyDescriptor:Az,getOwnPropertyNames:Iz,getPrototypeOf:Dz}=Object,wz=Object.prototype.hasOwnProperty,Tz=(z,G)=>{for(var H in G)b(z,H,{get:G[H],enumerable:!0})},u=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of Iz(G))if(!wz.call(z,K)&&K!==H)b(z,K,{get:()=>G[K],enumerable:!(Q=Az(G,K))||Q.enumerable})}return z},l=(z,G,H)=>(H=z!=null?Rz(Dz(z)):{},u(G||!z||!z.__esModule?b(H,"default",{value:z,enumerable:!0}):H,z)),jz=(z)=>u(b({},"__esModule",{value:!0}),z),g={};Tz(g,{isValidAccessToken:()=>Ez,readAuthConfig:()=>Oz,writeAuthConfig:()=>Sz});c.exports=jz(g);var F=l(W("fs")),h=l(W("path")),Mz=f();function k(){let z=(0,Mz.getVercelDataDir)();if(!z)throw Error(`Unable to find Vercel CLI data directory. Your platform: ${process.platform}. Supported: darwin, linux, win32.`);return h.join(z,"auth.json")}function Oz(){try{let z=k();if(!F.existsSync(z))return null;let G=F.readFileSync(z,"utf8");if(!G)return null;return JSON.parse(G)}catch(z){return null}}function Sz(z){let G=k(),H=h.dirname(G);if(!F.existsSync(H))F.mkdirSync(H,{mode:504,recursive:!0});F.writeFileSync(G,JSON.stringify(z,null,2),{mode:384})}function Ez(z,G=0){if(!z.token)return!1;if(typeof z.expiresAt!=="number")return!0;let H=Math.floor(Date.now()/1000),Q=G/1000;return z.expiresAt>=H+Q}});var a=Z((BG,s)=>{var{defineProperty:T,getOwnPropertyDescriptor:Cz,getOwnPropertyNames:xz}=Object,yz=Object.prototype.hasOwnProperty,Pz=(z,G)=>{for(var H in G)T(z,H,{get:G[H],enumerable:!0})},uz=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of xz(G))if(!yz.call(z,K)&&K!==H)T(z,K,{get:()=>G[K],enumerable:!(Q=Cz(G,K))||Q.enumerable})}return z},lz=(z)=>uz(T({},"__esModule",{value:!0}),z),d={};Pz(d,{processTokenResponse:()=>iz,refreshTokenRequest:()=>cz});s.exports=lz(d);var D=W("os"),gz="https://vercel.com",hz="cl_HYyOPBNtFMfHhaUn9L4QPfTZz6TP47bp",p=`@vercel/oidc node-${process.version} ${(0,D.platform)()} (${(0,D.arch)()}) ${(0,D.hostname)()}`,w=null;async function kz(){if(w)return w;let z=`${gz}/.well-known/openid-configuration`,G=await fetch(z,{headers:{"user-agent":p}});if(!G.ok)throw Error("Failed to discover OAuth endpoints");let H=await G.json();if(!H||typeof H.token_endpoint!=="string")throw Error("Invalid OAuth discovery response");let Q=H.token_endpoint;return w=Q,Q}async function cz(z){let G=await kz();return await fetch(G,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","user-agent":p},body:new URLSearchParams({client_id:hz,grant_type:"refresh_token",...z})})}async function iz(z){let G=await z.json();if(!z.ok){let H=typeof G==="object"&&G&&"error"in G?String(G.error):"Token refresh failed";return[Error(H)]}if(typeof G!=="object"||G===null)return[Error("Invalid token response")];if(typeof G.access_token!=="string")return[Error("Missing access_token in response")];if(G.token_type!=="Bearer")return[Error("Invalid token_type in response")];if(typeof G.expires_in!=="number")return[Error("Missing expires_in in response")];return[null,G]}});var t=Z((FG,r)=>{var{defineProperty:j,getOwnPropertyDescriptor:fz,getOwnPropertyNames:dz}=Object,pz=Object.prototype.hasOwnProperty,sz=(z,G)=>{for(var H in G)j(z,H,{get:G[H],enumerable:!0})},az=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of dz(G))if(!pz.call(z,K)&&K!==H)j(z,K,{get:()=>G[K],enumerable:!(Q=fz(G,K))||Q.enumerable})}return z},_z=(z)=>az(j({},"__esModule",{value:!0}),z),_={};sz(_,{AccessTokenMissingError:()=>m,RefreshAccessTokenFailedError:()=>n});r.exports=_z(_);class m extends Error{constructor(){super("No authentication found. Please log in with the Vercel CLI (vercel login).");this.name="AccessTokenMissingError"}}class n extends Error{constructor(z){super("Failed to refresh authentication token.",{cause:z});this.name="RefreshAccessTokenFailedError"}}});var f=Z((UG,Hz)=>{var{create:mz,defineProperty:V,getOwnPropertyDescriptor:nz,getOwnPropertyNames:rz,getPrototypeOf:tz}=Object,ez=Object.prototype.hasOwnProperty,oz=(z,G)=>{for(var H in G)V(z,H,{get:G[H],enumerable:!0})},o=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of rz(G))if(!ez.call(z,K)&&K!==H)V(z,K,{get:()=>G[K],enumerable:!(Q=nz(G,K))||Q.enumerable})}return z},zz=(z,G,H)=>(H=z!=null?mz(tz(z)):{},o(G||!z||!z.__esModule?V(H,"default",{value:z,enumerable:!0}):H,z)),zG=(z)=>o(V({},"__esModule",{value:!0}),z),Gz={};oz(Gz,{assertVercelOidcTokenResponse:()=>M,findProjectInfo:()=>QG,getTokenPayload:()=>YG,getVercelDataDir:()=>GG,getVercelOidcToken:()=>KG,getVercelToken:()=>HG,isExpired:()=>ZG,loadToken:()=>XG,saveToken:()=>WG});Hz.exports=zG(Gz);var U=zz(W("path")),X=zz(W("fs")),v=R(),J=P(),$=i(),e=a(),q=t();function GG(){let G=(0,J.getUserDataDir)();if(!G)return null;return U.join(G,"com.vercel.cli")}async function HG(z){let G=(0,$.readAuthConfig)();if(!G?.token)throw new q.AccessTokenMissingError;if((0,$.isValidAccessToken)(G,z?.expirationBufferMs))return G.token;if(!G.refreshToken)throw(0,$.writeAuthConfig)({}),new q.RefreshAccessTokenFailedError("No refresh token available");try{let H=await(0,e.refreshTokenRequest)({refresh_token:G.refreshToken}),[Q,K]=await(0,e.processTokenResponse)(H);if(Q||!K)throw(0,$.writeAuthConfig)({}),new q.RefreshAccessTokenFailedError(Q);let Y={token:K.access_token,expiresAt:Math.floor(Date.now()/1000)+K.expires_in};if(K.refresh_token)Y.refreshToken=K.refresh_token;return(0,$.writeAuthConfig)(Y),Y.token}catch(H){if((0,$.writeAuthConfig)({}),H instanceof q.AccessTokenMissingError||H instanceof q.RefreshAccessTokenFailedError)throw H;throw new q.RefreshAccessTokenFailedError(H)}}async function KG(z,G,H){let Q=`https://api.vercel.com/v1/projects/${G}/token?source=vercel-oidc-refresh${H?`&teamId=${H}`:""}`,K=await fetch(Q,{method:"POST",headers:{Authorization:`Bearer ${z}`}});if(!K.ok)throw new v.VercelOidcTokenError(`Failed to refresh OIDC token: ${K.statusText}`);let Y=await K.json();return M(Y),Y}function M(z){if(!z||typeof z!=="object")throw TypeError("Vercel OIDC token is malformed. Expected an object. Please run `vc env pull` and try again");if(!("token"in z)||typeof z.token!=="string")throw TypeError("Vercel OIDC token is malformed. Expected a string-valued token property. Please run `vc env pull` and try again")}function QG(){let z=(0,J.findRootDir)();if(!z)throw new v.VercelOidcTokenError("Unable to find project root directory. Have you linked your project with `vc link?`");let G=U.join(z,".vercel","project.json");if(!X.existsSync(G))throw new v.VercelOidcTokenError("project.json not found, have you linked your project with `vc link?`");let H=JSON.parse(X.readFileSync(G,"utf8"));if(typeof H.projectId!=="string"&&typeof H.orgId!=="string")throw TypeError("Expected a string-valued projectId property. Try running `vc link` to re-link your project.");return{projectId:H.projectId,teamId:H.orgId}}function WG(z,G){let H=(0,J.getUserDataDir)();if(!H)throw new v.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");let Q=U.join(H,"com.vercel.token",`${G}.json`),K=JSON.stringify(z);X.mkdirSync(U.dirname(Q),{mode:504,recursive:!0}),X.writeFileSync(Q,K),X.chmodSync(Q,432);return}function XG(z){let G=(0,J.getUserDataDir)();if(!G)throw new v.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");let H=U.join(G,"com.vercel.token",`${z}.json`);if(!X.existsSync(H))return null;let Q=JSON.parse(X.readFileSync(H,"utf8"));return M(Q),Q}function YG(z){let G=z.split(".");if(G.length!==3)throw new v.VercelOidcTokenError("Invalid token. Please run `vc env pull` and try again");let H=G[1].replace(/-/g,"+").replace(/_/g,"/"),Q=H.padEnd(H.length+(4-H.length%4)%4,"=");return JSON.parse(Buffer.from(Q,"base64").toString("utf8"))}function ZG(z,G=0){return z.exp*1000<Date.now()+G}});
1
+ import{tc as Z,vc as W}from"./index-b3q3j39x.js";var R=Z(($G,E)=>{var{defineProperty:N,getOwnPropertyDescriptor:Kz,getOwnPropertyNames:Qz}=Object,Wz=Object.prototype.hasOwnProperty,Xz=(z,G)=>{for(var H in G)N(z,H,{get:G[H],enumerable:!0})},Yz=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of Qz(G))if(!Wz.call(z,K)&&K!==H)N(z,K,{get:()=>G[K],enumerable:!(Q=Kz(G,K))||Q.enumerable})}return z},Zz=(z)=>Yz(N({},"__esModule",{value:!0}),z),O={};Xz(O,{VercelOidcTokenError:()=>S});E.exports=Zz(O);class S extends Error{constructor(z,G){super(z);this.name="VercelOidcTokenError",this.cause=G}toString(){if(this.cause)return`${this.name}: ${this.message}: ${this.cause}`;return`${this.name}: ${this.message}`}}});var P=Z((qG,y)=>{var{create:$z,defineProperty:L,getOwnPropertyDescriptor:qz,getOwnPropertyNames:vz,getPrototypeOf:Bz}=Object,Fz=Object.prototype.hasOwnProperty,Uz=(z,G)=>{for(var H in G)L(z,H,{get:G[H],enumerable:!0})},C=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of vz(G))if(!Fz.call(z,K)&&K!==H)L(z,K,{get:()=>G[K],enumerable:!(Q=qz(G,K))||Q.enumerable})}return z},I=(z,G,H)=>(H=z!=null?$z(Bz(z)):{},C(G||!z||!z.__esModule?L(H,"default",{value:z,enumerable:!0}):H,z)),Lz=(z)=>C(L({},"__esModule",{value:!0}),z),x={};Uz(x,{findRootDir:()=>Jz,getUserDataDir:()=>Nz});y.exports=Lz(x);var B=I(W("path")),bz=I(W("fs")),A=I(W("os")),Vz=R();function Jz(){try{let z=process.cwd();while(z!==B.default.dirname(z)){let G=B.default.join(z,".vercel");if(bz.default.existsSync(G))return z;z=B.default.dirname(z)}}catch(z){throw new Vz.VercelOidcTokenError("Token refresh only supported in node server environments")}return null}function Nz(){if(process.env.XDG_DATA_HOME)return process.env.XDG_DATA_HOME;switch(A.default.platform()){case"darwin":return B.default.join(A.default.homedir(),"Library/Application Support");case"linux":return B.default.join(A.default.homedir(),".local/share");case"win32":if(process.env.LOCALAPPDATA)return process.env.LOCALAPPDATA;return null;default:return null}}});var i=Z((vG,c)=>{var{create:Rz,defineProperty:b,getOwnPropertyDescriptor:Az,getOwnPropertyNames:Iz,getPrototypeOf:Dz}=Object,wz=Object.prototype.hasOwnProperty,Tz=(z,G)=>{for(var H in G)b(z,H,{get:G[H],enumerable:!0})},u=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of Iz(G))if(!wz.call(z,K)&&K!==H)b(z,K,{get:()=>G[K],enumerable:!(Q=Az(G,K))||Q.enumerable})}return z},l=(z,G,H)=>(H=z!=null?Rz(Dz(z)):{},u(G||!z||!z.__esModule?b(H,"default",{value:z,enumerable:!0}):H,z)),jz=(z)=>u(b({},"__esModule",{value:!0}),z),g={};Tz(g,{isValidAccessToken:()=>Ez,readAuthConfig:()=>Oz,writeAuthConfig:()=>Sz});c.exports=jz(g);var F=l(W("fs")),h=l(W("path")),Mz=f();function k(){let z=(0,Mz.getVercelDataDir)();if(!z)throw Error(`Unable to find Vercel CLI data directory. Your platform: ${process.platform}. Supported: darwin, linux, win32.`);return h.join(z,"auth.json")}function Oz(){try{let z=k();if(!F.existsSync(z))return null;let G=F.readFileSync(z,"utf8");if(!G)return null;return JSON.parse(G)}catch(z){return null}}function Sz(z){let G=k(),H=h.dirname(G);if(!F.existsSync(H))F.mkdirSync(H,{mode:504,recursive:!0});F.writeFileSync(G,JSON.stringify(z,null,2),{mode:384})}function Ez(z,G=0){if(!z.token)return!1;if(typeof z.expiresAt!=="number")return!0;let H=Math.floor(Date.now()/1000),Q=G/1000;return z.expiresAt>=H+Q}});var a=Z((BG,s)=>{var{defineProperty:T,getOwnPropertyDescriptor:Cz,getOwnPropertyNames:xz}=Object,yz=Object.prototype.hasOwnProperty,Pz=(z,G)=>{for(var H in G)T(z,H,{get:G[H],enumerable:!0})},uz=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of xz(G))if(!yz.call(z,K)&&K!==H)T(z,K,{get:()=>G[K],enumerable:!(Q=Cz(G,K))||Q.enumerable})}return z},lz=(z)=>uz(T({},"__esModule",{value:!0}),z),d={};Pz(d,{processTokenResponse:()=>iz,refreshTokenRequest:()=>cz});s.exports=lz(d);var D=W("os"),gz="https://vercel.com",hz="cl_HYyOPBNtFMfHhaUn9L4QPfTZz6TP47bp",p=`@vercel/oidc node-${process.version} ${(0,D.platform)()} (${(0,D.arch)()}) ${(0,D.hostname)()}`,w=null;async function kz(){if(w)return w;let z=`${gz}/.well-known/openid-configuration`,G=await fetch(z,{headers:{"user-agent":p}});if(!G.ok)throw Error("Failed to discover OAuth endpoints");let H=await G.json();if(!H||typeof H.token_endpoint!=="string")throw Error("Invalid OAuth discovery response");let Q=H.token_endpoint;return w=Q,Q}async function cz(z){let G=await kz();return await fetch(G,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","user-agent":p},body:new URLSearchParams({client_id:hz,grant_type:"refresh_token",...z})})}async function iz(z){let G=await z.json();if(!z.ok){let H=typeof G==="object"&&G&&"error"in G?String(G.error):"Token refresh failed";return[Error(H)]}if(typeof G!=="object"||G===null)return[Error("Invalid token response")];if(typeof G.access_token!=="string")return[Error("Missing access_token in response")];if(G.token_type!=="Bearer")return[Error("Invalid token_type in response")];if(typeof G.expires_in!=="number")return[Error("Missing expires_in in response")];return[null,G]}});var t=Z((FG,r)=>{var{defineProperty:j,getOwnPropertyDescriptor:fz,getOwnPropertyNames:dz}=Object,pz=Object.prototype.hasOwnProperty,sz=(z,G)=>{for(var H in G)j(z,H,{get:G[H],enumerable:!0})},az=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of dz(G))if(!pz.call(z,K)&&K!==H)j(z,K,{get:()=>G[K],enumerable:!(Q=fz(G,K))||Q.enumerable})}return z},_z=(z)=>az(j({},"__esModule",{value:!0}),z),_={};sz(_,{AccessTokenMissingError:()=>m,RefreshAccessTokenFailedError:()=>n});r.exports=_z(_);class m extends Error{constructor(){super("No authentication found. Please log in with the Vercel CLI (vercel login).");this.name="AccessTokenMissingError"}}class n extends Error{constructor(z){super("Failed to refresh authentication token.",{cause:z});this.name="RefreshAccessTokenFailedError"}}});var f=Z((UG,Hz)=>{var{create:mz,defineProperty:V,getOwnPropertyDescriptor:nz,getOwnPropertyNames:rz,getPrototypeOf:tz}=Object,ez=Object.prototype.hasOwnProperty,oz=(z,G)=>{for(var H in G)V(z,H,{get:G[H],enumerable:!0})},o=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of rz(G))if(!ez.call(z,K)&&K!==H)V(z,K,{get:()=>G[K],enumerable:!(Q=nz(G,K))||Q.enumerable})}return z},zz=(z,G,H)=>(H=z!=null?mz(tz(z)):{},o(G||!z||!z.__esModule?V(H,"default",{value:z,enumerable:!0}):H,z)),zG=(z)=>o(V({},"__esModule",{value:!0}),z),Gz={};oz(Gz,{assertVercelOidcTokenResponse:()=>M,findProjectInfo:()=>QG,getTokenPayload:()=>YG,getVercelDataDir:()=>GG,getVercelOidcToken:()=>KG,getVercelToken:()=>HG,isExpired:()=>ZG,loadToken:()=>XG,saveToken:()=>WG});Hz.exports=zG(Gz);var U=zz(W("path")),X=zz(W("fs")),v=R(),J=P(),$=i(),e=a(),q=t();function GG(){let G=(0,J.getUserDataDir)();if(!G)return null;return U.join(G,"com.vercel.cli")}async function HG(z){let G=(0,$.readAuthConfig)();if(!G?.token)throw new q.AccessTokenMissingError;if((0,$.isValidAccessToken)(G,z?.expirationBufferMs))return G.token;if(!G.refreshToken)throw(0,$.writeAuthConfig)({}),new q.RefreshAccessTokenFailedError("No refresh token available");try{let H=await(0,e.refreshTokenRequest)({refresh_token:G.refreshToken}),[Q,K]=await(0,e.processTokenResponse)(H);if(Q||!K)throw(0,$.writeAuthConfig)({}),new q.RefreshAccessTokenFailedError(Q);let Y={token:K.access_token,expiresAt:Math.floor(Date.now()/1000)+K.expires_in};if(K.refresh_token)Y.refreshToken=K.refresh_token;return(0,$.writeAuthConfig)(Y),Y.token}catch(H){if((0,$.writeAuthConfig)({}),H instanceof q.AccessTokenMissingError||H instanceof q.RefreshAccessTokenFailedError)throw H;throw new q.RefreshAccessTokenFailedError(H)}}async function KG(z,G,H){let Q=`https://api.vercel.com/v1/projects/${G}/token?source=vercel-oidc-refresh${H?`&teamId=${H}`:""}`,K=await fetch(Q,{method:"POST",headers:{Authorization:`Bearer ${z}`}});if(!K.ok)throw new v.VercelOidcTokenError(`Failed to refresh OIDC token: ${K.statusText}`);let Y=await K.json();return M(Y),Y}function M(z){if(!z||typeof z!=="object")throw TypeError("Vercel OIDC token is malformed. Expected an object. Please run `vc env pull` and try again");if(!("token"in z)||typeof z.token!=="string")throw TypeError("Vercel OIDC token is malformed. Expected a string-valued token property. Please run `vc env pull` and try again")}function QG(){let z=(0,J.findRootDir)();if(!z)throw new v.VercelOidcTokenError("Unable to find project root directory. Have you linked your project with `vc link?`");let G=U.join(z,".vercel","project.json");if(!X.existsSync(G))throw new v.VercelOidcTokenError("project.json not found, have you linked your project with `vc link?`");let H=JSON.parse(X.readFileSync(G,"utf8"));if(typeof H.projectId!=="string"&&typeof H.orgId!=="string")throw TypeError("Expected a string-valued projectId property. Try running `vc link` to re-link your project.");return{projectId:H.projectId,teamId:H.orgId}}function WG(z,G){let H=(0,J.getUserDataDir)();if(!H)throw new v.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");let Q=U.join(H,"com.vercel.token",`${G}.json`),K=JSON.stringify(z);X.mkdirSync(U.dirname(Q),{mode:504,recursive:!0}),X.writeFileSync(Q,K),X.chmodSync(Q,432);return}function XG(z){let G=(0,J.getUserDataDir)();if(!G)throw new v.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");let H=U.join(G,"com.vercel.token",`${z}.json`);if(!X.existsSync(H))return null;let Q=JSON.parse(X.readFileSync(H,"utf8"));return M(Q),Q}function YG(z){let G=z.split(".");if(G.length!==3)throw new v.VercelOidcTokenError("Invalid token. Please run `vc env pull` and try again");let H=G[1].replace(/-/g,"+").replace(/_/g,"/"),Q=H.padEnd(H.length+(4-H.length%4)%4,"=");return JSON.parse(Buffer.from(Q,"base64").toString("utf8"))}function ZG(z,G=0){return z.exp*1000<Date.now()+G}});
2
2
  export{R as a,f as b};
@@ -0,0 +1,7 @@
1
+ import{randomUUID as O}from"node:crypto";import{mkdir as a,open as x0,readFile as L,rename as i,rm as f,stat as s,writeFile as M}from"node:fs/promises";import{dirname as $0,join as t}from"node:path";function d(x,K){return`${x}.${K}.lock`}class p extends Error{details;constructor(x){super(`Timed out acquiring ${x.name} lock for ${x.target}`);this.name="LockContentionError",this.details=x}}class R extends Error{details;constructor(x){super(`Lost ${x.name} lock for ${x.target}`);this.name="LockOwnershipError",this.details=x}}async function Q0(x,K,H){let B=performance.now();for(;;){let W=await l({path:x,name:K.name,ttlMs:K.ttlMs,renew:K.renew??!1});if(W)try{return await H(W)}finally{await W.release()}let j=K.timeoutMs-(performance.now()-B);if(j<=0)throw new p({target:x,name:K.name,timeoutMs:K.timeoutMs});await new Promise((C)=>setTimeout(C,Math.min(25,Math.ceil(j))))}}var z0=globalThis.setTimeout.bind(globalThis),K0=globalThis.clearTimeout.bind(globalThis);function N0(x){let K=x?.code;return K==="ENOENT"||K==="EINVAL"||K==="ENOTDIR"}async function l(x){let K=d(x.path,x.name),H=t(K,"owner.json"),B=O(),W=x.now??Date.now,j=null,C=!1,G,X,n=new Promise(($)=>{X=$});function T($){try{let z=x.onRenewalTimer?.($);if(z&&(typeof z==="object"||typeof z==="function")&&"then"in z&&typeof z.then==="function")Promise.resolve(z).catch(()=>{})}catch{}}function I(){if(!j)return;K0(j),j=null,T("cancelled")}function Z($,z){if(G||C)return;G=Object.freeze({reason:$,expectedOwnerId:B,...typeof z?.ownerId==="string"?{observedOwnerId:z.ownerId}:{},...typeof z?.expiresAt==="number"?{observedExpiresAt:z.expiresAt}:{}}),I(),X(G)}let g=null,V=`${K}.evicting`,E=t(V,"owner.json"),P=O(),r=5000,U=8;async function _(){try{return JSON.parse(await L(K,"utf8"))}catch($){if($.code!=="EISDIR")throw $;return JSON.parse(await L(H,"utf8"))}}async function e(){let $=`${K}.${O()}.tmp`,z,N=!1;try{z=await x0($,"wx",384),N=!0,await z.writeFile(`${JSON.stringify({ownerId:B,expiresAt:W()+x.ttlMs})}
2
+ `,"utf8"),await z.chmod(384),await z.close(),z=void 0,await i($,K),N=!1}finally{if(await z?.close().catch(()=>{}),N)await f($,{force:!0}).catch(()=>{})}}async function q(){try{return await M(K,`${JSON.stringify({ownerId:B,expiresAt:W()+x.ttlMs})}
3
+ `,{encoding:"utf8",mode:384,flag:"wx"}),!0}catch($){let z=$.code;if(z==="EEXIST"||z==="EISDIR")return!1;if(z==="ENOENT"){await a($0(K),{recursive:!0});try{return await M(K,`${JSON.stringify({ownerId:B,expiresAt:W()+x.ttlMs})}
4
+ `,{encoding:"utf8",mode:384,flag:"wx"}),!0}catch(N){let Y=N.code;if(Y==="EEXIST"||Y==="EISDIR")return!1;throw N}}throw $}}async function D(){await new Promise(($)=>setTimeout($,Math.floor(Math.random()*4)))}async function m(){try{let $=await _();return Number($?.expiresAt)>W()}catch{try{return(await s(K)).mtimeMs+x.ttlMs>W()}catch{return!1}}}async function Q(){try{return JSON.parse(await L(E,"utf8"))?.ownerId===P}catch{return!1}}async function S(){if(await Q())await f(V,{recursive:!0,force:!0}).catch(()=>{})}async function u(){await a(V);try{await M(E,`${JSON.stringify({ownerId:P,createdAt:W()})}
5
+ `,{encoding:"utf8",mode:384,flag:"wx"})}catch($){if(N0($))return!1;throw await S(),$}if(x.onStep)await x.onStep("eviction-marker-acquired");return!0}async function k(){let $;try{$=await s(V)}catch(N){if(N.code==="ENOENT")return"missing";throw N}if($.mtimeMs+r>W())return"fresh";if(x.onStep)await x.onStep("stale-marker-stat");let z=`${V}.${O()}`;try{await i(V,z)}catch(N){if(N.code==="ENOENT")return"missing";throw N}if(x.onStep)await x.onStep("stale-marker-claimed");return await f(z,{recursive:!0,force:!0}).catch(()=>{}),"recovered"}async function v($){try{if(!await u())return!1}catch(z){if(z.code==="EEXIST")return!1;throw z}try{await $()}finally{await S()}return!0}async function h(){for(let $=0;$<U;$++){if(x.onStep)await x.onStep("relinquish-read");let z;try{z=await _()}catch{return}if(z?.ownerId!==B)return;try{await f(K,{recursive:!0,force:!0});return}catch{await D()}}}function w(){if(!x.renew||C||G)return;let $=x.renewIntervalMs??Math.max(1000,Math.floor(x.ttlMs/3));if(j=z0(()=>{j=null;let z=(async()=>{let N=!C;try{if(!await v(async()=>{let b=await _(),o=W();if(C||G){N=!1;return}if(b?.ownerId!==B){Z("taken-over",b),N=!1;return}if(!(Number(b?.expiresAt)>o)){Z("expired",b),N=!1;return}if(x.onStep)await x.onStep("renewal-owner-confirmed");if(C||G){N=!1;return}if(!await Q())return;if(x.onStep)await x.onStep("renewal-write-fenced");if(C||G){N=!1;return}if(!await Q())return;if(x.onStep)await x.onStep("renewal-write-ready");if(C||G){N=!1;return}if(await e(),!await Q()){Z("marker-lost"),N=!1,await h();return}})&&x.onStep)await x.onStep("renewal-marker-unavailable")}catch{try{let Y=await _();if(Y?.ownerId!==B)Z("taken-over",Y);else if(!(Number(Y?.expiresAt)>W()))Z("expired",Y)}catch{Z("renewal-failed")}}finally{if(x.onStep)try{await x.onStep("renewal-finished")}catch{}if(N&&!C&&!G)w()}})();g=z,z.finally(()=>{if(g===z)g=null})},$),"unref"in j)j.unref();T("scheduled")}function c(){try{let $=x.onContended?.();if($&&(typeof $==="object"||typeof $==="function")&&"then"in $&&typeof $.then==="function")Promise.resolve($).catch(()=>{})}catch{}return null}let J=await q();if(!J)for(let $=0;$<U;$++){if(J=await q(),J)break;if(await m())return c();if(x.onStep)await x.onStep("stale-lock-observed");try{if(!await u()){await D();continue}}catch(z){if(z.code!=="EEXIST")throw z;if(await k()==="fresh")return null;await D();continue}try{if(await m())return c();if(!await Q())return null;if(x.onStep)await x.onStep("stale-lock-confirmed");if(!await Q())return null;if(await f(K,{recursive:!0,force:!0}).catch(()=>{}),!await Q())return null;if(x.onStep)await x.onStep("stale-lock-removed");if(J=await q(),!J)return null;if(x.onStep)await x.onStep("stale-lock-recreated");if(!await Q())return await h(),J=!1,null;break}finally{await S()}}if(!J)return null;return w(),{ownerId:B,whenLost:()=>n,hasLost:()=>G!==void 0,assertOwned:async()=>{let $;try{let z=await _();if($=z,!C&&!G&&z?.ownerId===B&&Number(z?.expiresAt)>W())return;Z(z?.ownerId!==B?"taken-over":"expired",z)}catch{Z("unreadable")}throw new R({target:x.path,name:x.name,expectedOwnerId:B,...typeof $?.ownerId==="string"?{observedOwnerId:$.ownerId}:{},...typeof $?.expiresAt==="number"?{observedExpiresAt:$.expiresAt}:{}})},release:async()=>{C=!0,I(),await g;for(let $=0;$<U;$++){try{if(await v(async()=>{if((await _())?.ownerId!==B)return;if(x.onStep)await x.onStep("release-owner-confirmed");if(!await Q())return;await f(K,{recursive:!0,force:!0}).catch(()=>{})}))return;await k()}catch{return}await D()}}}}import{randomUUID as W0}from"node:crypto";import{mkdir as j0,open as F,rename as B0,rm as C0}from"node:fs/promises";import{dirname as A}from"node:path";class y extends Error{constructor(x){super("file or directory sync failed",{cause:x});this.name="AtomicSyncError"}}async function b0(x,K,H={}){await G0(x,K,H)}async function G0(x,K,H,B){await j0(A(x),{recursive:!0});let W=`${x}.${(H.stageName??W0)()}.tmp`,j,C=!1;try{if(j=await F(W,"wx",384),C=!0,await j.writeFile(H.serialize?H.serialize(K):`${JSON.stringify(K,null,2)}
6
+ `,"utf8"),await j.chmod(384),H.durable)try{await j.sync()}catch(G){throw new y(G)}if(await j.close(),j=void 0,await H.beforeRename?.(),await B0(W,x),C=!1,B?.(),H.durable){let G=await F(A(x),"r");try{await G.sync()}catch(X){throw new y(X)}finally{await G.close()}}}finally{if(await j?.close().catch(()=>{}),C)await C0(W,{force:!0}).catch(()=>{})}}async function O0(x){let K=await F(x,"r");try{await K.sync()}finally{await K.close()}let H=await F(A(x),"r");try{await H.sync()}finally{await H.close()}}var U0=Object.freeze({sidebar:Object.freeze({name:"sidebar-write",ttlMs:1e4,timeoutMs:15000,renew:!0}),preferences:Object.freeze({name:"preferences",ttlMs:1e4,timeoutMs:2000,renew:!0})});
7
+ export{y as Kb,b0 as Lb,G0 as Mb,O0 as Nb,l as Ob,p as Pb,R as Qb,Q0 as Rb,U0 as Sb};
@@ -0,0 +1,2 @@
1
+ import{$b as h,Zb as D,_b as _}from"./index-8kj7sa1p.js";import{pc as R}from"./index-766sfrh5.js";class T extends Error{operation;constructor(f){super(`a ${f} on a strict notification scope needs a session id`);this.name="RpcSessionRequiredError",this.operation=f}}function F(f){return typeof f==="string"&&f.length>0}var S=new Map;function W(f){let x=JSON.stringify([f.rpcRoot,f.directoryPrefix,f.registrationSessionId,...f.requireSession===!0?["strict"]:[]]),z=S.get(x);if(!z)z={queue:[],nextId:1,lastDrainAtBySession:new Map,lastDrainAtAny:0},S.set(x,z);return z}var U=100,k=3000;function c(f,x,z){if(f.requireSession===!0&&!F(z))throw new T("push");let H=W(f);if(H.queue.push({id:H.nextId++,type:"open-dialog",payload:x,sessionId:z}),H.queue.length>U)H.queue=H.queue.slice(-U)}function d(f,x=0,z){if(f.requireSession===!0&&!F(z))throw new T("drain");let H=W(f),Y=Date.now();if(H.lastDrainAtAny=Y,z!==void 0)H.lastDrainAtBySession.set(z,Y);let Z=f.sessionlessDrain==="broadcast-only",V=(B)=>z===void 0?!Z||B.sessionId===void 0:B.sessionId===void 0||B.sessionId===z;if(x>0)H.queue=H.queue.filter((B)=>{if(B.id>x)return!0;if(z===void 0)return!Z||B.sessionId!==void 0;return B.sessionId!==z});return H.queue.filter((B)=>B.id>x&&V(B))}function i(f,x){let z=Date.now(),H=W(f),Y=x!==void 0?H.lastDrainAtBySession.get(x)??0:f.sessionlessDrain==="broadcast-only"?H.lastDrainAtAny:0;return Y>0&&z-Y<k}import{randomBytes as w,timingSafeEqual as j}from"node:crypto";import{readFile as t,unlink as q}from"node:fs/promises";import{createServer as v}from"node:http";import{join as u}from"node:path";class N extends Error{status;constructor(f,x){if(!Number.isInteger(f)||f<400||f>499)throw RangeError(`RpcRequestError status must be 4xx, got ${f}`);super(x);this.name="RpcRequestError",this.status=f}}var E=1e6;class g extends Error{declaredOversize;constructor(f){super("body too large");this.declaredOversize=f}}function I(f){return new Promise((x,z)=>{let H=(B=!1)=>{f.removeAllListeners("data"),f.on("data",()=>{}),f.resume(),z(new g(B))},Y=Number(f.headers["content-length"]);if(Number.isFinite(Y)&&Y>E){H(!0);return}let Z=[],V=0;f.on("data",(B)=>{if(V+=B.length,V>E){H();return}Z.push(B)}),f.on("end",()=>x(Buffer.concat(Z).toString("utf8"))),f.on("error",z)})}class m extends Error{}async function l(f,x){let z,H=new Promise((Y,Z)=>{z=setTimeout(()=>Z(new m("apply deadline exceeded")),x),z.unref?.()});f.catch(()=>{});try{return await Promise.race([f,H])}finally{clearTimeout(z)}}function p(f,x){if(!f?.startsWith("Bearer "))return!1;let z=Buffer.from(f.slice(7)),H=Buffer.from(x);return z.length===H.length&&j(z,H)}async function xf(f){if(typeof f.drain==="function"===(typeof f.drainAsync==="function"))throw TypeError("exactly one of drain or drainAsync must be provided");let x=f.log??{warn(){},debug(){}},z=w(32).toString("hex"),H=f.timeoutMs??90000,Y=f.receiptTimeoutMs??2000,Z=!1,V=new Set,B=v((G,K)=>{G.setTimeout(H,()=>{G.socket.destroy()}),M(G,K)});B.on("connection",(G)=>{V.add(G),G.once("close",()=>V.delete(G))}),B.requestTimeout=Y,B.headersTimeout=Y;async function M(G,K){let J=(X,Q,C={})=>{if(K.headersSent||K.writableEnded||K.destroyed)return;K.writeHead(X,{"content-type":"application/json",...C}),K.end(JSON.stringify(Q))};try{let X=new URL(G.url??"/","http://127.0.0.1").pathname;if(G.method==="GET"&&X==="/health")return J(200,{ok:!0});if(G.method!=="POST"||!X.startsWith("/rpc/"))return J(404,{error:"not found"});if(!p(G.headers.authorization,z))return J(401,{error:"unauthorized"});let Q=X.slice(5),C;try{C=await I(G)}catch($){if(!($ instanceof g))throw $;if($.declaredOversize){let y=G.socket;K.once("finish",()=>{y.end();let A=setTimeout(()=>y.destroy(),2000);if(A.unref(),G.once("end",()=>y.destroy()),y.once("close",()=>clearTimeout(A)),G.complete)y.destroy()})}return J(413,{error:"body too large"},{connection:"close"})}let b;try{b=JSON.parse(C||"{}")}catch{return J(400,{error:"invalid json"})}if(Q==="pending-notifications"){let $;try{if(f.parsePending)$=f.parsePending(b);else{if(!b||typeof b!=="object"||Array.isArray(b))throw Error("invalid params");let L=b;if(f.requireSession===!0&&!F(L.sessionId))return J(400,{error:"session required"});if("lastReceivedId"in L&&(typeof L.lastReceivedId!=="number"||!Number.isSafeInteger(L.lastReceivedId)||L.lastReceivedId<0)||"sessionId"in L&&typeof L.sessionId!=="string")throw Error("invalid params");$={lastReceivedId:Number(L.lastReceivedId??0),sessionId:typeof L.sessionId==="string"?L.sessionId:void 0}}}catch(L){if(L instanceof N)throw L;return J(400,{error:"invalid params"})}let{lastReceivedId:y,sessionId:A}=$;if(f.requireSession===!0&&!F(A))return J(400,{error:"session required"});if(A===void 0&&!Z)Z=!0,x.warn("rpc notification drain missing session id",{pid:process.pid});let O;if(f.drainAsync)try{O=await f.drainAsync(y,A)}catch(L){return x.warn("rpc notification drain failed",{pid:process.pid,error:L instanceof Error?L.message:String(L)}),J(500,{error:"drain failed"})}else O=f.drain?.(y,A);return J(200,{messages:O})}if(Q==="apply"){let $=Promise.resolve(f.apply(b)),y=f.applyDeadlineMs===void 0?await $:await l($,f.applyDeadlineMs);return J(200,y)}return J(404,{error:"unknown method"})}catch(X){if(X instanceof N)return x.debug("rpc request refused",{pid:process.pid,status:X.status}),J(X.status,{error:X.message});if(X instanceof m)return x.warn("rpc apply deadline exceeded",{pid:process.pid,deadlineMs:f.applyDeadlineMs}),J(504,{error:"handler deadline exceeded"});x.warn("rpc request failed",{pid:process.pid,error:X instanceof Error?X.message:String(X)}),J(500,{error:"internal error"})}}let P=await new Promise((G,K)=>{B.on("error",K),B.listen(0,"127.0.0.1",()=>{let J=B.address();if(J&&typeof J==="object")G(J.port);else K(Error("no port"))})});if(B.unref(),f.sweepRoot)try{await h(f.sweepRoot,f.dir,f.isManagedDir,x)}catch(G){x.warn("rpc state sweep failed",{pid:process.pid,error:G instanceof Error?G.message:String(G)})}try{await _(f.dir,{port:P,token:z,pid:process.pid},{secureDir:f.secureDir}),x.debug("rpc server pid",{pid:process.pid,rpcPort:P})}catch(G){throw await new Promise((K)=>B.close(()=>K())),G}return{port:P,token:z,async stop(){await new Promise((J)=>{B.closeAllConnections?.(),B.close(()=>J());for(let X of V)X.destroy()});let G=u(f.dir,`port-${process.pid}.json`),K=await t(G,"utf8").then((J)=>JSON.parse(J)).catch(()=>{return});if(K?.port===P&&K.token===z)await q(G).catch(()=>{})}}}async function Bf(f,x,z){let H=globalThis,Y=Symbol.for(f),Z=H[Y]??{servers:new Map,pending:new Map};H[Y]=Z;let{servers:V,pending:B}=Z,M=B.get(x)??Promise.resolve(),P,G=M.catch(()=>{}).then(async()=>{let J=V.get(x);if(J){if(await J.stop(),V.get(x)===J)V.delete(x)}P=await z(),V.set(x,P)});B.set(x,G);try{await G}finally{if(B.get(x)===G)B.delete(x)}let K=P;if(!K)throw Error("RPC server failed to start");return{server:K,release:async()=>{if(V.get(x)!==K)return;if(await K.stop(),V.get(x)===K)V.delete(x)}}}var yf=D(R);
2
+ export{c as Tb,d as Ub,i as Vb,xf as Wb,Bf as Xb,yf as Yb};