@cortexkit/opencode-openai-auth 1.23.1 → 1.23.2

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 (226) hide show
  1. package/dist/bin.js +7 -7
  2. package/dist/{index-7hy72nfy.js → index-by5wfvqm.js} +2 -2
  3. package/dist/index-nd2ks7er.js +2 -0
  4. package/dist/index-t876xhkr.js +60 -0
  5. package/dist/{index-p81hxfe6.js → index-v8w8j1wx.js} +1 -1
  6. package/dist/{index-3ya2s179.js → index-v8wrmhyp.js} +1 -1
  7. package/dist/{index-bd18sfjj.js → index-x00sxt2w.js} +10 -10
  8. package/dist/index.d.ts +3 -2
  9. package/dist/index.js +1 -1
  10. package/dist/{runtime-layout-B07ApQZL.d.ts → internal-DacVgEWs.d.ts} +86 -663
  11. package/dist/rpc/port-file.js +1 -1
  12. package/dist/runtime-layout-Dcbj_Rq3.d.ts +650 -0
  13. package/dist/{sidebar-state--OTpRzFd.d.ts → sidebar-state-L--CdbLi.d.ts} +4 -15
  14. package/dist/sidebar-state.d.ts +1 -1
  15. package/dist/sidebar-state.js +1 -1
  16. package/dist/tui.d.ts +5 -2
  17. package/dist/v2/server.d.ts +2 -1
  18. package/dist/v2/server.js +4 -4
  19. package/package.json +1 -1
  20. package/src/tui-compiled/raw/shared/054118b2705fdc20-ansi.js +98 -0
  21. package/src/tui-compiled/raw/shared/0895e780489c494d-window.js +33 -0
  22. package/src/tui-compiled/raw/shared/0b7d24474e2f33e9-credential-redaction.js +424 -0
  23. package/src/tui-compiled/raw/shared/0c9533222cb4380c-namespace.js +224 -0
  24. package/src/tui-compiled/raw/shared/112607e46a5b5f58-accounts.js +393 -0
  25. package/src/tui-compiled/raw/shared/136fa4abe48ad69d-cachekeep.js +411 -0
  26. package/src/tui-compiled/raw/shared/1547bd74f4214d2d-index.js +28 -0
  27. package/src/tui-compiled/raw/shared/1567207f323dc733-codex-http.js +44 -0
  28. package/src/tui-compiled/raw/shared/15f402885cbb2fb3-envelope-loss.js +151 -0
  29. package/src/tui-compiled/raw/shared/18df43cab4563acf-families.js +149 -0
  30. package/src/tui-compiled/raw/shared/1a4c289eec261e04-codex-instructions.js +59 -0
  31. package/src/tui-compiled/raw/shared/1afd446e190ef85c-vault-messages.js +12 -0
  32. package/src/tui-compiled/raw/shared/1b06ec96856ff8b9-codex-endpoint.js +17 -0
  33. package/src/tui-compiled/raw/shared/1e2f1a89bb34a773-vault-adapter.js +110 -0
  34. package/src/tui-compiled/raw/shared/2194fb8e8b42d7d5-insula-quota.js +73 -0
  35. package/src/tui-compiled/raw/shared/22b2bce42f2d6806-handle.js +10 -0
  36. package/src/tui-compiled/raw/shared/2577ec69f9973ae9-quota-normalize.js +13 -14
  37. package/src/tui-compiled/raw/shared/26055d4e5ad5e71f-codex-request.js +198 -0
  38. package/src/tui-compiled/raw/shared/26b57ac4c3b0c3f6-unconfirmed-retain-counter.js +41 -0
  39. package/src/tui-compiled/raw/shared/2bb681e99c2721d7-registry.js +538 -0
  40. package/src/tui-compiled/raw/shared/2dce6e9613993329-quota-manager.js +13 -20
  41. package/src/tui-compiled/raw/shared/2ec33b3e2b8ac38a-terminal.js +168 -0
  42. package/src/tui-compiled/raw/shared/30bcca1d1b4240a0-pool-session-pins.js +32 -0
  43. package/src/tui-compiled/raw/shared/3af9a210aa2ccdf2-codex-call-status.js +21 -0
  44. package/src/tui-compiled/raw/shared/3b31b36bf0877602-wording.js +120 -0
  45. package/src/tui-compiled/raw/shared/3c4c1a2d3fc92726-failure.js +59 -0
  46. package/src/tui-compiled/raw/shared/3dfe71eec6e0487d-presets.js +240 -0
  47. package/src/tui-compiled/raw/shared/43de3a5c4845cfc1-pool-adapter.js +149 -0
  48. package/src/tui-compiled/raw/shared/49353b63a833c8fb-session-cache-policy.js +60 -0
  49. package/src/tui-compiled/raw/shared/4adf46e07e025363-axes.js +7 -0
  50. package/src/tui-compiled/raw/shared/4ba847b77580b1eb-confirm.js +21 -0
  51. package/src/tui-compiled/raw/shared/4d05c2d7a531aece-oauth.js +48 -36
  52. package/src/tui-compiled/raw/shared/5018d4665e969588-limit-policy.js +159 -0
  53. package/src/tui-compiled/raw/shared/595bdf3fff13ba79-limit-identity.js +49 -0
  54. package/src/tui-compiled/raw/shared/59def9e82b61204a-session-cache-activity.js +35 -0
  55. package/src/tui-compiled/raw/shared/5d806e1a305d14f5-commands.js +879 -0
  56. package/src/tui-compiled/raw/shared/5fc39320fa8bd3a0-limit-registry.js +473 -0
  57. package/src/tui-compiled/raw/shared/63c1ee7e70e85e8d-vault.js +1 -0
  58. package/src/tui-compiled/raw/shared/6545ab7f757314b7-refresh-all-quota.js +237 -0
  59. package/src/tui-compiled/raw/shared/66937534c260d20b-stable-json.js +11 -0
  60. package/src/tui-compiled/raw/shared/7056acef1b021f19-bridge.js +10 -0
  61. package/src/tui-compiled/raw/shared/72d2ca42883809b4-marker.js +107 -0
  62. package/src/tui-compiled/raw/shared/775431e21f469203-record.js +3 -0
  63. package/src/tui-compiled/raw/shared/799f3ade4efbd1ea-opencode-v1.js +47 -0
  64. package/src/tui-compiled/raw/shared/7b2a0471b29e4f5e-wake.js +47 -0
  65. package/src/tui-compiled/raw/shared/7b5d6afff4ff32b9-select.js +159 -0
  66. package/src/tui-compiled/raw/shared/7bf96bf4d9249b3d-vault-billing.js +108 -0
  67. package/src/tui-compiled/raw/shared/7c98bde36aad4819-input-transformations.js +34 -0
  68. package/src/tui-compiled/raw/shared/7fb0418303f20a10-index.js +3 -0
  69. package/src/tui-compiled/raw/shared/806e12ccbad34388-pi-wait.js +51 -0
  70. package/src/tui-compiled/raw/shared/81ae201b724cac14-menu.js +73 -0
  71. package/src/tui-compiled/raw/shared/8349ed25dc629e97-scope.js +10 -0
  72. package/src/tui-compiled/raw/shared/86da3379973780b9-limit-provenance.js +60 -0
  73. package/src/tui-compiled/raw/shared/8aba66ed486d30a7-decide.js +425 -0
  74. package/src/tui-compiled/raw/shared/8c0c8df25a5dca1f-manager.js +735 -0
  75. package/src/tui-compiled/raw/shared/8c42bbec02f59636-vault-routing.js +212 -0
  76. package/src/tui-compiled/raw/shared/8ca6175bfae53e13-envelope.js +123 -0
  77. package/src/tui-compiled/raw/shared/8d0245e41049d83f-header-classifier.js +121 -0
  78. package/src/tui-compiled/raw/shared/9c162809179c7560-login.js +89 -0
  79. package/src/tui-compiled/raw/shared/a1f495296a4b756f-frame-turn.js +72 -0
  80. package/src/tui-compiled/raw/shared/a37138dcbd893f55-hold-bounds.js +5 -0
  81. package/src/tui-compiled/raw/shared/aa7fb10d77a2cccd-vault-account-menu.js +133 -0
  82. package/src/tui-compiled/raw/shared/adc5eeb5a8d28280-persistence.js +9 -0
  83. package/src/tui-compiled/raw/shared/b301c79e6378d1fb-vault.js +678 -0
  84. package/src/tui-compiled/raw/shared/b3c11de5f36e617a-reset.js +44 -0
  85. package/src/tui-compiled/raw/shared/ba6535c610d1edb3-pool-source-state.js +100 -0
  86. package/src/tui-compiled/raw/shared/bd4aef685681048c-duration.js +20 -0
  87. package/src/tui-compiled/raw/shared/bd5977eca210d2b8-index.js +662 -0
  88. package/src/tui-compiled/raw/shared/bfc46d34f4c9db33-limit-recovery.js +127 -0
  89. package/src/tui-compiled/raw/shared/c66495424ad84aee-hold.js +25 -0
  90. package/src/tui-compiled/raw/shared/c6a67b836bd5afcd-vault-command-menu.js +300 -0
  91. package/src/tui-compiled/raw/shared/c9340fb545c4e5de-internal.js +73 -0
  92. package/src/tui-compiled/raw/shared/c954c6447b7b9b64-activity.js +52 -0
  93. package/src/tui-compiled/raw/shared/cba8b0aee46b8526-codex-lite.js +85 -0
  94. package/src/tui-compiled/raw/shared/cec39ccddab4fe9c-labels.js +11 -0
  95. package/src/tui-compiled/raw/shared/cef0f2346957e83c-index.js +552 -0
  96. package/src/tui-compiled/raw/shared/cf7dedf24f902d68-dump-size.js +41 -0
  97. package/src/tui-compiled/raw/shared/d422d6dbc4e35199-background-quota-refresh.js +107 -0
  98. package/src/tui-compiled/raw/shared/d5b268767d330507-doctor.js +81 -0
  99. package/src/tui-compiled/raw/shared/d7ac5ca41f49121b-index.js +12 -0
  100. package/src/tui-compiled/raw/shared/d7fa77560855dee2-jitter.js +9 -0
  101. package/src/tui-compiled/raw/shared/de7f7d8803624369-path.js +31 -0
  102. package/src/tui-compiled/raw/shared/df0bdc74fb0c0db0-limit-mark.js +27 -0
  103. package/src/tui-compiled/raw/shared/e26c2bb5722ab047-routing-hold.js +23 -0
  104. package/src/tui-compiled/raw/shared/e2ae081583adfce3-dump.js +80 -0
  105. package/src/tui-compiled/raw/shared/e44ba1b3a9903f5d-reset-credits.js +483 -0
  106. package/src/tui-compiled/raw/shared/e5229952fc12f647-codex-models.js +34 -0
  107. package/src/tui-compiled/raw/shared/e8fda84e90176436-uuid-v7.js +13 -0
  108. package/src/tui-compiled/raw/shared/ea56007991dbf068-terminal.js +19 -0
  109. package/src/tui-compiled/raw/shared/ec6f1d96e7d70174-quota-refusal.js +145 -0
  110. package/src/tui-compiled/raw/shared/f03d7b43a214a4a1-canonical-input.js +42 -0
  111. package/src/tui-compiled/raw/shared/f1012265b3a768c7-merge-laws.js +31 -0
  112. package/src/tui-compiled/raw/shared/f2ca864fe967415a-cache-policy.js +198 -0
  113. package/src/tui-compiled/raw/shared/f317a4740f9d76f8-identity.js +21 -0
  114. package/src/tui-compiled/raw/shared/f607353c4126272a-routing-wait.js +19 -0
  115. package/src/tui-compiled/raw/shared/f6189f5c9aee31eb-decision.js +55 -0
  116. package/src/tui-compiled/raw/shared/f6d728f5e601f98b-request-history.js +120 -0
  117. package/src/tui-compiled/raw/shared/f981e6b15fb76cdb-codex-body.js +28 -0
  118. package/src/tui-compiled/raw/shared/fda579e5a0a54165-codex-effort.js +60 -0
  119. package/src/tui-compiled/raw/sidebar-state.js +54 -4
  120. package/src/tui-compiled/raw/tui/v2-dialog.js +1 -1
  121. package/src/tui-compiled/raw/tui.tsx +27 -5
  122. package/src/tui-compiled/runtime/shared/054118b2705fdc20-ansi.js +98 -0
  123. package/src/tui-compiled/runtime/shared/0895e780489c494d-window.js +33 -0
  124. package/src/tui-compiled/runtime/shared/0b7d24474e2f33e9-credential-redaction.js +424 -0
  125. package/src/tui-compiled/runtime/shared/0c9533222cb4380c-namespace.js +224 -0
  126. package/src/tui-compiled/runtime/shared/112607e46a5b5f58-accounts.js +393 -0
  127. package/src/tui-compiled/runtime/shared/136fa4abe48ad69d-cachekeep.js +411 -0
  128. package/src/tui-compiled/runtime/shared/1547bd74f4214d2d-index.js +28 -0
  129. package/src/tui-compiled/runtime/shared/1567207f323dc733-codex-http.js +44 -0
  130. package/src/tui-compiled/runtime/shared/15f402885cbb2fb3-envelope-loss.js +151 -0
  131. package/src/tui-compiled/runtime/shared/18df43cab4563acf-families.js +149 -0
  132. package/src/tui-compiled/runtime/shared/1a4c289eec261e04-codex-instructions.js +59 -0
  133. package/src/tui-compiled/runtime/shared/1afd446e190ef85c-vault-messages.js +12 -0
  134. package/src/tui-compiled/runtime/shared/1b06ec96856ff8b9-codex-endpoint.js +17 -0
  135. package/src/tui-compiled/runtime/shared/1e2f1a89bb34a773-vault-adapter.js +110 -0
  136. package/src/tui-compiled/runtime/shared/2194fb8e8b42d7d5-insula-quota.js +73 -0
  137. package/src/tui-compiled/runtime/shared/22b2bce42f2d6806-handle.js +10 -0
  138. package/src/tui-compiled/runtime/shared/2577ec69f9973ae9-quota-normalize.js +13 -14
  139. package/src/tui-compiled/runtime/shared/26055d4e5ad5e71f-codex-request.js +198 -0
  140. package/src/tui-compiled/runtime/shared/26b57ac4c3b0c3f6-unconfirmed-retain-counter.js +41 -0
  141. package/src/tui-compiled/runtime/shared/2bb681e99c2721d7-registry.js +538 -0
  142. package/src/tui-compiled/runtime/shared/2dce6e9613993329-quota-manager.js +13 -20
  143. package/src/tui-compiled/runtime/shared/2ec33b3e2b8ac38a-terminal.js +168 -0
  144. package/src/tui-compiled/runtime/shared/30bcca1d1b4240a0-pool-session-pins.js +32 -0
  145. package/src/tui-compiled/runtime/shared/3af9a210aa2ccdf2-codex-call-status.js +21 -0
  146. package/src/tui-compiled/runtime/shared/3b31b36bf0877602-wording.js +120 -0
  147. package/src/tui-compiled/runtime/shared/3c4c1a2d3fc92726-failure.js +59 -0
  148. package/src/tui-compiled/runtime/shared/3dfe71eec6e0487d-presets.js +240 -0
  149. package/src/tui-compiled/runtime/shared/43de3a5c4845cfc1-pool-adapter.js +149 -0
  150. package/src/tui-compiled/runtime/shared/49353b63a833c8fb-session-cache-policy.js +60 -0
  151. package/src/tui-compiled/runtime/shared/4adf46e07e025363-axes.js +7 -0
  152. package/src/tui-compiled/runtime/shared/4ba847b77580b1eb-confirm.js +21 -0
  153. package/src/tui-compiled/runtime/shared/4d05c2d7a531aece-oauth.js +48 -36
  154. package/src/tui-compiled/runtime/shared/5018d4665e969588-limit-policy.js +159 -0
  155. package/src/tui-compiled/runtime/shared/595bdf3fff13ba79-limit-identity.js +49 -0
  156. package/src/tui-compiled/runtime/shared/59def9e82b61204a-session-cache-activity.js +35 -0
  157. package/src/tui-compiled/runtime/shared/5d806e1a305d14f5-commands.js +879 -0
  158. package/src/tui-compiled/runtime/shared/5fc39320fa8bd3a0-limit-registry.js +473 -0
  159. package/src/tui-compiled/runtime/shared/63c1ee7e70e85e8d-vault.js +1 -0
  160. package/src/tui-compiled/runtime/shared/6545ab7f757314b7-refresh-all-quota.js +237 -0
  161. package/src/tui-compiled/runtime/shared/66937534c260d20b-stable-json.js +11 -0
  162. package/src/tui-compiled/runtime/shared/7056acef1b021f19-bridge.js +10 -0
  163. package/src/tui-compiled/runtime/shared/72d2ca42883809b4-marker.js +107 -0
  164. package/src/tui-compiled/runtime/shared/775431e21f469203-record.js +3 -0
  165. package/src/tui-compiled/runtime/shared/799f3ade4efbd1ea-opencode-v1.js +47 -0
  166. package/src/tui-compiled/runtime/shared/7b2a0471b29e4f5e-wake.js +47 -0
  167. package/src/tui-compiled/runtime/shared/7b5d6afff4ff32b9-select.js +159 -0
  168. package/src/tui-compiled/runtime/shared/7bf96bf4d9249b3d-vault-billing.js +108 -0
  169. package/src/tui-compiled/runtime/shared/7c98bde36aad4819-input-transformations.js +34 -0
  170. package/src/tui-compiled/runtime/shared/7fb0418303f20a10-index.js +3 -0
  171. package/src/tui-compiled/runtime/shared/806e12ccbad34388-pi-wait.js +51 -0
  172. package/src/tui-compiled/runtime/shared/81ae201b724cac14-menu.js +73 -0
  173. package/src/tui-compiled/runtime/shared/8349ed25dc629e97-scope.js +10 -0
  174. package/src/tui-compiled/runtime/shared/86da3379973780b9-limit-provenance.js +60 -0
  175. package/src/tui-compiled/runtime/shared/8aba66ed486d30a7-decide.js +425 -0
  176. package/src/tui-compiled/runtime/shared/8c0c8df25a5dca1f-manager.js +735 -0
  177. package/src/tui-compiled/runtime/shared/8c42bbec02f59636-vault-routing.js +212 -0
  178. package/src/tui-compiled/runtime/shared/8ca6175bfae53e13-envelope.js +123 -0
  179. package/src/tui-compiled/runtime/shared/8d0245e41049d83f-header-classifier.js +121 -0
  180. package/src/tui-compiled/runtime/shared/9c162809179c7560-login.js +89 -0
  181. package/src/tui-compiled/runtime/shared/a1f495296a4b756f-frame-turn.js +72 -0
  182. package/src/tui-compiled/runtime/shared/a37138dcbd893f55-hold-bounds.js +5 -0
  183. package/src/tui-compiled/runtime/shared/aa7fb10d77a2cccd-vault-account-menu.js +133 -0
  184. package/src/tui-compiled/runtime/shared/adc5eeb5a8d28280-persistence.js +9 -0
  185. package/src/tui-compiled/runtime/shared/b301c79e6378d1fb-vault.js +678 -0
  186. package/src/tui-compiled/runtime/shared/b3c11de5f36e617a-reset.js +44 -0
  187. package/src/tui-compiled/runtime/shared/ba6535c610d1edb3-pool-source-state.js +100 -0
  188. package/src/tui-compiled/runtime/shared/bd4aef685681048c-duration.js +20 -0
  189. package/src/tui-compiled/runtime/shared/bd5977eca210d2b8-index.js +662 -0
  190. package/src/tui-compiled/runtime/shared/bfc46d34f4c9db33-limit-recovery.js +127 -0
  191. package/src/tui-compiled/runtime/shared/c66495424ad84aee-hold.js +25 -0
  192. package/src/tui-compiled/runtime/shared/c6a67b836bd5afcd-vault-command-menu.js +300 -0
  193. package/src/tui-compiled/runtime/shared/c9340fb545c4e5de-internal.js +73 -0
  194. package/src/tui-compiled/runtime/shared/c954c6447b7b9b64-activity.js +52 -0
  195. package/src/tui-compiled/runtime/shared/cba8b0aee46b8526-codex-lite.js +85 -0
  196. package/src/tui-compiled/runtime/shared/cec39ccddab4fe9c-labels.js +11 -0
  197. package/src/tui-compiled/runtime/shared/cef0f2346957e83c-index.js +552 -0
  198. package/src/tui-compiled/runtime/shared/cf7dedf24f902d68-dump-size.js +41 -0
  199. package/src/tui-compiled/runtime/shared/d422d6dbc4e35199-background-quota-refresh.js +107 -0
  200. package/src/tui-compiled/runtime/shared/d5b268767d330507-doctor.js +81 -0
  201. package/src/tui-compiled/runtime/shared/d7ac5ca41f49121b-index.js +12 -0
  202. package/src/tui-compiled/runtime/shared/d7fa77560855dee2-jitter.js +9 -0
  203. package/src/tui-compiled/runtime/shared/de7f7d8803624369-path.js +31 -0
  204. package/src/tui-compiled/runtime/shared/df0bdc74fb0c0db0-limit-mark.js +27 -0
  205. package/src/tui-compiled/runtime/shared/e26c2bb5722ab047-routing-hold.js +23 -0
  206. package/src/tui-compiled/runtime/shared/e2ae081583adfce3-dump.js +80 -0
  207. package/src/tui-compiled/runtime/shared/e44ba1b3a9903f5d-reset-credits.js +483 -0
  208. package/src/tui-compiled/runtime/shared/e5229952fc12f647-codex-models.js +34 -0
  209. package/src/tui-compiled/runtime/shared/e8fda84e90176436-uuid-v7.js +13 -0
  210. package/src/tui-compiled/runtime/shared/ea56007991dbf068-terminal.js +19 -0
  211. package/src/tui-compiled/runtime/shared/ec6f1d96e7d70174-quota-refusal.js +145 -0
  212. package/src/tui-compiled/runtime/shared/f03d7b43a214a4a1-canonical-input.js +42 -0
  213. package/src/tui-compiled/runtime/shared/f1012265b3a768c7-merge-laws.js +31 -0
  214. package/src/tui-compiled/runtime/shared/f2ca864fe967415a-cache-policy.js +198 -0
  215. package/src/tui-compiled/runtime/shared/f317a4740f9d76f8-identity.js +21 -0
  216. package/src/tui-compiled/runtime/shared/f607353c4126272a-routing-wait.js +19 -0
  217. package/src/tui-compiled/runtime/shared/f6189f5c9aee31eb-decision.js +55 -0
  218. package/src/tui-compiled/runtime/shared/f6d728f5e601f98b-request-history.js +120 -0
  219. package/src/tui-compiled/runtime/shared/f981e6b15fb76cdb-codex-body.js +28 -0
  220. package/src/tui-compiled/runtime/shared/fda579e5a0a54165-codex-effort.js +60 -0
  221. package/src/tui-compiled/runtime/sidebar-state.js +54 -4
  222. package/src/tui-compiled/runtime/tui/v2-dialog.js +1 -1
  223. package/src/tui-compiled/runtime/tui.js +11 -4
  224. package/dist/index-0p8r7cpy.js +0 -60
  225. package/dist/index-px1t650b.js +0 -2
  226. package/dist/map-D5PHhv4z.d.ts +0 -72
@@ -0,0 +1,678 @@
1
+ import { statSync } from "node:fs";
2
+ import { rm } from "node:fs/promises";
3
+ import { dirname, join } from "node:path";
4
+ import { resolveClaustrumConnectionPath } from "@cortexkit/claustrum-client";
5
+ import {
6
+ assertHostSlotMatchesMode,
7
+ ClaustrumConsumer,
8
+ ClaustrumConsumerError,
9
+ ClaustrumEnrollmentManager,
10
+ ClaustrumUnreachableError,
11
+ connectClaustrumEnrollmentClient,
12
+ connectClaustrumScopedClient,
13
+ enrollmentName,
14
+ hasVaultHost,
15
+ hostEnrollmentPaths,
16
+ readClaustrumEnrollmentStatus,
17
+ readVaultRoster,
18
+ VAULT_HOST_CONNECT_REFUSAL,
19
+ vaultAuthority
20
+ } from "./e8d3c8da776ef9cd-index.js";
21
+ import { CommandError } from "./dbef697d1df1cd84-index.js";
22
+ import { projectQuota } from "./d5a8f1061ee2f114-index.js";
23
+ import {
24
+ normalizeInsulaCodexQuota,
25
+ preserveInsulaUnlimited
26
+ } from "./2194fb8e8b42d7d5-insula-quota.js";
27
+ import { createLogger } from "./d669d72c40e9e116-logger.js";
28
+ import { extractAccountIdFromClaims, parseJwtClaims } from "./4d05c2d7a531aece-oauth.js";
29
+ import { observationFromSnapshot } from "./bfbdd0f9aae56b47-pool-quota.js";
30
+ import { whamUsageFn } from "./85512cc5263ba259-provider.js";
31
+ import { errorMessage } from "./f37fcefc7aedbf25-error.js";
32
+ import {
33
+ VAULT_RECLASSIFY_COMMAND,
34
+ vaultEmptyAccessHint,
35
+ vaultGrantCommand
36
+ } from "./1afd446e190ef85c-vault-messages.js";
37
+ const log = createLogger("vault");
38
+ export const VAULT_PLUGIN_NAME = "openai-auth";
39
+
40
+ export { hasVaultHost as isVaultHosted };
41
+ export const VAULT_FAMILY = {
42
+ refreshAdapter: "openai",
43
+ category: "openai-native",
44
+ apiKeys: !1
45
+ };
46
+ const HOST_NAMES = {
47
+ opencode: "OpenCode",
48
+ pi: "Pi"
49
+ };
50
+ export const VAULT_REQUESTED_GRANTS = [
51
+ { selector: { category: "openai-native" }, operation: "read" }
52
+ ];
53
+ export function vaultEnrollmentName(host) {
54
+ return enrollmentName(VAULT_PLUGIN_NAME, host);
55
+ }
56
+ export function vaultEnrollmentDisplayName(host) {
57
+ return `ChatGPT for ${HOST_NAMES[host]}`;
58
+ }
59
+ export function vaultStateDir(accountStatePath) {
60
+ return join(dirname(accountStatePath), "openai-auth-vault");
61
+ }
62
+ export function vaultPaths(stateDir, host) {
63
+ return {
64
+ ...hostEnrollmentPaths({ stateDir, host }),
65
+ rosterPath: join(stateDir, `${host}-roster.json`)
66
+ };
67
+ }
68
+ export const VAULT_REQUEST_ROSTER_WAIT_MS = 2000, VAULT_MODE_REFUSAL_CAUSES = [
69
+ "vault-unreachable",
70
+ "vault-empty",
71
+ "vault-no-grant",
72
+ "vault-grant-unreached",
73
+ "vault-refused"
74
+ ], VAULT_MODE_REFUSALS = {
75
+ "vault-unreachable": "Request refused locally: this host is connected to the credential vault, which could not be reached, and local accounts are not used while it is connected. Start the vault and connect accounts in it, or disconnect this host from the vault.",
76
+ "vault-empty": "Request refused locally: this host is connected to the credential vault, which serves it no usable OpenAI account, and local accounts are not used while it is connected. Connect accounts in the vault, or disconnect this host from the vault.",
77
+ "vault-grant-unreached": `Request refused locally: this host is connected to the credential vault, whose grant for it reaches no ChatGPT login, and local accounts are not used while it is connected. Logins without the openai-native category are not reached: run ${VAULT_RECLASSIFY_COMMAND} to fill empty category sets, then check the CATEGORIES column with ck auth status. Or disconnect this host from the vault.`,
78
+ "vault-refused": "Request refused locally: the credential vault did not authorize an account, and local accounts are not used while this host is connected to it. Check the accounts in the vault, or disconnect this host from the vault."
79
+ };
80
+ export function vaultModeRefusalText(cause, name) {
81
+ if (cause !== "vault-no-grant")
82
+ return VAULT_MODE_REFUSALS[cause];
83
+ return `Request refused locally: this host is connected to the credential vault, which has no grant letting it read OpenAI accounts, and local accounts are not used while it is connected. Disconnect this host from the vault, or grant it access with: ${vaultGrantCommand(name)}`;
84
+ }
85
+ export function vaultModeNoRouteCause(vault) {
86
+ const roster = vault.snapshot();
87
+ if (roster === void 0)
88
+ return "vault-unreachable";
89
+ if (roster.rows.length === 0) {
90
+ const reach = vault.grantReach();
91
+ if (reach !== void 0)
92
+ return reach.grants === 0 ? "vault-no-grant" : "vault-grant-unreached";
93
+ }
94
+ return "vault-empty";
95
+ }
96
+ export function vaultIdentityOf(accessToken) {
97
+ const claims = parseJwtClaims(accessToken);
98
+ return claims ? extractAccountIdFromClaims(claims) : void 0;
99
+ }
100
+
101
+ export class OpenAiVault {
102
+ host;
103
+ name;
104
+ paths;
105
+ #options;
106
+ #consumer;
107
+ #pulls = new Map;
108
+ #quotaPolls = new Map;
109
+ #lastQuotaSource = new Map;
110
+ #consumerHasInsula;
111
+ #lastError;
112
+ #waiting;
113
+ #discovery;
114
+ #polling = !1;
115
+ #closed = !1;
116
+ #firstRoster = Promise.withResolvers();
117
+ #authority = "unknown";
118
+ #authorityKey;
119
+ constructor(options) {
120
+ this.#options = options;
121
+ this.host = options.host;
122
+ this.name = vaultEnrollmentName(options.host);
123
+ this.paths = vaultPaths(options.stateDir, options.host);
124
+ this.#consumer = new ClaustrumConsumer({
125
+ rosterPath: this.paths.rosterPath,
126
+ tokenPath: this.paths.tokenPath,
127
+ family: VAULT_FAMILY,
128
+ pluginId: VAULT_PLUGIN_NAME,
129
+ connect: () => this.#connectScoped(),
130
+ isCustodyActive: () => this.#custodyActive(),
131
+ ...options.reservedRouteIds ? { reservedRouteIds: options.reservedRouteIds } : {},
132
+ parseIdentity: vaultIdentityOf,
133
+ insula: { provider: "codex", normalize: normalizeInsulaCodexQuota },
134
+ ...options.now ? { now: options.now } : {},
135
+ ...options.pollIntervalMs !== void 0 ? { pollIntervalMs: options.pollIntervalMs } : {},
136
+ ...options.setTimeoutImpl ? { setTimeoutImpl: options.setTimeoutImpl } : {},
137
+ ...options.clearTimeoutImpl ? { clearTimeoutImpl: options.clearTimeoutImpl } : {},
138
+ onRoster: (roster) => {
139
+ this.#lastError = void 0;
140
+ const current = new Set(roster.rows.map((row) => row.routeId));
141
+ for (const id of this.#lastQuotaSource.keys())
142
+ if (!current.has(id))
143
+ this.#lastQuotaSource.delete(id);
144
+ },
145
+ onDiscovery: (discovery) => this.#track(discovery),
146
+ onError: (error) => this.#fail("vault roster refresh failed", error),
147
+ logger: {
148
+ ...log,
149
+ warn: (message, fields) => {
150
+ if (message !== "skipped insula provider poll")
151
+ log.warn(message, fields);
152
+ }
153
+ }
154
+ });
155
+ }
156
+ #connectionFile() {
157
+ return (this.#options.connectionFile ?? resolveClaustrumConnectionPath)();
158
+ }
159
+ #clientOptions() {
160
+ return {
161
+ connectionFile: this.#connectionFile(),
162
+ storagePath: this.paths.tokenPath,
163
+ logger: (errorClass) => log.debug("vault transport error", { errorClass })
164
+ };
165
+ }
166
+ #connectScoped() {
167
+ return (this.#options.connectScoped?.() ?? connectClaustrumScopedClient(this.#clientOptions())).then((client) => {
168
+ this.#consumerHasInsula = client.insula !== void 0;
169
+ return client;
170
+ });
171
+ }
172
+ #logQuotaSource(routeId, source, reason) {
173
+ if (!this.owns(routeId))
174
+ return;
175
+ const previous = this.#lastQuotaSource.get(routeId);
176
+ if (previous?.source === source && previous.reason === reason)
177
+ return;
178
+ this.#lastQuotaSource.set(routeId, { source, reason });
179
+ log.info("vault background quota source changed", {
180
+ routeId,
181
+ source,
182
+ reason
183
+ });
184
+ }
185
+ #connectEnrollment() {
186
+ return this.#options.connectEnrollment?.() ?? connectClaustrumEnrollmentClient(this.#clientOptions());
187
+ }
188
+ #fail(message, error) {
189
+ this.#lastError = errorMessage(error);
190
+ log.warn(message, {
191
+ host: this.host,
192
+ error: this.#lastError,
193
+ ...error instanceof ClaustrumUnreachableError && error.reason ? { reason: error.reason } : {}
194
+ });
195
+ }
196
+ #enrollmentKey() {
197
+ if (hasVaultHost())
198
+ return "host";
199
+ return [this.paths.tokenPath, this.paths.statePath].map((path) => {
200
+ try {
201
+ const stat = statSync(path);
202
+ return `${stat.ino}:${stat.size}:${stat.mtimeMs}:${stat.ctimeMs}`;
203
+ } catch {
204
+ return "?";
205
+ }
206
+ }).join("|");
207
+ }
208
+ async authority() {
209
+ const key = this.#enrollmentKey(), mode = await vaultAuthority(this.paths, this.name);
210
+ if (key === this.#enrollmentKey()) {
211
+ if (mode !== this.#authority)
212
+ log.info("vault authority", { host: this.host, authority: mode });
213
+ this.#authority = mode;
214
+ this.#authorityKey = key;
215
+ return mode;
216
+ }
217
+ return "unreadable";
218
+ }
219
+ enrolled() {
220
+ return hasVaultHost() || this.#authorityKey !== this.#enrollmentKey() || this.#authority !== "local";
221
+ }
222
+ async#custodyActive() {
223
+ if (this.#authorityKey !== this.#enrollmentKey())
224
+ await this.authority();
225
+ return this.enrolled();
226
+ }
227
+ start() {
228
+ if (this.#polling || this.#closed)
229
+ return;
230
+ this.#polling = !0;
231
+ this.#consumer.start();
232
+ }
233
+ #track(discovery) {
234
+ if (this.#discovery === discovery)
235
+ return;
236
+ this.#discovery = discovery;
237
+ discovery.finally(() => {
238
+ if (this.#discovery === discovery)
239
+ this.#discovery = void 0;
240
+ this.#firstRoster.resolve();
241
+ }).catch(() => {});
242
+ }
243
+ #discover() {
244
+ return this.#consumer.refresh();
245
+ }
246
+ firstRoster() {
247
+ return this.#firstRoster.promise;
248
+ }
249
+ async awaitRequestRoster() {
250
+ if (this.snapshot())
251
+ return;
252
+ if (!["vault", "host"].includes(await this.authority()))
253
+ return;
254
+ const inFlight = this.#discovery;
255
+ if (inFlight)
256
+ await inFlight.catch(() => {
257
+ return;
258
+ });
259
+ if (this.snapshot() || !["vault", "host"].includes(await this.authority()))
260
+ return;
261
+ await (this.#discovery ?? this.#discover()).catch((error) => {
262
+ this.#fail("vault roster refresh failed", error);
263
+ });
264
+ }
265
+ async refresh() {
266
+ try {
267
+ await this.authority();
268
+ const earlier = this.#discovery;
269
+ if (earlier)
270
+ await earlier.catch(() => {
271
+ return;
272
+ });
273
+ const roster = await this.#discover();
274
+ this.#lastError = void 0;
275
+ return roster;
276
+ } catch (error) {
277
+ this.#fail("vault roster refresh failed", error);
278
+ return this.#consumer.snapshot();
279
+ }
280
+ }
281
+ snapshot() {
282
+ return this.#consumer.snapshot();
283
+ }
284
+ watchState() {
285
+ return this.#consumer.watchState();
286
+ }
287
+ keptReceiptState() {
288
+ return this.#consumer.keptReceiptState();
289
+ }
290
+ grantReach() {
291
+ return this.#consumer.grantReach();
292
+ }
293
+ serves() {
294
+ return this.enrolled() && (this.snapshot()?.rows.length ?? 0) > 0;
295
+ }
296
+ identities() {
297
+ if (!this.enrolled())
298
+ return new Set;
299
+ return new Set((this.snapshot()?.rows ?? []).flatMap((row) => row.accountIdentity !== void 0 ? [row.accountIdentity] : []));
300
+ }
301
+ routes() {
302
+ if (!this.enrolled())
303
+ return [];
304
+ const rows = new Map((this.snapshot()?.rows ?? []).map((row) => [row.routeId, row]));
305
+ return this.#consumer.routingRows().map((routing) => {
306
+ const identity = rows.get(routing.id)?.accountIdentity;
307
+ return {
308
+ id: routing.id,
309
+ credentialId: rows.get(routing.id)?.credentialId,
310
+ kind: routing.kind === "api-key" ? "api-key" : "oauth",
311
+ ...identity !== void 0 ? { identity } : {},
312
+ ...routing.quota !== void 0 ? { quota: routing.quota } : {}
313
+ };
314
+ });
315
+ }
316
+ owns(routeId) {
317
+ return (this.snapshot()?.rows ?? []).some((row) => row.routeId === routeId);
318
+ }
319
+ async send(routeId, dispatch, options) {
320
+ let dispatched = !1;
321
+ try {
322
+ return await this.#consumer.send(routeId, (attempt) => {
323
+ dispatched = !0;
324
+ return dispatch(attempt.accessToken, attempt);
325
+ }, {
326
+ site: options.site,
327
+ ...options.signal ? { signal: options.signal } : {}
328
+ });
329
+ } catch (error) {
330
+ if (dispatched)
331
+ throw error;
332
+ this.#fail("vault refused to serve an account", error);
333
+ return;
334
+ }
335
+ }
336
+ async authorize(routeId, options = {}) {
337
+ try {
338
+ return await this.#consumer.authorize(routeId, options.signal);
339
+ } catch (error) {
340
+ this.#fail("vault refused to serve an account", error);
341
+ return;
342
+ }
343
+ }
344
+ async reportFailure(attempt, status) {
345
+ if (status !== 401)
346
+ return;
347
+ try {
348
+ await this.#consumer.reportFailure(attempt, 401, "direct");
349
+ } catch (error) {
350
+ this.#fail("vault failure report failed", error);
351
+ }
352
+ await this.refresh();
353
+ }
354
+ recordSnapshot(routeId, snapshot, complete, receipt) {
355
+ const observation = observationFromSnapshot(snapshot, (this.#options.now ?? Date.now)(), complete);
356
+ if (!observation)
357
+ return Promise.resolve();
358
+ return this.#consumer.recordQuota(routeId, observation, receipt).then(() => {}, (error) => this.#fail("vault quota write failed", error));
359
+ }
360
+ reportUsage(routeId, reply, receipt) {
361
+ try {
362
+ let metadata;
363
+ if ("headers" in reply) {
364
+ const headers = {};
365
+ reply.headers.forEach((value, name) => {
366
+ if (name.startsWith("x-codex-"))
367
+ headers[name] = value;
368
+ });
369
+ if (Object.keys(headers).length === 0)
370
+ return;
371
+ metadata = { headers };
372
+ } else
373
+ metadata = { frame: reply.frame };
374
+ this.#consumer.reportUsage({
375
+ routeId,
376
+ credentialId: receipt.credentialId,
377
+ reading: {
378
+ provider: "codex",
379
+ observedAtMs: (this.#options.now ?? Date.now)(),
380
+ ...metadata,
381
+ ...receipt.accountIdentity ? { account: receipt.accountIdentity } : {}
382
+ }
383
+ });
384
+ } catch {}
385
+ }
386
+ pollQuota(routeId, background = !0) {
387
+ const pending = this.#quotaPolls.get(routeId);
388
+ if (pending)
389
+ return pending;
390
+ const pull = this.#pollQuota(routeId, background).finally(() => {
391
+ this.#quotaPolls.delete(routeId);
392
+ });
393
+ this.#quotaPolls.set(routeId, pull);
394
+ return pull;
395
+ }
396
+ async#pollQuota(routeId, background) {
397
+ if (background) {
398
+ await this.authority();
399
+ await this.#consumer.refreshInsulaQuota();
400
+ const row = (await readVaultRoster(this.paths.rosterPath))?.rows.find((row) => row.routeId === routeId);
401
+ let fallback;
402
+ const cached = await this.#consumer.pollInsulaQuotaForRoute(routeId, async () => {
403
+ this.#logQuotaSource(routeId, "fallback", this.#consumerHasInsula === !1 ? "insula-not-configured" : "no-insula-reading");
404
+ fallback = await this.#pollProviderQuota(routeId, background);
405
+ return;
406
+ });
407
+ if (fallback)
408
+ return fallback;
409
+ if (cached !== void 0 && row?.accountIdentity) {
410
+ const observation = observationFromSnapshot(preserveInsulaUnlimited(cached, this.routes().find((route) => route.id === routeId)?.quota), cached.primary.checkedAt, !0);
411
+ if (!observation) {
412
+ this.#logQuotaSource(routeId, "fallback", "insula-unusable");
413
+ return { ok: !1, error: "unusable insula reading" };
414
+ }
415
+ if (await this.#consumer.recordAccountQuota(routeId, row.accountIdentity, observation)) {
416
+ this.#logQuotaSource(routeId, "insula", null);
417
+ return { ok: !0 };
418
+ }
419
+ this.#logQuotaSource(routeId, "fallback", "account-changed");
420
+ return { ok: !1, error: "vault account changed" };
421
+ }
422
+ const { miss } = await this.#consumer.lookupInsulaQuotaForRoute(routeId), reason = miss === "cold" || miss === "upstream-failed" ? miss : "no-insula-reading";
423
+ this.#logQuotaSource(routeId, "insula", reason);
424
+ return { ok: !1, error: `insula ${reason}` };
425
+ }
426
+ return this.#pollProviderQuota(routeId, background);
427
+ }
428
+ async#pollProviderQuota(routeId, background) {
429
+ let failure;
430
+ const fetchImpl = this.#options.fetchImpl?.() ?? globalThis.fetch, response = await this.send(routeId, async (token, attempt) => {
431
+ try {
432
+ const cached = background ? void 0 : await this.#consumer.cachedInsulaQuota(attempt);
433
+ if (cached !== void 0) {
434
+ const observation = observationFromSnapshot(preserveInsulaUnlimited(cached, this.routes().find((route) => route.id === routeId)?.quota), cached.primary.checkedAt, !0);
435
+ if (!observation)
436
+ throw Error("unusable insula reading");
437
+ await this.#consumer.recordQuota(routeId, observation, attempt);
438
+ return new Response(null, { status: 200 });
439
+ }
440
+ const snapshot = await whamUsageFn({
441
+ accessToken: token,
442
+ fetchImpl,
443
+ now: this.#options.now ?? Date.now,
444
+ ...attempt.accountIdentity ? { accountId: attempt.accountIdentity } : {},
445
+ accountKey: routeId,
446
+ logger: log
447
+ });
448
+ await this.recordSnapshot(routeId, snapshot, !0, attempt);
449
+ failure = void 0;
450
+ return new Response(null, { status: 200 });
451
+ } catch (error) {
452
+ failure = errorMessage(error);
453
+ const status = error?.status;
454
+ if (typeof status === "number")
455
+ return new Response(null, { status });
456
+ throw error;
457
+ }
458
+ }, { site: "quota" }).catch((error) => {
459
+ failure = errorMessage(error);
460
+ return;
461
+ });
462
+ if (!response)
463
+ return { ok: !1, error: failure ?? "vault refused" };
464
+ return response.ok ? { ok: !0 } : { ok: !1, error: failure ?? `status ${response.status}` };
465
+ }
466
+ requestReading(routeId) {
467
+ const pending = this.#pulls.get(routeId);
468
+ if (pending)
469
+ return pending;
470
+ const pull = this.pollQuota(routeId, !1).catch((error) => {
471
+ log.warn("vault quota poll failed", {
472
+ routeId,
473
+ error: errorMessage(error)
474
+ });
475
+ }).finally(() => {
476
+ this.#pulls.delete(routeId);
477
+ });
478
+ this.#pulls.set(routeId, pull);
479
+ return pull;
480
+ }
481
+ async pollStale(maxAgeMs) {
482
+ const now = (this.#options.now ?? Date.now)(), results = [];
483
+ for (const route of this.routes()) {
484
+ const checkedAt = latestReadingAt(route.quota);
485
+ if (checkedAt !== void 0 && now - checkedAt < maxAgeMs)
486
+ continue;
487
+ results.push({ id: route.id, ...await this.pollQuota(route.id) });
488
+ }
489
+ return results;
490
+ }
491
+ async reorder(routeIds) {
492
+ const authority = await this.authority();
493
+ if (authority !== "vault" && authority !== "host")
494
+ throw Error("Vault order can only be changed in vault mode.");
495
+ return this.#consumer.reorder(routeIds);
496
+ }
497
+ async decline(routeId) {
498
+ await this.#consumer.decline(routeId);
499
+ log.info("vault account declined", { routeId });
500
+ }
501
+ async accept(routeId) {
502
+ await this.#consumer.accept(routeId);
503
+ log.info("vault account accepted", { routeId });
504
+ }
505
+ async status() {
506
+ const authority = await this.authority();
507
+ let enrollment;
508
+ try {
509
+ enrollment = authority === "host" ? { state: "idle" } : await readClaustrumEnrollmentStatus(this.paths, this.name);
510
+ } catch (error) {
511
+ this.#fail("vault enrollment state unreadable", error);
512
+ enrollment = {
513
+ state: "blocked",
514
+ proposedName: this.name,
515
+ code: error instanceof ClaustrumConsumerError ? error.kind : "unreadable-state"
516
+ };
517
+ }
518
+ const snapshot = this.enrolled() ? this.snapshot() : void 0;
519
+ return {
520
+ host: this.host,
521
+ name: this.name,
522
+ enrollment,
523
+ discovered: snapshot !== void 0,
524
+ accounts: snapshot?.rows ?? [],
525
+ ...this.#lastError ? { lastError: this.#lastError } : {}
526
+ };
527
+ }
528
+ async connectStep() {
529
+ if (await this.authority() === "host")
530
+ throw new CommandError("vault-host", VAULT_HOST_CONNECT_REFUSAL);
531
+ const client = await this.#connectEnrollment().catch((error) => {
532
+ throw new CommandError("vault-unreachable", `Could not reach the Claustrum vault (${this.#connectionFile()}): ${errorMessage(error)}. Is the vault running?`);
533
+ });
534
+ try {
535
+ const manager = new ClaustrumEnrollmentManager({
536
+ client,
537
+ paths: this.paths,
538
+ proposedName: this.name,
539
+ displayName: vaultEnrollmentDisplayName(this.host),
540
+ requestedGrants: VAULT_REQUESTED_GRANTS,
541
+ ...this.#options.now ? { now: this.#options.now } : {}
542
+ }), current = await manager.status();
543
+ if (current.state === "denied" || current.state === "blocked")
544
+ await manager.resetTerminal();
545
+ const status = await manager.reconcile();
546
+ log.info("vault enrollment step", {
547
+ host: this.host,
548
+ state: status.state
549
+ });
550
+ if (status.state === "approved") {
551
+ this.#lastError = void 0;
552
+ await this.refresh();
553
+ }
554
+ return status;
555
+ } finally {
556
+ client.close();
557
+ }
558
+ }
559
+ waitForApproval(options = {}) {
560
+ this.#waiting ??= (async () => {
561
+ const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms))), interval = options.pollIntervalMs ?? 2000, deadline = Date.now() + (options.timeoutMs ?? 600000);
562
+ let status = await this.connectStep();
563
+ while (status.state === "pending" || status.state === "busy") {
564
+ options.onPending?.(status);
565
+ if (Date.now() >= deadline)
566
+ return status;
567
+ await sleep(interval);
568
+ status = await this.connectStep();
569
+ }
570
+ return status;
571
+ })().finally(() => {
572
+ this.#waiting = void 0;
573
+ });
574
+ return this.#waiting;
575
+ }
576
+ async disconnect() {
577
+ if (await this.authority() === "host")
578
+ throw new CommandError("vault-host", VAULT_HOST_CONNECT_REFUSAL);
579
+ await rm(this.paths.tokenPath, { force: !0 });
580
+ await rm(this.paths.statePath, { force: !0 });
581
+ await this.#options.afterDisconnect?.();
582
+ await this.authority();
583
+ this.#lastError = void 0;
584
+ log.info("vault enrollment forgotten", { host: this.host });
585
+ }
586
+ assertHostSlot(auth) {
587
+ if (this.serves())
588
+ assertHostSlotMatchesMode({ mode: "custody", auth, provider: "openai" });
589
+ }
590
+ close() {
591
+ this.#closed = !0;
592
+ this.#firstRoster.resolve();
593
+ this.#consumer.close();
594
+ }
595
+ async dispose() {
596
+ this.close();
597
+ await this.#consumer.dispose();
598
+ }
599
+ }
600
+ function latestReadingAt(quota) {
601
+ if (!quota)
602
+ return;
603
+ const times = projectQuota(quota).limits.map((limit) => limit.checkedAt);
604
+ return times.length > 0 ? Math.max(...times) : void 0;
605
+ }
606
+ export function vaultApprovalInstructions(name, status) {
607
+ if (status.state !== "pending")
608
+ return [];
609
+ if (!status.requestId)
610
+ return [
611
+ `The vault did not take the enrollment request yet${status.retryCode ? ` (${status.retryCode})` : ""}. Run Connect again in a moment.`
612
+ ];
613
+ return [
614
+ `Enrollment request ${status.requestId} for ${name} is waiting for approval. Approve it with:`,
615
+ ` ck auth enroll approve --request-id ${status.requestId}`,
616
+ ...status.requestedGrantsStatus === "sent" ? [] : [
617
+ `Then grant OpenAI access to the name you approved with --name (defaults to ${name}):`,
618
+ ` ${vaultGrantCommand(name)}`
619
+ ]
620
+ ];
621
+ }
622
+ export function vaultEnrollmentLine(host, name, status) {
623
+ const who = `${HOST_NAMES[host]} (${status.state === "approved" ? status.approvedName ?? name : name})`;
624
+ switch (status.state) {
625
+ case "approved":
626
+ return `${who}: connected to the Claustrum vault.`;
627
+ case "idle":
628
+ return `${who}: not connected to the Claustrum vault.`;
629
+ case "pending":
630
+ return status.requestId ? `${who}: waiting for approval of request ${status.requestId}.` : `${who}: enrollment request not taken yet${status.retryCode ? ` (${status.retryCode})` : ""}.`;
631
+ case "denied":
632
+ return `${who}: the vault denied the enrollment request.`;
633
+ case "blocked":
634
+ return `${who}: enrollment stopped (${status.code}).`;
635
+ case "unavailable":
636
+ return `${who}: the vault is unavailable (${status.code}).`;
637
+ case "busy":
638
+ return `${who}: another process is enrolling right now.`;
639
+ }
640
+ }
641
+ export function vaultConnectOutcome(vault, status) {
642
+ if ((status.state === "blocked" || status.state === "unavailable") && status.code === "unknown_method")
643
+ return {
644
+ ok: !1,
645
+ text: 'Enrollment stopped (unknown_method). This Claustrum vault is too old to connect plugins. Run ck upgrade to move to Claustrum v0.2.0 or newer (read "Upgrading from v0.1.3" in its release notes first), then run Connect again.'
646
+ };
647
+ switch (status.state) {
648
+ case "approved": {
649
+ const name = status.approvedName ?? vault.name, accounts = vault.snapshot()?.rows.length ?? 0;
650
+ return {
651
+ ok: !0,
652
+ text: `Connected: the vault approved ${name}. It serves ${accounts} OpenAI account${accounts === 1 ? "" : "s"} to this host${accounts === 0 ? `. ${vaultEmptyAccessHint(name, vault.grantReach())}` : "."}`
653
+ };
654
+ }
655
+ case "denied":
656
+ return {
657
+ ok: !1,
658
+ text: "The vault denied the enrollment request. Run Connect again to send a new one."
659
+ };
660
+ case "blocked":
661
+ return {
662
+ ok: !1,
663
+ text: `Enrollment stopped (${status.code}). Resolve the refusal before running Connect again.`
664
+ };
665
+ case "pending":
666
+ case "busy":
667
+ return {
668
+ ok: !1,
669
+ text: [
670
+ ...vaultApprovalInstructions(vault.name, status),
671
+ "Still waiting. The request stays open: run Connect again after approving it."
672
+ ].join(`
673
+ `)
674
+ };
675
+ default:
676
+ return { ok: !1, text: `Enrollment is ${status.state}.` };
677
+ }
678
+ }