@code-yeongyu/senpi 2026.9.10 → 2026.9.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (337) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/dist/core/agent-session.d.ts +57 -0
  3. package/dist/core/agent-session.d.ts.map +1 -1
  4. package/dist/core/agent-session.js +130 -20
  5. package/dist/core/agent-session.js.map +1 -1
  6. package/dist/core/auth-storage.d.ts +2 -0
  7. package/dist/core/auth-storage.d.ts.map +1 -1
  8. package/dist/core/auth-storage.js +49 -17
  9. package/dist/core/auth-storage.js.map +1 -1
  10. package/dist/core/brand.d.ts +5 -0
  11. package/dist/core/brand.d.ts.map +1 -1
  12. package/dist/core/brand.js +13 -0
  13. package/dist/core/brand.js.map +1 -1
  14. package/dist/core/changelog-source.d.ts +8 -0
  15. package/dist/core/changelog-source.d.ts.map +1 -0
  16. package/dist/core/changelog-source.js +19 -0
  17. package/dist/core/changelog-source.js.map +1 -0
  18. package/dist/core/credential-accounts.d.ts +3 -0
  19. package/dist/core/credential-accounts.d.ts.map +1 -1
  20. package/dist/core/credential-accounts.js +20 -1
  21. package/dist/core/credential-accounts.js.map +1 -1
  22. package/dist/core/credential-pool/classify.d.ts.map +1 -1
  23. package/dist/core/credential-pool/classify.js +8 -0
  24. package/dist/core/credential-pool/classify.js.map +1 -1
  25. package/dist/core/extensions/builtin/account/index.d.ts.map +1 -1
  26. package/dist/core/extensions/builtin/account/index.js +7 -3
  27. package/dist/core/extensions/builtin/account/index.js.map +1 -1
  28. package/dist/core/extensions/builtin/account-display-name.d.ts +7 -0
  29. package/dist/core/extensions/builtin/account-display-name.d.ts.map +1 -0
  30. package/dist/core/extensions/builtin/account-display-name.js +40 -0
  31. package/dist/core/extensions/builtin/account-display-name.js.map +1 -0
  32. package/dist/core/extensions/builtin/ask-user/format.d.ts.map +1 -1
  33. package/dist/core/extensions/builtin/ask-user/format.js +7 -2
  34. package/dist/core/extensions/builtin/ask-user/format.js.map +1 -1
  35. package/dist/core/extensions/builtin/ask-user/pending.d.ts.map +1 -1
  36. package/dist/core/extensions/builtin/ask-user/pending.js +3 -0
  37. package/dist/core/extensions/builtin/ask-user/pending.js.map +1 -1
  38. package/dist/core/extensions/builtin/claude-sdk-oauth/account-command.d.ts.map +1 -1
  39. package/dist/core/extensions/builtin/claude-sdk-oauth/account-command.js +21 -9
  40. package/dist/core/extensions/builtin/claude-sdk-oauth/account-command.js.map +1 -1
  41. package/dist/core/extensions/builtin/claude-sdk-oauth/account-management.d.ts +1 -0
  42. package/dist/core/extensions/builtin/claude-sdk-oauth/account-management.d.ts.map +1 -1
  43. package/dist/core/extensions/builtin/claude-sdk-oauth/account-management.js +11 -6
  44. package/dist/core/extensions/builtin/claude-sdk-oauth/account-management.js.map +1 -1
  45. package/dist/core/extensions/builtin/claude-sdk-oauth/accounts.d.ts +9 -0
  46. package/dist/core/extensions/builtin/claude-sdk-oauth/accounts.d.ts.map +1 -1
  47. package/dist/core/extensions/builtin/claude-sdk-oauth/accounts.js +10 -1
  48. package/dist/core/extensions/builtin/claude-sdk-oauth/accounts.js.map +1 -1
  49. package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js +3 -0
  50. package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js.map +1 -1
  51. package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.d.ts.map +1 -1
  52. package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js +19 -10
  53. package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js.map +1 -1
  54. package/dist/core/extensions/builtin/claude-sdk-oauth/settings.d.ts.map +1 -1
  55. package/dist/core/extensions/builtin/claude-sdk-oauth/settings.js +3 -9
  56. package/dist/core/extensions/builtin/claude-sdk-oauth/settings.js.map +1 -1
  57. package/dist/core/extensions/builtin/config-reload/routine-settings.d.ts.map +1 -1
  58. package/dist/core/extensions/builtin/config-reload/routine-settings.js +1 -0
  59. package/dist/core/extensions/builtin/config-reload/routine-settings.js.map +1 -1
  60. package/dist/core/extensions/builtin/cursor-cli-oauth/account-command.d.ts.map +1 -1
  61. package/dist/core/extensions/builtin/cursor-cli-oauth/account-command.js +5 -3
  62. package/dist/core/extensions/builtin/cursor-cli-oauth/account-command.js.map +1 -1
  63. package/dist/core/extensions/builtin/cursor-cli-oauth/accounts.d.ts +1 -0
  64. package/dist/core/extensions/builtin/cursor-cli-oauth/accounts.d.ts.map +1 -1
  65. package/dist/core/extensions/builtin/cursor-cli-oauth/accounts.js.map +1 -1
  66. package/dist/core/extensions/builtin/cursor-cli-oauth/settings.d.ts.map +1 -1
  67. package/dist/core/extensions/builtin/cursor-cli-oauth/settings.js +3 -9
  68. package/dist/core/extensions/builtin/cursor-cli-oauth/settings.js.map +1 -1
  69. package/dist/core/extensions/builtin/goal/agent-end-continuation.d.ts.map +1 -1
  70. package/dist/core/extensions/builtin/goal/agent-end-continuation.js +13 -1
  71. package/dist/core/extensions/builtin/goal/agent-end-continuation.js.map +1 -1
  72. package/dist/core/extensions/builtin/goal/prompt.d.ts.map +1 -1
  73. package/dist/core/extensions/builtin/goal/prompt.js +11 -8
  74. package/dist/core/extensions/builtin/goal/prompt.js.map +1 -1
  75. package/dist/core/extensions/builtin/goal/terminal-provider-error.d.ts +1 -0
  76. package/dist/core/extensions/builtin/goal/terminal-provider-error.d.ts.map +1 -1
  77. package/dist/core/extensions/builtin/goal/terminal-provider-error.js +28 -0
  78. package/dist/core/extensions/builtin/goal/terminal-provider-error.js.map +1 -1
  79. package/dist/core/extensions/builtin/goal/todo-gate.js +2 -2
  80. package/dist/core/extensions/builtin/goal/todo-gate.js.map +1 -1
  81. package/dist/core/extensions/builtin/goal/tool-registration.js +2 -2
  82. package/dist/core/extensions/builtin/goal/tool-registration.js.map +1 -1
  83. package/dist/core/extensions/builtin/gpt-account.d.ts.map +1 -1
  84. package/dist/core/extensions/builtin/gpt-account.js +19 -8
  85. package/dist/core/extensions/builtin/gpt-account.js.map +1 -1
  86. package/dist/core/extensions/builtin/prompt-preset/deepseek-v4-1-flash.d.ts +3 -0
  87. package/dist/core/extensions/builtin/prompt-preset/deepseek-v4-1-flash.d.ts.map +1 -0
  88. package/dist/core/extensions/builtin/prompt-preset/deepseek-v4-1-flash.js +19 -0
  89. package/dist/core/extensions/builtin/prompt-preset/deepseek-v4-1-flash.js.map +1 -0
  90. package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.d.ts +6 -6
  91. package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.d.ts.map +1 -1
  92. package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.js +26 -7
  93. package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.js.map +1 -1
  94. package/dist/core/extensions/builtin/prompt-preset/presets.d.ts.map +1 -1
  95. package/dist/core/extensions/builtin/prompt-preset/presets.js +29 -0
  96. package/dist/core/extensions/builtin/prompt-preset/presets.js.map +1 -1
  97. package/dist/core/extensions/builtin/prompt-preset/settings.d.ts +1 -1
  98. package/dist/core/extensions/builtin/prompt-preset/settings.d.ts.map +1 -1
  99. package/dist/core/extensions/builtin/prompt-preset/settings.js +1 -0
  100. package/dist/core/extensions/builtin/prompt-preset/settings.js.map +1 -1
  101. package/dist/core/high-reasoning-warning.d.ts.map +1 -1
  102. package/dist/core/high-reasoning-warning.js +5 -1
  103. package/dist/core/high-reasoning-warning.js.map +1 -1
  104. package/dist/core/manual-continue.d.ts +14 -0
  105. package/dist/core/manual-continue.d.ts.map +1 -1
  106. package/dist/core/manual-continue.js +13 -0
  107. package/dist/core/manual-continue.js.map +1 -1
  108. package/dist/core/model-runtime.d.ts.map +1 -1
  109. package/dist/core/model-runtime.js +2 -2
  110. package/dist/core/model-runtime.js.map +1 -1
  111. package/dist/core/remote-catalog-merge.d.ts +16 -0
  112. package/dist/core/remote-catalog-merge.d.ts.map +1 -0
  113. package/dist/core/remote-catalog-merge.js +75 -0
  114. package/dist/core/remote-catalog-merge.js.map +1 -0
  115. package/dist/core/remote-catalog-provider.d.ts +3 -0
  116. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  117. package/dist/core/remote-catalog-provider.js +12 -40
  118. package/dist/core/remote-catalog-provider.js.map +1 -1
  119. package/dist/core/session-entry-materializer.d.ts +12 -0
  120. package/dist/core/session-entry-materializer.d.ts.map +1 -0
  121. package/dist/core/session-entry-materializer.js +26 -0
  122. package/dist/core/session-entry-materializer.js.map +1 -0
  123. package/dist/core/session-manager.d.ts +36 -1
  124. package/dist/core/session-manager.d.ts.map +1 -1
  125. package/dist/core/session-manager.js +38 -8
  126. package/dist/core/session-manager.js.map +1 -1
  127. package/dist/core/settings-manager.d.ts +3 -0
  128. package/dist/core/settings-manager.d.ts.map +1 -1
  129. package/dist/core/settings-manager.js +10 -0
  130. package/dist/core/settings-manager.js.map +1 -1
  131. package/dist/modes/app-server/daemon/process.d.ts +6 -1
  132. package/dist/modes/app-server/daemon/process.d.ts.map +1 -1
  133. package/dist/modes/app-server/daemon/process.js +23 -4
  134. package/dist/modes/app-server/daemon/process.js.map +1 -1
  135. package/dist/modes/app-server/protocol/account.d.ts +2 -0
  136. package/dist/modes/app-server/protocol/account.d.ts.map +1 -1
  137. package/dist/modes/app-server/protocol/account.js.map +1 -1
  138. package/dist/modes/interactive/components/ask-user-question-keys.d.ts +1 -1
  139. package/dist/modes/interactive/components/ask-user-question-keys.d.ts.map +1 -1
  140. package/dist/modes/interactive/components/ask-user-question-keys.js +65 -17
  141. package/dist/modes/interactive/components/ask-user-question-keys.js.map +1 -1
  142. package/dist/modes/interactive/components/ask-user-question-render.d.ts +2 -1
  143. package/dist/modes/interactive/components/ask-user-question-render.d.ts.map +1 -1
  144. package/dist/modes/interactive/components/ask-user-question-render.js +39 -9
  145. package/dist/modes/interactive/components/ask-user-question-render.js.map +1 -1
  146. package/dist/modes/interactive/components/ask-user-question-state.d.ts +14 -4
  147. package/dist/modes/interactive/components/ask-user-question-state.d.ts.map +1 -1
  148. package/dist/modes/interactive/components/ask-user-question-state.js +63 -6
  149. package/dist/modes/interactive/components/ask-user-question-state.js.map +1 -1
  150. package/dist/modes/interactive/components/ask-user-question.d.ts +2 -0
  151. package/dist/modes/interactive/components/ask-user-question.d.ts.map +1 -1
  152. package/dist/modes/interactive/components/ask-user-question.js +27 -14
  153. package/dist/modes/interactive/components/ask-user-question.js.map +1 -1
  154. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  155. package/dist/modes/interactive/components/footer.js +51 -19
  156. package/dist/modes/interactive/components/footer.js.map +1 -1
  157. package/dist/modes/interactive/components/login-dialog.d.ts +11 -0
  158. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  159. package/dist/modes/interactive/components/login-dialog.js +29 -9
  160. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  161. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  162. package/dist/modes/interactive/components/tree-selector.js +7 -0
  163. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  164. package/dist/modes/interactive/help-content.d.ts.map +1 -1
  165. package/dist/modes/interactive/help-content.js +4 -0
  166. package/dist/modes/interactive/help-content.js.map +1 -1
  167. package/dist/modes/interactive/interactive-mode.d.ts +13 -4
  168. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  169. package/dist/modes/interactive/interactive-mode.js +44 -15
  170. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  171. package/dist/modes/interactive/tips/catalog/input-tips.js +1 -1
  172. package/dist/modes/interactive/tips/catalog/input-tips.js.map +1 -1
  173. package/dist/modes/rpc/connection-handler.d.ts.map +1 -1
  174. package/dist/modes/rpc/connection-handler.js +3 -1
  175. package/dist/modes/rpc/connection-handler.js.map +1 -1
  176. package/dist/modes/rpc/connection-question-bridge.js +1 -1
  177. package/dist/modes/rpc/connection-question-bridge.js.map +1 -1
  178. package/dist/modes/rpc/host-ensure.d.ts.map +1 -1
  179. package/dist/modes/rpc/host-ensure.js +33 -11
  180. package/dist/modes/rpc/host-ensure.js.map +1 -1
  181. package/dist/modes/rpc/host-lifecycle.d.ts +14 -0
  182. package/dist/modes/rpc/host-lifecycle.d.ts.map +1 -1
  183. package/dist/modes/rpc/host-lifecycle.js +31 -5
  184. package/dist/modes/rpc/host-lifecycle.js.map +1 -1
  185. package/dist/modes/rpc/rpc-input-validation.d.ts.map +1 -1
  186. package/dist/modes/rpc/rpc-input-validation.js +2 -0
  187. package/dist/modes/rpc/rpc-input-validation.js.map +1 -1
  188. package/dist/modes/rpc/rpc-types.d.ts +2 -0
  189. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  190. package/dist/modes/rpc/rpc-types.js.map +1 -1
  191. package/dist/utils/changelog.d.ts +3 -1
  192. package/dist/utils/changelog.d.ts.map +1 -1
  193. package/dist/utils/changelog.js +89 -23
  194. package/dist/utils/changelog.js.map +1 -1
  195. package/dist/utils/paths.d.ts +5 -0
  196. package/dist/utils/paths.d.ts.map +1 -1
  197. package/dist/utils/paths.js +14 -1
  198. package/dist/utils/paths.js.map +1 -1
  199. package/docs/app-server.md +6 -0
  200. package/docs/extensions.md +19 -3
  201. package/docs/rpc.md +10 -0
  202. package/docs/settings.md +2 -1
  203. package/docs/tui.md +1 -1
  204. package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +28 -0
  205. package/node_modules/@code-yeongyu/senpi-codemode/README.md +5 -4
  206. package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
  207. package/node_modules/@code-yeongyu/senpi-codemode/src/output/streaming-output-buffer.ts +58 -0
  208. package/node_modules/@code-yeongyu/senpi-codemode/src/output/streaming-output.ts +9 -64
  209. package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt-template.ts +1 -1
  210. package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  211. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/discovery.d.ts +17 -0
  212. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/discovery.d.ts.map +1 -0
  213. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/discovery.js +90 -0
  214. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/discovery.js.map +1 -0
  215. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/frames.d.ts +23 -0
  216. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/frames.d.ts.map +1 -0
  217. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/frames.js +71 -0
  218. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/frames.js.map +1 -0
  219. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/gen/cascade_pb.d.ts +873 -0
  220. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/gen/cascade_pb.d.ts.map +1 -0
  221. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/gen/cascade_pb.js +303 -0
  222. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/gen/cascade_pb.js.map +1 -0
  223. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/metadata.d.ts +12 -0
  224. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/metadata.d.ts.map +1 -0
  225. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/metadata.js +35 -0
  226. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/metadata.js.map +1 -0
  227. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/paths.d.ts +23 -0
  228. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/paths.d.ts.map +1 -0
  229. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/paths.js +23 -0
  230. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/paths.js.map +1 -0
  231. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/request.d.ts +24 -0
  232. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/request.d.ts.map +1 -0
  233. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/request.js +116 -0
  234. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/request.js.map +1 -0
  235. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/stream-state.d.ts +20 -0
  236. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/stream-state.d.ts.map +1 -0
  237. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/stream-state.js +153 -0
  238. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/stream-state.js.map +1 -0
  239. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/types.d.ts +12 -0
  240. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/types.d.ts.map +1 -0
  241. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/types.js +3 -0
  242. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/types.js.map +1 -0
  243. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/wire.d.ts +6 -0
  244. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/wire.d.ts.map +1 -0
  245. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/wire.js +6 -0
  246. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/wire.js.map +1 -0
  247. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.d.ts +14 -0
  248. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.d.ts.map +1 -0
  249. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.js +162 -0
  250. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.js.map +1 -0
  251. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.lazy.d.ts +5 -0
  252. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.lazy.d.ts.map +1 -0
  253. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.lazy.js +23 -0
  254. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.lazy.js.map +1 -0
  255. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-callback.d.ts +25 -0
  256. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-callback.d.ts.map +1 -0
  257. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-callback.js +124 -0
  258. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-callback.js.map +1 -0
  259. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-token.d.ts +18 -0
  260. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-token.d.ts.map +1 -0
  261. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-token.js +101 -0
  262. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-token.js.map +1 -0
  263. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin.d.ts +14 -0
  264. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin.d.ts.map +1 -0
  265. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin.js +111 -0
  266. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin.js.map +1 -0
  267. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.d.ts.map +1 -1
  268. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.js +5 -1
  269. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.js.map +1 -1
  270. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-identity.d.ts +24 -0
  271. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-identity.d.ts.map +1 -0
  272. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-identity.js +86 -0
  273. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-identity.js.map +1 -0
  274. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.d.ts +2 -0
  275. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.d.ts.map +1 -1
  276. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.js +5 -0
  277. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.js.map +1 -1
  278. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts +51 -4
  279. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts.map +1 -1
  280. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js +196 -7
  281. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js.map +1 -1
  282. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts +8 -0
  283. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts.map +1 -1
  284. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js +10 -0
  285. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js.map +1 -1
  286. package/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts +9 -1
  287. package/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts.map +1 -1
  288. package/node_modules/@earendil-works/pi-ai/dist/auth/types.js.map +1 -1
  289. package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.d.ts.map +1 -1
  290. package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.js +2 -0
  291. package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.js.map +1 -1
  292. package/node_modules/@earendil-works/pi-ai/dist/compat.d.ts +1 -0
  293. package/node_modules/@earendil-works/pi-ai/dist/compat.d.ts.map +1 -1
  294. package/node_modules/@earendil-works/pi-ai/dist/compat.js +3 -0
  295. package/node_modules/@earendil-works/pi-ai/dist/compat.js.map +1 -1
  296. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +4 -4
  297. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js.map +1 -1
  298. package/node_modules/@earendil-works/pi-ai/dist/models.d.ts +1 -1
  299. package/node_modules/@earendil-works/pi-ai/dist/models.d.ts.map +1 -1
  300. package/node_modules/@earendil-works/pi-ai/dist/models.js +14 -5
  301. package/node_modules/@earendil-works/pi-ai/dist/models.js.map +1 -1
  302. package/node_modules/@earendil-works/pi-ai/dist/providers/all.d.ts.map +1 -1
  303. package/node_modules/@earendil-works/pi-ai/dist/providers/all.js +2 -0
  304. package/node_modules/@earendil-works/pi-ai/dist/providers/all.js.map +1 -1
  305. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  306. package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  307. package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
  308. package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
  309. package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
  310. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
  311. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opengateway.json +1 -1
  312. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  313. package/node_modules/@earendil-works/pi-ai/dist/providers/data/venice.json +1 -1
  314. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  315. package/node_modules/@earendil-works/pi-ai/dist/providers/devin.d.ts +12 -0
  316. package/node_modules/@earendil-works/pi-ai/dist/providers/devin.d.ts.map +1 -0
  317. package/node_modules/@earendil-works/pi-ai/dist/providers/devin.js +62 -0
  318. package/node_modules/@earendil-works/pi-ai/dist/providers/devin.js.map +1 -0
  319. package/node_modules/@earendil-works/pi-ai/dist/providers/devin.models.d.ts +10 -0
  320. package/node_modules/@earendil-works/pi-ai/dist/providers/devin.models.d.ts.map +1 -0
  321. package/node_modules/@earendil-works/pi-ai/dist/providers/devin.models.js +28 -0
  322. package/node_modules/@earendil-works/pi-ai/dist/providers/devin.models.js.map +1 -0
  323. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +3 -1
  324. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
  325. package/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
  326. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
  327. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +4 -0
  328. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
  329. package/node_modules/@earendil-works/pi-ai/package.json +2 -2
  330. package/node_modules/@earendil-works/pi-pty/package.json +1 -1
  331. package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  332. package/node_modules/@earendil-works/pi-tui/dist/dollar-invocation-autocomplete.d.ts +1 -1
  333. package/node_modules/@earendil-works/pi-tui/dist/dollar-invocation-autocomplete.d.ts.map +1 -1
  334. package/node_modules/@earendil-works/pi-tui/dist/dollar-invocation-autocomplete.js +55 -16
  335. package/node_modules/@earendil-works/pi-tui/dist/dollar-invocation-autocomplete.js.map +1 -1
  336. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  337. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"file":"slots.js","sourceRoot":"","sources":["../../../src/auth/pool/slots.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAkB3C,MAAM,iBAAiB,GAAG,kCAAkC,CAAC;AAE7D,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC/C,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CACd,yBAAyB,IAAI,qEAAqE,CAClG,CAAC;IACH,CAAC;AACF,CAAC;AAED,SAAS,WAAW,CAAC,UAA4B;IAChD,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;AACtE,CAAC;AAED,SAAS,sBAAsB,CAAC,UAA4B;IAC3D,IAAI,UAAU,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QACjC,OAAO;YACN,IAAI,EAAE,iBAAiB;YACvB,MAAM,EAAE,OAAO;YACf,MAAM,EAAE,UAAU,CAAC,MAAM;YACzB,OAAO,EAAE,UAAU,CAAC,OAAO;YAC3B,OAA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,MAAM,EAAE,SAAS,CAAC,MAAM;QACxB,OAAO,EAAE,SAAS,CAAC,OAAO;QAC1B,OAAO,EAAE,SAAS,CAAC,OAAO;KAC1B,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM;QACtB,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACpF,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IACpB,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["import type { Credential } from \"../types.ts\";\n\nexport type { Credential };\n\nexport const DEFAULT_SLOT_NAME = \"default\";\n\nexport type CredentialSlotSource = \"login\" | \"import\" | \"env\";\n\nexport type CredentialSlot = {\n\tname: string;\n\tsource?: CredentialSlotSource;\n\tkey?: string;\n\taccess?: string;\n\trefresh?: string;\n\texpires?: number;\n};\n\nexport type PooledCredential = Credential & {\n\taccounts?: CredentialSlot[];\n\tpinned?: string;\n};\n\nconst SLOT_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/;\n\nexport function assertValidSlotName(name: string): void {\n\tif (!SLOT_NAME_PATTERN.test(name)) {\n\t\tthrow new Error(\n\t\t\t`Invalid account name '${name}': use letters, digits, '-' or '_', starting with a letter or digit`,\n\t\t);\n\t}\n}\n\nfunction storedSlots(credential: PooledCredential): CredentialSlot[] {\n\treturn Array.isArray(credential.accounts) ? credential.accounts : [];\n}\n\nfunction slotFromFlatCredential(credential: PooledCredential): CredentialSlot {\n\tif (credential.type === \"oauth\") {\n\t\treturn {\n\t\t\tname: DEFAULT_SLOT_NAME,\n\t\t\tsource: \"login\",\n\t\t\taccess: credential.access,\n\t\t\trefresh: credential.refresh,\n\t\t\texpires: credential.expires,\n\t\t};\n\t}\n\treturn { name: DEFAULT_SLOT_NAME, source: \"login\", key: credential.key };\n}\n\n/**\n * A flat credential written by a build predating pools is read as a one-slot pool\n * without writing anything back; the caller decides whether a write ever happens.\n */\nexport function listSlots(credential: PooledCredential | undefined): CredentialSlot[] {\n\tif (!credential) return [];\n\tconst slots = storedSlots(credential);\n\treturn slots.length > 0 ? [...slots] : [slotFromFlatCredential(credential)];\n}\n\nexport function findSlot(credential: PooledCredential | undefined, name: string): CredentialSlot | undefined {\n\treturn listSlots(credential).find((slot) => slot.name === name);\n}\n\n/**\n * Replaces or appends one slot while every sibling, the pin, and the flat\n * top-level credential survive untouched. The flat fields stay as written so a\n * build that ignores `accounts` still authenticates from them.\n */\nexport function upsertSlot(credential: PooledCredential | undefined, slot: CredentialSlot): PooledCredential {\n\tassertValidSlotName(slot.name);\n\tconst base: PooledCredential =\n\t\tcredential ??\n\t\t(slot.access !== undefined || slot.refresh !== undefined\n\t\t\t? { type: \"oauth\", access: slot.access ?? \"\", refresh: slot.refresh ?? \"\", expires: slot.expires ?? 0 }\n\t\t\t: { type: \"api_key\", key: slot.key });\n\tconst existing = listSlots(base);\n\tconst index = existing.findIndex((candidate) => candidate.name === slot.name);\n\tconst accounts =\n\t\tindex >= 0\n\t\t\t? existing.map((candidate) => (candidate.name === slot.name ? { ...candidate, ...slot } : candidate))\n\t\t\t: [...existing, slot];\n\treturn { ...base, accounts };\n}\n\n/** Whether the flat top-level fields are this slot's material rather than a sibling's. */\nfunction slotMirrorsFlat(credential: PooledCredential, slot: CredentialSlot): boolean {\n\tif (credential.type === \"oauth\") return slot.access === credential.access || slot.refresh === credential.refresh;\n\treturn slot.key === credential.key;\n}\n\n/** Rewrites the flat top-level projection to carry the given slot's material. */\nfunction projectFlatFields(credential: PooledCredential, slot: CredentialSlot): PooledCredential {\n\tif (credential.type === \"oauth\") {\n\t\tif (slot.access === undefined || slot.refresh === undefined || slot.expires === undefined) return credential;\n\t\treturn { ...credential, access: slot.access, refresh: slot.refresh, expires: slot.expires };\n\t}\n\treturn { ...credential, key: slot.key };\n}\n\n/**\n * Removes one slot. The credential is dropped entirely once its last slot is gone,\n * and a pin naming the removed slot is cleared so selection never points at a slot\n * that no longer exists.\n *\n * When the removed slot was the one the flat top-level fields projected, those\n * fields are re-projected from the first survivor. Without that the pool keeps\n * authenticating with the deleted account's material: a credential with a single\n * remaining slot does not enter the rotation path, so ordinary requests resolve\n * the flat projection and would keep using exactly the account the user removed.\n * `accounts` is preserved either way, so the entry stays a pool.\n */\nexport function removeSlot(credential: PooledCredential | undefined, name: string): PooledCredential | undefined {\n\tif (!credential) return undefined;\n\tconst existing = listSlots(credential);\n\tconst removed = existing.find((slot) => slot.name === name);\n\tconst accounts = existing.filter((slot) => slot.name !== name);\n\tif (accounts.length === 0) return undefined;\n\tconst reprojected =\n\t\tremoved && slotMirrorsFlat(credential, removed) ? projectFlatFields(credential, accounts[0]) : credential;\n\tconst next: PooledCredential = { ...reprojected, accounts };\n\tif (next.pinned === name) delete next.pinned;\n\treturn next;\n}\n\nexport function pinSlot(credential: PooledCredential, name: string): PooledCredential {\n\tassertValidSlotName(name);\n\treturn { ...credential, pinned: name };\n}\n\n/**\n * Projects one named slot onto the flat credential shape for request-scoped\n * resolution; pool bookkeeping fields are stripped so provider handlers see a\n * plain credential and never write pool state back through the projection.\n */\nexport function projectSlot(credential: PooledCredential | undefined, name: string): Credential | undefined {\n\tif (!credential) return undefined;\n\tconst slot = findSlot(credential, name);\n\tif (!slot) return undefined;\n\tconst { accounts: _accounts, pinned: _pinned, ...flat } = credential;\n\tif (flat.type === \"oauth\") {\n\t\tif (slot.access === undefined || slot.refresh === undefined || slot.expires === undefined) return undefined;\n\t\treturn { ...flat, access: slot.access, refresh: slot.refresh, expires: slot.expires };\n\t}\n\treturn { ...flat, key: slot.key };\n}\n\nfunction slotFromFlatCredentialNamed(credential: Credential, name: string): CredentialSlot {\n\tif (credential.type === \"oauth\") {\n\t\treturn {\n\t\t\tname,\n\t\t\tsource: \"login\",\n\t\t\taccess: credential.access,\n\t\t\trefresh: credential.refresh,\n\t\t\texpires: credential.expires,\n\t\t};\n\t}\n\treturn { name, source: \"login\", key: credential.key };\n}\n\nfunction nextLoginSlotName(credential: PooledCredential): string {\n\tconst taken = new Set(listSlots(credential).map((slot) => slot.name));\n\tfor (let index = 2; index < 1000; index++) {\n\t\tconst candidate = `login-${index}`;\n\t\tif (!taken.has(candidate)) return candidate;\n\t}\n\tthrow new Error(\"Credential pool is full\");\n}\n\n/**\n * Appends an unnamed flat credential to a pool as a generated `login-N` slot.\n * An absent current entry keeps today's whole-write shape; a flat current entry\n * is promoted to a pool so the legacy credential stays reachable as `default`\n * instead of being overwritten by the second login.\n *\n * A login result that already carries its own populated `accounts` array is a\n * provider-owned pool: it IS the complete post-login credential, so it is\n * written through untouched. Reading its top-level fields as a flat credential\n * would append the provider's placeholder material as a second slot.\n */\nexport function appendLoginSlot(current: PooledCredential | undefined, flat: Credential): Credential {\n\tif (\"accounts\" in flat && Array.isArray(flat.accounts) && flat.accounts.length > 0) {\n\t\treturn flat;\n\t}\n\tif (!current) {\n\t\treturn flat;\n\t}\n\treturn upsertSlot(current, slotFromFlatCredentialNamed(flat, nextLoginSlotName(current)));\n}\n\n/**\n * Merges a rotated OAuth credential back into the pool: the slot whose material\n * matches the pre-refresh flat fields is updated in place together with those\n * flat fields, while every sibling and the pin survive byte-identical. A flat\n * current entry keeps today's whole-write shape.\n */\n/**\n * Merges a rotated OAuth credential into the NAMED slot. The flat top-level\n * projection rotates only when it mirrored that slot's previous material, so\n * refreshing a secondary slot never disturbs what an older binary reads.\n */\nexport function mergeRefreshedSlot(current: PooledCredential, name: string, refreshed: Credential): Credential {\n\tif (refreshed.type !== \"oauth\" || current.type !== \"oauth\") return current;\n\tif (!Array.isArray(current.accounts) || current.accounts.length === 0) return mergeRefreshed(current, refreshed);\n\tconst target = current.accounts.find((slot) => slot.name === name);\n\tif (!target) return current;\n\tconst rotated = { access: refreshed.access, refresh: refreshed.refresh, expires: refreshed.expires };\n\tconst accounts = current.accounts.map((slot) => (slot === target ? { ...slot, ...rotated } : slot));\n\tconst mirrorsFlat = target.access === current.access || target.refresh === current.refresh;\n\treturn mirrorsFlat ? { ...current, ...rotated, accounts } : { ...current, accounts };\n}\n\nexport function mergeRefreshed(current: PooledCredential, refreshed: Credential): Credential {\n\tif (!Array.isArray(current.accounts) || current.accounts.length === 0) {\n\t\treturn refreshed;\n\t}\n\tif (refreshed.type !== \"oauth\" || current.type !== \"oauth\") return refreshed;\n\tconst target = current.accounts.find((slot) => slot.access === current.access || slot.refresh === current.refresh);\n\tconst rotated = {\n\t\taccess: refreshed.access,\n\t\trefresh: refreshed.refresh,\n\t\texpires: refreshed.expires,\n\t};\n\tconst accounts = target\n\t\t? current.accounts.map((slot) => (slot === target ? { ...slot, ...rotated } : slot))\n\t\t: current.accounts;\n\treturn { ...current, ...rotated, accounts };\n}\n"]}
1
+ {"version":3,"file":"slots.js","sourceRoot":"","sources":["../../../src/auth/pool/slots.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAqB3C,MAAM,iBAAiB,GAAG,kCAAkC,CAAC;AAE7D,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC/C,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CACd,yBAAyB,IAAI,qEAAqE,CAClG,CAAC;IACH,CAAC;AACF,CAAC;AAED,MAAM,yBAAyB,GAAG,6BAA6B,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAE3C,gFAAgF;AAChF,MAAM,uBAAuB,GAAG,wDAAwD,CAAC;AACzF,qFAAqF;AACrF,MAAM,2BAA2B,GAAG,sDAAsD,CAAC;AAC3F,MAAM,sBAAsB,GAC3B,4OAA4O,CAAC;AAE9O;;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,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,SAAS,CAAC;IAC7E,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACnH,MAAM,OAAO,GAAG;QACf,MAAM,EAAE,SAAS,CAAC,MAAM;QACxB,OAAO,EAAE,SAAS,CAAC,OAAO;QAC1B,OAAO,EAAE,SAAS,CAAC,OAAO;KAC1B,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM;QACtB,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACpF,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IACpB,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["import type { Credential } from \"../types.ts\";\n\nexport type { Credential };\n\nexport const DEFAULT_SLOT_NAME = \"default\";\n\nexport type CredentialSlotSource = \"login\" | \"import\" | \"env\";\n\nexport type CredentialSlot = {\n\t/** Immutable operational identity. */\n\tname: string;\n\t/** Optional presentation metadata; never used for credential selection. */\n\tdisplayName?: string;\n\tsource?: CredentialSlotSource;\n\tkey?: string;\n\taccess?: string;\n\trefresh?: string;\n\texpires?: number;\n};\n\nexport type PooledCredential = Credential & {\n\taccounts?: CredentialSlot[];\n\tpinned?: string;\n};\n\nconst SLOT_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/;\n\nexport function assertValidSlotName(name: string): void {\n\tif (!SLOT_NAME_PATTERN.test(name)) {\n\t\tthrow new Error(\n\t\t\t`Invalid account name '${name}': use letters, digits, '-' or '_', starting with a letter or digit`,\n\t\t);\n\t}\n}\n\nconst UNSAFE_DISPLAY_CHARACTERS = /[\\p{Cc}\\p{Cf}\\p{Zl}\\p{Zp}]/u;\n\n/**\n * Labels are bounded in terminal columns, not UTF-16 code units: 80 code units\n * of CJK render ~170 columns, which no footer segment can hold, while 41 emoji\n * render 82 columns yet count 82 code units. The bound is what the footer's\n * parenthesised provider segment can carry alongside a provider id.\n */\nexport const DISPLAY_NAME_MAX_COLUMNS = 32;\n\n/** Code points that advance a cell without painting anything a user can see. */\nconst BLANK_DISPLAY_CHARACTER = /^[\\s\\p{M}\\u115f\\u1160\\u17b4\\u17b5\\u2800\\u3164\\uffa0]$/u;\n/** Invisible code points that are not whitespace, so trimming never removes them. */\nconst INVISIBLE_DISPLAY_CHARACTER = /^[\\p{M}\\u115f\\u1160\\u17b4\\u17b5\\u2800\\u3164\\uffa0]$/u;\nconst WIDE_DISPLAY_CHARACTER =\n\t/^(?:[\\u1100-\\u115f\\u2329\\u232a\\u2e80-\\u303e\\u3041-\\u33ff\\u3400-\\u4dbf\\u4e00-\\u9fff\\ua000-\\ua4cf\\ua960-\\ua97f\\uac00-\\ud7a3\\uf900-\\ufaff\\ufe10-\\ufe19\\ufe30-\\ufe6f\\uff00-\\uff60\\uffe0-\\uffe6]|[\\u{1f300}-\\u{1faff}]|[\\u{20000}-\\u{3fffd}])$/u;\n\n/**\n * Latin lookalikes for the Cyrillic letters a homoglyph label would use. Folded\n * only for the uniqueness comparison; the stored label keeps the user's script.\n */\nconst CYRILLIC_LOOKALIKES: Record<string, string> = {\n\t\"\\u0430\": \"a\",\n\t\"\\u0432\": \"b\",\n\t\"\\u0435\": \"e\",\n\t\"\\u043a\": \"k\",\n\t\"\\u043c\": \"m\",\n\t\"\\u043d\": \"h\",\n\t\"\\u043e\": \"o\",\n\t\"\\u0440\": \"p\",\n\t\"\\u0441\": \"c\",\n\t\"\\u0442\": \"t\",\n\t\"\\u0443\": \"y\",\n\t\"\\u0445\": \"x\",\n\t\"\\u0455\": \"s\",\n\t\"\\u0456\": \"i\",\n\t\"\\u0458\": \"j\",\n};\n\nconst displayNameGraphemes = new Intl.Segmenter(undefined, { granularity: \"grapheme\" });\n\n/** Terminal columns a label occupies, measured per grapheme cluster. */\nexport function displayNameColumns(value: string): number {\n\tlet columns = 0;\n\tfor (const { segment } of displayNameGraphemes.segment(value)) {\n\t\tconst codePoint = segment.codePointAt(0);\n\t\tif (codePoint === undefined) continue;\n\t\tconst base = String.fromCodePoint(codePoint);\n\t\tif (INVISIBLE_DISPLAY_CHARACTER.test(base)) continue;\n\t\tcolumns += WIDE_DISPLAY_CHARACTER.test(base) || segment.includes(\"\\ufe0f\") ? 2 : 1;\n\t}\n\treturn columns;\n}\n\n/** The stored form: NFC, trimmed, internal whitespace runs collapsed to one space. */\nfunction normalizeDisplayName(value: string): string {\n\treturn value.normalize(\"NFC\").trim().replace(/\\s+/gu, \" \");\n}\n\n/**\n * Comparison key for \"unique per provider\": compatibility-folded (fullwidth and\n * other compatibility forms), case-folded, invisible code points dropped, and\n * Cyrillic lookalikes mapped to Latin, so two labels that render identically\n * cannot both be stored.\n */\nfunction displayNameKey(value: string): string {\n\treturn [...normalizeDisplayName(value).normalize(\"NFKC\").toLowerCase()]\n\t\t.filter((character) => !INVISIBLE_DISPLAY_CHARACTER.test(character))\n\t\t.map((character) => CYRILLIC_LOOKALIKES[character] ?? character)\n\t\t.join(\"\");\n}\n\n/** Treat persisted metadata as untrusted presentation input. */\nexport function accountDisplayName(value: unknown): string | undefined {\n\tif (typeof value !== \"string\" || UNSAFE_DISPLAY_CHARACTERS.test(value)) return undefined;\n\tconst normalized = normalizeDisplayName(value);\n\tconst characters = [...normalized];\n\t// A leading combining mark glues the label onto whatever precedes it, and a\n\t// label made only of blank-rendering code points is indistinguishable from none.\n\tif (characters.length === 0 || /^\\p{M}$/u.test(characters[0])) return undefined;\n\tif (characters.every((character) => BLANK_DISPLAY_CHARACTER.test(character))) return undefined;\n\treturn displayNameColumns(normalized) <= DISPLAY_NAME_MAX_COLUMNS ? normalized : undefined;\n}\n\nexport function accountLabel(account: { name: string; displayName?: string }): string {\n\tconst displayName = accountDisplayName(account.displayName);\n\treturn displayName === undefined ? account.name : `${displayName} (${account.name})`;\n}\n\n/** Pure metadata update; callers serialize this against the latest stored credential. */\nexport function renameSlotDisplayName(\n\tcredential: PooledCredential,\n\tname: string,\n\tvalue: string | null,\n): PooledCredential {\n\tassertValidSlotName(name);\n\tconst accounts = Array.isArray(credential.accounts) ? credential.accounts : listSlots(credential);\n\tconst target = accounts.find((slot) => slot.name === name);\n\tif (!target) throw new Error(`Stored provider account not found: ${name}`);\n\tif (target.source === \"env\") throw new Error(`Environment provider account cannot be renamed: ${name}`);\n\tconst displayName = value === null ? undefined : accountDisplayName(value);\n\tif (value !== null && displayName === undefined) {\n\t\tthrow new Error(\n\t\t\t`Display name must be 1-${DISPLAY_NAME_MAX_COLUMNS} terminal columns of visible text without control or formatting characters.`,\n\t\t);\n\t}\n\tif (\n\t\tdisplayName !== undefined &&\n\t\taccounts.some(\n\t\t\t(slot) =>\n\t\t\t\tslot.name !== name &&\n\t\t\t\tdisplayNameKey(accountDisplayName(slot.displayName) ?? \"\") === displayNameKey(displayName),\n\t\t)\n\t) {\n\t\tthrow new Error(\"Display name is already used by another account for this provider.\");\n\t}\n\treturn {\n\t\t...credential,\n\t\taccounts: accounts.map((slot) => {\n\t\t\tif (slot.name !== name) return slot;\n\t\t\tconst { displayName: _displayName, ...unchanged } = slot;\n\t\t\treturn displayName === undefined ? unchanged : { ...unchanged, displayName };\n\t\t}),\n\t};\n}\n\nfunction storedSlots(credential: PooledCredential): CredentialSlot[] {\n\treturn Array.isArray(credential.accounts) ? credential.accounts : [];\n}\n\nfunction slotFromFlatCredential(credential: PooledCredential): CredentialSlot {\n\tif (credential.type === \"oauth\") {\n\t\treturn {\n\t\t\tname: DEFAULT_SLOT_NAME,\n\t\t\tsource: \"login\",\n\t\t\taccess: credential.access,\n\t\t\trefresh: credential.refresh,\n\t\t\texpires: credential.expires,\n\t\t};\n\t}\n\treturn { name: DEFAULT_SLOT_NAME, source: \"login\", key: credential.key };\n}\n\n/**\n * A flat credential written by a build predating pools is read as a one-slot pool\n * without writing anything back; the caller decides whether a write ever happens.\n */\nexport function listSlots(credential: PooledCredential | undefined): CredentialSlot[] {\n\tif (!credential) return [];\n\tconst slots = storedSlots(credential);\n\treturn slots.length > 0 ? [...slots] : [slotFromFlatCredential(credential)];\n}\n\nexport function findSlot(credential: PooledCredential | undefined, name: string): CredentialSlot | undefined {\n\treturn listSlots(credential).find((slot) => slot.name === name);\n}\n\n/**\n * Replaces or appends one slot while every sibling, the pin, and the flat\n * top-level credential survive untouched. The flat fields stay as written so a\n * build that ignores `accounts` still authenticates from them.\n */\nexport function upsertSlot(credential: PooledCredential | undefined, slot: CredentialSlot): PooledCredential {\n\tassertValidSlotName(slot.name);\n\tconst base: PooledCredential =\n\t\tcredential ??\n\t\t(slot.access !== undefined || slot.refresh !== undefined\n\t\t\t? { type: \"oauth\", access: slot.access ?? \"\", refresh: slot.refresh ?? \"\", expires: slot.expires ?? 0 }\n\t\t\t: { type: \"api_key\", key: slot.key });\n\tconst existing = listSlots(base);\n\tconst index = existing.findIndex((candidate) => candidate.name === slot.name);\n\tconst accounts =\n\t\tindex >= 0\n\t\t\t? existing.map((candidate) => (candidate.name === slot.name ? { ...candidate, ...slot } : candidate))\n\t\t\t: [...existing, slot];\n\treturn { ...base, accounts };\n}\n\n/** Whether the flat top-level fields are this slot's material rather than a sibling's. */\nfunction slotMirrorsFlat(credential: PooledCredential, slot: CredentialSlot): boolean {\n\tif (credential.type === \"oauth\") return slot.access === credential.access || slot.refresh === credential.refresh;\n\treturn slot.key === credential.key;\n}\n\n/** Rewrites the flat top-level projection to carry the given slot's material. */\nfunction projectFlatFields(credential: PooledCredential, slot: CredentialSlot): PooledCredential {\n\tif (credential.type === \"oauth\") {\n\t\tif (slot.access === undefined || slot.refresh === undefined || slot.expires === undefined) return credential;\n\t\treturn { ...credential, access: slot.access, refresh: slot.refresh, expires: slot.expires };\n\t}\n\treturn { ...credential, key: slot.key };\n}\n\n/**\n * Removes one slot. The credential is dropped entirely once its last slot is gone,\n * and a pin naming the removed slot is cleared so selection never points at a slot\n * that no longer exists.\n *\n * When the removed slot was the one the flat top-level fields projected, those\n * fields are re-projected from the first survivor. Without that the pool keeps\n * authenticating with the deleted account's material: a credential with a single\n * remaining slot does not enter the rotation path, so ordinary requests resolve\n * the flat projection and would keep using exactly the account the user removed.\n * `accounts` is preserved either way, so the entry stays a pool.\n */\nexport function removeSlot(credential: PooledCredential | undefined, name: string): PooledCredential | undefined {\n\tif (!credential) return undefined;\n\tconst existing = listSlots(credential);\n\tconst removed = existing.find((slot) => slot.name === name);\n\tconst accounts = existing.filter((slot) => slot.name !== name);\n\tif (accounts.length === 0) return undefined;\n\tconst reprojected =\n\t\tremoved && slotMirrorsFlat(credential, removed) ? projectFlatFields(credential, accounts[0]) : credential;\n\tconst next: PooledCredential = { ...reprojected, accounts };\n\tif (next.pinned === name) delete next.pinned;\n\treturn next;\n}\n\nexport function pinSlot(credential: PooledCredential, name: string): PooledCredential {\n\tassertValidSlotName(name);\n\treturn { ...credential, pinned: name };\n}\n\n/**\n * Projects one named slot onto the flat credential shape for request-scoped\n * resolution; pool bookkeeping fields are stripped so provider handlers see a\n * plain credential and never write pool state back through the projection.\n */\nexport function projectSlot(credential: PooledCredential | undefined, name: string): Credential | undefined {\n\tif (!credential) return undefined;\n\tconst slot = findSlot(credential, name);\n\tif (!slot) return undefined;\n\tconst { accounts: _accounts, pinned: _pinned, ...flat } = credential;\n\tif (flat.type === \"oauth\") {\n\t\tif (slot.access === undefined || slot.refresh === undefined || slot.expires === undefined) return undefined;\n\t\treturn { ...flat, access: slot.access, refresh: slot.refresh, expires: slot.expires };\n\t}\n\treturn { ...flat, key: slot.key };\n}\n\nfunction slotFromFlatCredentialNamed(credential: Credential, name: string): CredentialSlot {\n\tif (credential.type === \"oauth\") {\n\t\treturn {\n\t\t\tname,\n\t\t\tsource: \"login\",\n\t\t\taccess: credential.access,\n\t\t\trefresh: credential.refresh,\n\t\t\texpires: credential.expires,\n\t\t};\n\t}\n\treturn { name, source: \"login\", key: credential.key };\n}\n\nfunction nextLoginSlotName(credential: PooledCredential): string {\n\tconst taken = new Set(listSlots(credential).map((slot) => slot.name));\n\tfor (let index = 2; index < 1000; index++) {\n\t\tconst candidate = `login-${index}`;\n\t\tif (!taken.has(candidate)) return candidate;\n\t}\n\tthrow new Error(\"Credential pool is full\");\n}\n\nfunction providedSlots(credential: Credential): CredentialSlot[] | undefined {\n\tconst accounts = (credential as PooledCredential).accounts;\n\treturn Array.isArray(accounts) && accounts.length > 0 ? accounts : undefined;\n}\n\n/**\n * Unions a provider-owned pool onto the value read under the credential lock.\n * `current` wins for every name it already holds: the provider built its\n * object from a snapshot taken BEFORE the interactive browser round trip, so a\n * sibling account that rotated its refresh token or earned a rate-limit block\n * during that window must not be rewound to the snapshot. Only names that do\n * not exist yet are appended.\n */\nfunction mergeProvidedPool(\n\tcurrent: PooledCredential,\n\texisting: readonly CredentialSlot[],\n\tprovided: readonly CredentialSlot[],\n): PooledCredential {\n\tconst known = new Set(existing.map((slot) => slot.name));\n\tconst added = provided.filter((slot) => !known.has(slot.name));\n\treturn added.length === 0 ? current : { ...current, accounts: [...existing, ...added] };\n}\n\n/**\n * Appends an unnamed flat credential to a pool as a generated `login-N` slot.\n * An absent current entry keeps today's whole-write shape; a flat current entry\n * is promoted to a pool so the legacy credential stays reachable as `default`\n * instead of being overwritten by the second login.\n *\n * A login result that already carries its own populated `accounts` array is a\n * provider-owned pool, and a provider that already holds a POOL names the\n * account this login created itself. That pool is MERGED onto `current` rather\n * than written through: a pre-browser-flow snapshot must never overwrite what\n * concurrent writers stored meanwhile. A flat `current` keeps the whole-write\n * shape - the provider echoes the flat fields it read, so there is nothing to\n * preserve and the login must not be dropped on a name collision.\n *\n * `onAllocated` reports the account this login committed, so a caller can name\n * it in a receipt without re-reading storage.\n */\nexport function appendLoginSlot(\n\tcurrent: PooledCredential | undefined,\n\tflat: Credential,\n\tonAllocated?: (name: string, origin: \"generated\" | \"provider\") => void,\n): Credential {\n\tconst provided = providedSlots(flat);\n\tif (provided) {\n\t\t// Provider-owned envelopes identify an addition by immutable ID, never by\n\t\t// token equality or array position. Ambiguous envelopes have no receipt.\n\t\tconst previous = new Set(\n\t\t\t(current && Array.isArray(current.accounts) ? current.accounts : listSlots(current)).map((slot) => slot.name),\n\t\t);\n\t\tconst added = provided.filter((slot) => !previous.has(slot.name));\n\t\tif (added.length === 1 && SLOT_NAME_PATTERN.test(added[0].name) && added[0].source !== \"env\") {\n\t\t\tonAllocated?.(added[0].name, \"provider\");\n\t\t}\n\t}\n\tif (!current) {\n\t\tif (!provided) onAllocated?.(DEFAULT_SLOT_NAME, \"generated\");\n\t\treturn flat;\n\t}\n\tconst storedAccounts = Array.isArray(current.accounts) ? current.accounts : undefined;\n\tif (provided) {\n\t\t// A pool merges onto the stored pool; a flat current keeps the whole-write\n\t\t// shape because the provider's accounts already carry this login.\n\t\treturn storedAccounts ? mergeProvidedPool(current, storedAccounts, provided) : flat;\n\t}\n\tconst name = nextLoginSlotName(current);\n\tconst next = upsertSlot(current, slotFromFlatCredentialNamed(flat, name));\n\tonAllocated?.(name, \"generated\");\n\treturn next;\n}\n\n/**\n * Material a provider writes into the flat credential when the real token lives\n * outside auth.json (an SDK subprocess or a vendor CLI owns it): the literal\n * `<providerId>-managed` in both OAuth fields. It is a marker, never a token.\n */\nexport function managedSentinelMaterial(providerId: string): string {\n\treturn `${providerId}-managed`;\n}\n\n/**\n * A POOL SLOT carrying that marker can never authenticate: `projectSlot` hands\n * it to the provider's `check`, which rejects it, and the request dies with\n * \"Provider is not configured\". Slots like that exist only because a shipped\n * build appended a provider-owned pool's flat sentinel as a generated `login-N`\n * slot.\n */\nexport function isManagedSentinelSlot(providerId: string, slot: CredentialSlot): boolean {\n\tconst sentinel = managedSentinelMaterial(providerId);\n\treturn slot.access === sentinel && slot.refresh === sentinel;\n}\n\n/**\n * Drops those poisoned slots from a stored credential, clearing a pin that\n * named one. Returns `undefined` when the credential holds none, so a caller\n * can tell a repair from a no-op and only rewrite storage when the bytes\n * actually change.\n */\nexport function repairManagedSentinelSlots(providerId: string, credential: Credential): PooledCredential | undefined {\n\tconst pooled = credential as PooledCredential;\n\tif (!Array.isArray(pooled.accounts)) return undefined;\n\tconst kept = pooled.accounts.filter((slot) => !isManagedSentinelSlot(providerId, slot));\n\tif (kept.length === pooled.accounts.length) return undefined;\n\tconst repaired: PooledCredential = { ...pooled, accounts: kept };\n\tif (repaired.pinned !== undefined && !kept.some((slot) => slot.name === repaired.pinned)) delete repaired.pinned;\n\treturn repaired;\n}\n\n/**\n * Merges a rotated OAuth credential back into the pool: the slot whose material\n * matches the pre-refresh flat fields is updated in place together with those\n * flat fields, while every sibling and the pin survive byte-identical. A flat\n * current entry keeps today's whole-write shape.\n */\n/**\n * Merges a rotated OAuth credential into the NAMED slot. The flat top-level\n * projection rotates only when it mirrored that slot's previous material, so\n * refreshing a secondary slot never disturbs what an older binary reads.\n */\nexport function mergeRefreshedSlot(current: PooledCredential, name: string, refreshed: Credential): Credential {\n\tif (refreshed.type !== \"oauth\" || current.type !== \"oauth\") return current;\n\tif (!Array.isArray(current.accounts) || current.accounts.length === 0) return mergeRefreshed(current, refreshed);\n\tconst target = current.accounts.find((slot) => slot.name === name);\n\tif (!target) return current;\n\tconst rotated = { access: refreshed.access, refresh: refreshed.refresh, expires: refreshed.expires };\n\tconst accounts = current.accounts.map((slot) => (slot === target ? { ...slot, ...rotated } : slot));\n\tconst mirrorsFlat = target.access === current.access || target.refresh === current.refresh;\n\treturn mirrorsFlat ? { ...current, ...rotated, accounts } : { ...current, accounts };\n}\n\nexport function mergeRefreshed(current: PooledCredential, refreshed: Credential): Credential {\n\tif (!Array.isArray(current.accounts) || current.accounts.length === 0) {\n\t\treturn refreshed;\n\t}\n\tif (refreshed.type !== \"oauth\" || current.type !== \"oauth\") return refreshed;\n\tconst target = current.accounts.find((slot) => slot.access === current.access || slot.refresh === current.refresh);\n\tconst rotated = {\n\t\taccess: refreshed.access,\n\t\trefresh: refreshed.refresh,\n\t\texpires: refreshed.expires,\n\t};\n\tconst accounts = target\n\t\t? current.accounts.map((slot) => (slot === target ? { ...slot, ...rotated } : slot))\n\t\t: current.accounts;\n\treturn { ...current, ...rotated, accounts };\n}\n"]}
@@ -14,6 +14,14 @@ export interface AuthResolutionOverrides {
14
14
  slotName?: string;
15
15
  signal?: AbortSignal;
16
16
  }
17
+ /**
18
+ * Prefix of the auth-miss every resolution site raises when a provider has no
19
+ * usable credential. Consumers key recovery decisions off this exact wording,
20
+ * so it is a shared constant instead of a literal repeated at each throw site:
21
+ * rewording one copy would silently disable the other's behavior.
22
+ */
23
+ export declare const PROVIDER_NOT_CONFIGURED_PREFIX = "Provider is not configured: ";
24
+ export declare function providerNotConfiguredMessage(providerId: string): string;
17
25
  export declare class ModelsError extends Error {
18
26
  readonly code: ModelsErrorCode;
19
27
  constructor(code: ModelsErrorCode, message: string, options?: {
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/auth/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAU/C,OAAO,KAAK,EAGX,WAAW,EACX,UAAU,EAEV,eAAe,EAGf,YAAY,EACZ,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,kBAAkB,GAAG,UAAU,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAE7G,MAAM,WAAW,uBAAuB;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,WAAW,CAAC;IAClB,kFAAkF;IAClF,kBAAkB,CAAC,E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C,EAAE,WAAW,CAAC;CACrB;AAED;;;;;GAKG;AACH,eAAO,MAAM,8BAA8B,iCAAiC,CAAC;AAE7E,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAEvE;AAED,qBAAa,WAAY,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAE/B,YAAY,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAIhF;CACD;AAUD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAClC,QAAQ,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,YAAY,CAAA;CAAE,EAC5C,WAAW,EAAE,eAAe,EAC5B,WAAW,EAAE,WAAW,EACxB,SAAS,CAAC,EAAE,uBAAuB,GACjC,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAMjC;AAoGD,mFAAmF;AACnF,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,WAAW,CAOvF"}
@@ -2,6 +2,16 @@ import { operationSignal, raceWithAbortSignal } from "../utils/abort.js";
2
2
  import { formatThrownValue } from "../utils/diagnostics.js";
3
3
  import { OAuthRefreshExchangeError, OAuthRefreshStoreError, projectOAuthSlot, refreshOAuthCredential, } from "./oauth-refresh.js";
4
4
  import { projectSlot } from "./pool/slots.js";
5
+ /**
6
+ * Prefix of the auth-miss every resolution site raises when a provider has no
7
+ * usable credential. Consumers key recovery decisions off this exact wording,
8
+ * so it is a shared constant instead of a literal repeated at each throw site:
9
+ * rewording one copy would silently disable the other's behavior.
10
+ */
11
+ export const PROVIDER_NOT_CONFIGURED_PREFIX = "Provider is not configured: ";
12
+ export function providerNotConfiguredMessage(providerId) {
13
+ return `${PROVIDER_NOT_CONFIGURED_PREFIX}${providerId}`;
14
+ }
5
15
  export class ModelsError extends Error {
6
16
  constructor(code, message, options) {
7
17
  super(withCauseDetail(message, options?.cause), options);
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/auth/resolve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EACN,yBAAyB,EACzB,sBAAsB,EACtB,gBAAgB,EAChB,sBAAsB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AA6B9C,MAAM,OAAO,WAAY,SAAQ,KAAK;IAGrC,YAAY,IAAqB,EAAE,OAAe,EAAE,OAA6B;QAChF,KAAK,CAAC,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;QACzD,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD;AAED,iFAAiF;AACjF,SAAS,eAAe,CAAC,OAAe,EAAE,KAAc;IACvD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,OAAO,CAAC;IAC1D,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/C,IAAI,CAAC,MAAM,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,OAAO,CAAC;IACxD,OAAO,GAAG,OAAO,KAAK,MAAM,EAAE,CAAC;AAChC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAClC,QAA4C,EAC5C,WAA4B,EAC5B,WAAwB,EACxB,SAAmC;IAEnC,MAAM,MAAM,GAAG,eAAe,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAClD,OAAO,mBAAmB,C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AM,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;IACvE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,WAAW,CAAC,MAAM,EAAE,oCAAoC,UAAU,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACnG,CAAC;AACF,CAAC;AAED,KAAK,UAAU,cAAc,CAC5B,WAA4B,EAC5B,UAAkB,EAClB,MAAmB;IAEnB,IAAI,CAAC;QACJ,OAAO,MAAM,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,WAAW,CAAC,MAAM,EAAE,oCAAoC,UAAU,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACnG,CAAC;AACF,CAAC","sourcesContent":["import type { ProviderEnv } from \"../types.ts\";\nimport { operationSignal, raceWithAbortSignal } from \"../utils/abort.ts\";\nimport { formatThrownValue } from \"../utils/diagnostics.ts\";\nimport {\n\tOAuthRefreshExchangeError,\n\tOAuthRefreshStoreError,\n\tprojectOAuthSlot,\n\trefreshOAuthCredential,\n} from \"./oauth-refresh.ts\";\nimport { projectSlot } from \"./pool/slots.ts\";\nimport type {\n\tApiKeyAuth,\n\tApiKeyCredential,\n\tAuthContext,\n\tAuthResult,\n\tCredential,\n\tCredentialStore,\n\tOAuthAuth,\n\tOAuthCredential,\n\tProviderAuth,\n} from \"./types.ts\";\n\nexport type ModelsErrorCode = \"model_source\" | \"model_validation\" | \"provider\" | \"stream\" | \"auth\" | \"oauth\";\n\nexport interface AuthResolutionOverrides {\n\tapiKey?: string;\n\tenv?: ProviderEnv;\n\t/** Require this much remaining OAuth-token validity; defaults to five minutes. */\n\tminOAuthValidityMs?: number;\n\t/**\n\t * Resolve against one named slot of a pooled credential. A missing entry or\n\t * slot resolves to undefined rather than falling back to another account or\n\t * ambient env, so a slot-scoped request can never silently switch identities.\n\t */\n\tslotName?: string;\n\tsignal?: AbortSignal;\n}\n\nexport class ModelsError extends Error {\n\treadonly code: ModelsErrorCode;\n\n\tconstructor(code: ModelsErrorCode, message: string, options?: { cause?: unknown }) {\n\t\tsuper(withCauseDetail(message, options?.cause), options);\n\t\tthis.name = \"ModelsError\";\n\t\tthis.code = code;\n\t}\n}\n\n/** Callers surface `error.message` only, so keep the underlying reason in it. */\nfunction withCauseDetail(message: string, cause: unknown): string {\n\tif (cause === undefined || cause === null) return message;\n\tconst detail = formatThrownValue(cause).trim();\n\tif (!detail || message.includes(detail)) return message;\n\treturn `${message}: ${detail}`;\n}\n\n/**\n * Auth resolution shared by the `Models` and `ImagesModels` collections.\n * A stored credential owns the provider: ambient/env is consulted only when\n * nothing is stored. No silent env fallback after a failed refresh or for a\n * credential type without a matching handler.\n */\nexport function resolveProviderAuth(\n\tprovider: { id: string; auth: ProviderAuth },\n\tcredentials: CredentialStore,\n\tauthContext: AuthContext,\n\toverrides?: AuthResolutionOverrides,\n): Promise<AuthResult | undefined> {\n\tconst signal = operationSignal(overrides?.signal);\n\treturn raceWithAbortSignal(\n\t\tresolveProviderAuthWithSignal(provider, credentials, authContext, overrides, signal),\n\t\tsignal,\n\t);\n}\n\nasync function resolveProviderAuthWithSignal(\n\tprovider: { id: string; auth: ProviderAuth },\n\tcredentials: CredentialStore,\n\tauthContext: AuthContext,\n\toverrides: AuthResolutionOverrides | undefined,\n\tsignal: AbortSignal,\n): Promise<AuthResult | undefined> {\n\tsignal.throwIfAborted();\n\tconst requestAuthContext = overrides?.env ? overlayEnvAuthContext(authContext, overrides.env) : authContext;\n\tconst apiKey = provider.auth.apiKey;\n\n\tif (overrides?.apiKey !== undefined && apiKey && !apiKey.ambientOnly) {\n\t\treturn resolveApiKey(\n\t\t\trequestAuthContext,\n\t\t\tapiKey,\n\t\t\tprovider.id,\n\t\t\t{\n\t\t\t\ttype: \"api_key\",\n\t\t\t\tkey: overrides.apiKey,\n\t\t\t\tenv: overrides.env,\n\t\t\t},\n\t\t\tsignal,\n\t\t);\n\t}\n\n\tconst stored = await readCredential(credentials, provider.id, signal);\n\tconst slotName = overrides?.slotName;\n\tif (slotName !== undefined) {\n\t\tconst projected = stored === undefined ? undefined : projectSlot(stored, slotName);\n\t\tif (!projected) return undefined;\n\t\tif (projected.type === \"oauth\" && provider.auth.oauth) {\n\t\t\treturn resolveStoredOAuth(\n\t\t\t\tcredentials,\n\t\t\t\tprovider.id,\n\t\t\t\tprovider.auth.oauth,\n\t\t\t\tprojected,\n\t\t\t\trequestAuthContext,\n\t\t\t\toverrides?.env,\n\t\t\t\tsignal,\n\t\t\t\toverrides?.minOAuthValidityMs,\n\t\t\t\tslotName,\n\t\t\t);\n\t\t}\n\t\tif (projected.type === \"api_key\" && provider.auth.apiKey) {\n\t\t\tconst credential = overrides?.env ? { ...projected, env: { ...projected.env, ...overrides.env } } : projected;\n\t\t\treturn resolveApiKey(requestAuthContext, provider.auth.apiKey, provider.id, credential, signal);\n\t\t}\n\t\treturn undefined;\n\t}\n\tif (stored) {\n\t\tif (stored.type === \"oauth\" && provider.auth.oauth) {\n\t\t\treturn resolveStoredOAuth(\n\t\t\t\tcredentials,\n\t\t\t\tprovider.id,\n\t\t\t\tprovider.auth.oauth,\n\t\t\t\tstored,\n\t\t\t\trequestAuthContext,\n\t\t\t\toverrides?.env,\n\t\t\t\tsignal,\n\t\t\t\toverrides?.minOAuthValidityMs,\n\t\t\t);\n\t\t}\n\t\tif (stored.type === \"api_key\" && provider.auth.apiKey) {\n\t\t\tconst credential = overrides?.env ? { ...stored, env: { ...stored.env, ...overrides.env } } : stored;\n\t\t\treturn resolveApiKey(requestAuthContext, provider.auth.apiKey, provider.id, credential, signal);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tif (overrides?.apiKey !== undefined && apiKey) {\n\t\treturn resolveApiKey(\n\t\t\trequestAuthContext,\n\t\t\tapiKey,\n\t\t\tprovider.id,\n\t\t\t{\n\t\t\t\ttype: \"api_key\",\n\t\t\t\tkey: overrides.apiKey,\n\t\t\t\tenv: overrides.env,\n\t\t\t},\n\t\t\tsignal,\n\t\t);\n\t}\n\n\t// Ambient (env vars, AWS profiles, ADC files).\n\tconst ambientCredential =\n\t\tapiKey?.ambientOnly && overrides?.env ? { type: \"api_key\" as const, key: \"\", env: overrides.env } : undefined;\n\treturn apiKey ? resolveApiKey(requestAuthContext, apiKey, provider.id, ambientCredential, signal) : undefined;\n}\n\nfunction overlayEnvAuthContext(base: AuthContext, env: ProviderEnv): AuthContext {\n\treturn {\n\t\tenv: async (name) => (env[name] !== undefined ? env[name] : await base.env(name)),\n\t\tfileExists: (path) => base.fileExists(path),\n\t};\n}\n\nconst DEFAULT_OAUTH_MINIMUM_VALIDITY_MS = 5 * 60 * 1000;\n\n/** Maps a shared-refresh failure onto the `ModelsError` codes callers match on. */\nexport function oauthRefreshModelsError(error: unknown, providerId: string): ModelsError {\n\tif (error instanceof ModelsError) return error;\n\tif (error instanceof OAuthRefreshExchangeError) {\n\t\treturn new ModelsError(\"oauth\", `OAuth refresh failed for ${providerId}`, { cause: error.cause });\n\t}\n\tconst cause = error instanceof OAuthRefreshStoreError ? error.cause : error;\n\treturn new ModelsError(\"auth\", `Credential store modify failed for ${providerId}`, { cause });\n}\n\n/**\n * OAuth resolution: a token with less than five minutes remaining is refreshed\n * through `refreshOAuthCredential`, which re-checks the stored value, runs the\n * exchange outside the store lock, and compare-and-swaps the rotated slot.\n */\nasync function resolveStoredOAuth(\n\tcredentials: CredentialStore,\n\tproviderId: string,\n\toauth: OAuthAuth,\n\tstored: OAuthCredential,\n\tauthContext: AuthContext,\n\trequestEnv: ProviderEnv | undefined,\n\tsignal: AbortSignal,\n\tminOAuthValidityMs?: number,\n\tslotName?: string,\n): Promise<AuthResult | undefined> {\n\tconst minimumValidityMs = Math.max(DEFAULT_OAUTH_MINIMUM_VALIDITY_MS, minOAuthValidityMs ?? 0);\n\tconst expiresSoon = (credential: OAuthCredential) => Date.now() + minimumValidityMs >= credential.expires;\n\tlet credential = stored;\n\n\tif (expiresSoon(credential)) {\n\t\tlet post: Credential | undefined;\n\t\ttry {\n\t\t\tpost = await refreshOAuthCredential({\n\t\t\t\tcredentials,\n\t\t\t\tproviderId,\n\t\t\t\toauth,\n\t\t\t\tstale: credential,\n\t\t\t\tslotName,\n\t\t\t\tisStale: expiresSoon,\n\t\t\t\tsignal,\n\t\t\t\towning: true,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthrow oauthRefreshModelsError(error, providerId);\n\t\t}\n\t\tif (post?.type !== \"oauth\") return undefined; // logged out meanwhile\n\t\tconst postView = slotName === undefined ? post : projectOAuthSlot(post, slotName);\n\t\tif (!postView) return undefined; // slot removed meanwhile\n\t\tcredential = postView;\n\t\t// The normal five-minute window triggers a refresh but does not impose a\n\t\t// provider contract. Explicit callers (such as bearer-token export) do\n\t\t// require the requested minimum after the refresh.\n\t\tif (minOAuthValidityMs !== undefined && expiresSoon(credential)) {\n\t\t\tthrow new ModelsError(\"oauth\", `OAuth refresh returned a token that expires too soon for ${providerId}`);\n\t\t}\n\t}\n\n\tconst storedEnv = credentialEnvironment(credential);\n\tconst effectiveEnv = requestEnv ? { ...storedEnv, ...requestEnv } : storedEnv;\n\tconst effectiveCredential = effectiveEnv ? { ...credential, env: effectiveEnv } : credential;\n\n\tif (oauth.check) {\n\t\ttry {\n\t\t\tif (!(await oauth.check({ ctx: authContext, credential: effectiveCredential, signal }))) return undefined;\n\t\t} catch (error) {\n\t\t\tthrow new ModelsError(\"auth\", `OAuth auth check failed for provider ${providerId}`, { cause: error });\n\t\t}\n\t}\n\n\ttry {\n\t\treturn {\n\t\t\tauth: await oauth.toAuth(effectiveCredential),\n\t\t\t...(effectiveEnv ? { env: effectiveEnv } : {}),\n\t\t\tsource: \"OAuth\",\n\t\t};\n\t} catch (error) {\n\t\tthrow new ModelsError(\"oauth\", `OAuth auth derivation failed for ${providerId}`, { cause: error });\n\t}\n}\n\nfunction credentialEnvironment(credential: OAuthCredential): ProviderEnv | undefined {\n\tconst value = credential.env;\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) return undefined;\n\tconst environment: ProviderEnv = {};\n\tfor (const [name, entry] of Object.entries(value)) {\n\t\tif (typeof entry !== \"string\") return undefined;\n\t\tenvironment[name] = entry;\n\t}\n\treturn environment;\n}\n\nasync function resolveApiKey(\n\tauthContext: AuthContext,\n\tapiKey: ApiKeyAuth,\n\tproviderId: string,\n\tcredential: ApiKeyCredential | undefined,\n\tsignal: AbortSignal,\n): Promise<AuthResult | undefined> {\n\ttry {\n\t\treturn await apiKey.resolve({ ctx: authContext, credential, signal });\n\t} catch (error) {\n\t\tthrow new ModelsError(\"auth\", `API key auth failed for provider ${providerId}`, { cause: error });\n\t}\n}\n\nasync function readCredential(\n\tcredentials: CredentialStore,\n\tproviderId: string,\n\tsignal: AbortSignal,\n): Promise<Credential | undefined> {\n\ttry {\n\t\treturn await credentials.read(providerId, { signal });\n\t} catch (error) {\n\t\tthrow new ModelsError(\"auth\", `Credential store read failed for ${providerId}`, { cause: error });\n\t}\n}\n"]}
1
+ {"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/auth/resolve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EACN,yBAAyB,EACzB,sBAAsB,EACtB,gBAAgB,EAChB,sBAAsB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AA6B9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,8BAA8B,CAAC;AAE7E,MAAM,UAAU,4BAA4B,CAAC,UAAkB;IAC9D,OAAO,GAAG,8BAA8B,GAAG,UAAU,EAAE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AAC,UAAU,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,WAAW,CAAC,MAAM,EAAE,oCAAoC,UAAU,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACnG,CAAC;AACF,CAAC","sourcesContent":["import type { ProviderEnv } from \"../types.ts\";\nimport { operationSignal, raceWithAbortSignal } from \"../utils/abort.ts\";\nimport { formatThrownValue } from \"../utils/diagnostics.ts\";\nimport {\n\tOAuthRefreshExchangeError,\n\tOAuthRefreshStoreError,\n\tprojectOAuthSlot,\n\trefreshOAuthCredential,\n} from \"./oauth-refresh.ts\";\nimport { projectSlot } from \"./pool/slots.ts\";\nimport type {\n\tApiKeyAuth,\n\tApiKeyCredential,\n\tAuthContext,\n\tAuthResult,\n\tCredential,\n\tCredentialStore,\n\tOAuthAuth,\n\tOAuthCredential,\n\tProviderAuth,\n} from \"./types.ts\";\n\nexport type ModelsErrorCode = \"model_source\" | \"model_validation\" | \"provider\" | \"stream\" | \"auth\" | \"oauth\";\n\nexport interface AuthResolutionOverrides {\n\tapiKey?: string;\n\tenv?: ProviderEnv;\n\t/** Require this much remaining OAuth-token validity; defaults to five minutes. */\n\tminOAuthValidityMs?: number;\n\t/**\n\t * Resolve against one named slot of a pooled credential. A missing entry or\n\t * slot resolves to undefined rather than falling back to another account or\n\t * ambient env, so a slot-scoped request can never silently switch identities.\n\t */\n\tslotName?: string;\n\tsignal?: AbortSignal;\n}\n\n/**\n * Prefix of the auth-miss every resolution site raises when a provider has no\n * usable credential. Consumers key recovery decisions off this exact wording,\n * so it is a shared constant instead of a literal repeated at each throw site:\n * rewording one copy would silently disable the other's behavior.\n */\nexport const PROVIDER_NOT_CONFIGURED_PREFIX = \"Provider is not configured: \";\n\nexport function providerNotConfiguredMessage(providerId: string): string {\n\treturn `${PROVIDER_NOT_CONFIGURED_PREFIX}${providerId}`;\n}\n\nexport class ModelsError extends Error {\n\treadonly code: ModelsErrorCode;\n\n\tconstructor(code: ModelsErrorCode, message: string, options?: { cause?: unknown }) {\n\t\tsuper(withCauseDetail(message, options?.cause), options);\n\t\tthis.name = \"ModelsError\";\n\t\tthis.code = code;\n\t}\n}\n\n/** Callers surface `error.message` only, so keep the underlying reason in it. */\nfunction withCauseDetail(message: string, cause: unknown): string {\n\tif (cause === undefined || cause === null) return message;\n\tconst detail = formatThrownValue(cause).trim();\n\tif (!detail || message.includes(detail)) return message;\n\treturn `${message}: ${detail}`;\n}\n\n/**\n * Auth resolution shared by the `Models` and `ImagesModels` collections.\n * A stored credential owns the provider: ambient/env is consulted only when\n * nothing is stored. No silent env fallback after a failed refresh or for a\n * credential type without a matching handler.\n */\nexport function resolveProviderAuth(\n\tprovider: { id: string; auth: ProviderAuth },\n\tcredentials: CredentialStore,\n\tauthContext: AuthContext,\n\toverrides?: AuthResolutionOverrides,\n): Promise<AuthResult | undefined> {\n\tconst signal = operationSignal(overrides?.signal);\n\treturn raceWithAbortSignal(\n\t\tresolveProviderAuthWithSignal(provider, credentials, authContext, overrides, signal),\n\t\tsignal,\n\t);\n}\n\nasync function resolveProviderAuthWithSignal(\n\tprovider: { id: string; auth: ProviderAuth },\n\tcredentials: CredentialStore,\n\tauthContext: AuthContext,\n\toverrides: AuthResolutionOverrides | undefined,\n\tsignal: AbortSignal,\n): Promise<AuthResult | undefined> {\n\tsignal.throwIfAborted();\n\tconst requestAuthContext = overrides?.env ? overlayEnvAuthContext(authContext, overrides.env) : authContext;\n\tconst apiKey = provider.auth.apiKey;\n\n\tif (overrides?.apiKey !== undefined && apiKey && !apiKey.ambientOnly) {\n\t\treturn resolveApiKey(\n\t\t\trequestAuthContext,\n\t\t\tapiKey,\n\t\t\tprovider.id,\n\t\t\t{\n\t\t\t\ttype: \"api_key\",\n\t\t\t\tkey: overrides.apiKey,\n\t\t\t\tenv: overrides.env,\n\t\t\t},\n\t\t\tsignal,\n\t\t);\n\t}\n\n\tconst stored = await readCredential(credentials, provider.id, signal);\n\tconst slotName = overrides?.slotName;\n\tif (slotName !== undefined) {\n\t\tconst projected = stored === undefined ? undefined : projectSlot(stored, slotName);\n\t\tif (!projected) return undefined;\n\t\tif (projected.type === \"oauth\" && provider.auth.oauth) {\n\t\t\treturn resolveStoredOAuth(\n\t\t\t\tcredentials,\n\t\t\t\tprovider.id,\n\t\t\t\tprovider.auth.oauth,\n\t\t\t\tprojected,\n\t\t\t\trequestAuthContext,\n\t\t\t\toverrides?.env,\n\t\t\t\tsignal,\n\t\t\t\toverrides?.minOAuthValidityMs,\n\t\t\t\tslotName,\n\t\t\t);\n\t\t}\n\t\tif (projected.type === \"api_key\" && provider.auth.apiKey) {\n\t\t\tconst credential = overrides?.env ? { ...projected, env: { ...projected.env, ...overrides.env } } : projected;\n\t\t\treturn resolveApiKey(requestAuthContext, provider.auth.apiKey, provider.id, credential, signal);\n\t\t}\n\t\treturn undefined;\n\t}\n\tif (stored) {\n\t\tif (stored.type === \"oauth\" && provider.auth.oauth) {\n\t\t\treturn resolveStoredOAuth(\n\t\t\t\tcredentials,\n\t\t\t\tprovider.id,\n\t\t\t\tprovider.auth.oauth,\n\t\t\t\tstored,\n\t\t\t\trequestAuthContext,\n\t\t\t\toverrides?.env,\n\t\t\t\tsignal,\n\t\t\t\toverrides?.minOAuthValidityMs,\n\t\t\t);\n\t\t}\n\t\tif (stored.type === \"api_key\" && provider.auth.apiKey) {\n\t\t\tconst credential = overrides?.env ? { ...stored, env: { ...stored.env, ...overrides.env } } : stored;\n\t\t\treturn resolveApiKey(requestAuthContext, provider.auth.apiKey, provider.id, credential, signal);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tif (overrides?.apiKey !== undefined && apiKey) {\n\t\treturn resolveApiKey(\n\t\t\trequestAuthContext,\n\t\t\tapiKey,\n\t\t\tprovider.id,\n\t\t\t{\n\t\t\t\ttype: \"api_key\",\n\t\t\t\tkey: overrides.apiKey,\n\t\t\t\tenv: overrides.env,\n\t\t\t},\n\t\t\tsignal,\n\t\t);\n\t}\n\n\t// Ambient (env vars, AWS profiles, ADC files).\n\tconst ambientCredential =\n\t\tapiKey?.ambientOnly && overrides?.env ? { type: \"api_key\" as const, key: \"\", env: overrides.env } : undefined;\n\treturn apiKey ? resolveApiKey(requestAuthContext, apiKey, provider.id, ambientCredential, signal) : undefined;\n}\n\nfunction overlayEnvAuthContext(base: AuthContext, env: ProviderEnv): AuthContext {\n\treturn {\n\t\tenv: async (name) => (env[name] !== undefined ? env[name] : await base.env(name)),\n\t\tfileExists: (path) => base.fileExists(path),\n\t};\n}\n\nconst DEFAULT_OAUTH_MINIMUM_VALIDITY_MS = 5 * 60 * 1000;\n\n/** Maps a shared-refresh failure onto the `ModelsError` codes callers match on. */\nexport function oauthRefreshModelsError(error: unknown, providerId: string): ModelsError {\n\tif (error instanceof ModelsError) return error;\n\tif (error instanceof OAuthRefreshExchangeError) {\n\t\treturn new ModelsError(\"oauth\", `OAuth refresh failed for ${providerId}`, { cause: error.cause });\n\t}\n\tconst cause = error instanceof OAuthRefreshStoreError ? error.cause : error;\n\treturn new ModelsError(\"auth\", `Credential store modify failed for ${providerId}`, { cause });\n}\n\n/**\n * OAuth resolution: a token with less than five minutes remaining is refreshed\n * through `refreshOAuthCredential`, which re-checks the stored value, runs the\n * exchange outside the store lock, and compare-and-swaps the rotated slot.\n */\nasync function resolveStoredOAuth(\n\tcredentials: CredentialStore,\n\tproviderId: string,\n\toauth: OAuthAuth,\n\tstored: OAuthCredential,\n\tauthContext: AuthContext,\n\trequestEnv: ProviderEnv | undefined,\n\tsignal: AbortSignal,\n\tminOAuthValidityMs?: number,\n\tslotName?: string,\n): Promise<AuthResult | undefined> {\n\tconst minimumValidityMs = Math.max(DEFAULT_OAUTH_MINIMUM_VALIDITY_MS, minOAuthValidityMs ?? 0);\n\tconst expiresSoon = (credential: OAuthCredential) => Date.now() + minimumValidityMs >= credential.expires;\n\tlet credential = stored;\n\n\tif (expiresSoon(credential)) {\n\t\tlet post: Credential | undefined;\n\t\ttry {\n\t\t\tpost = await refreshOAuthCredential({\n\t\t\t\tcredentials,\n\t\t\t\tproviderId,\n\t\t\t\toauth,\n\t\t\t\tstale: credential,\n\t\t\t\tslotName,\n\t\t\t\tisStale: expiresSoon,\n\t\t\t\tsignal,\n\t\t\t\towning: true,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthrow oauthRefreshModelsError(error, providerId);\n\t\t}\n\t\tif (post?.type !== \"oauth\") return undefined; // logged out meanwhile\n\t\tconst postView = slotName === undefined ? post : projectOAuthSlot(post, slotName);\n\t\tif (!postView) return undefined; // slot removed meanwhile\n\t\tcredential = postView;\n\t\t// The normal five-minute window triggers a refresh but does not impose a\n\t\t// provider contract. Explicit callers (such as bearer-token export) do\n\t\t// require the requested minimum after the refresh.\n\t\tif (minOAuthValidityMs !== undefined && expiresSoon(credential)) {\n\t\t\tthrow new ModelsError(\"oauth\", `OAuth refresh returned a token that expires too soon for ${providerId}`);\n\t\t}\n\t}\n\n\tconst storedEnv = credentialEnvironment(credential);\n\tconst effectiveEnv = requestEnv ? { ...storedEnv, ...requestEnv } : storedEnv;\n\tconst effectiveCredential = effectiveEnv ? { ...credential, env: effectiveEnv } : credential;\n\n\tif (oauth.check) {\n\t\ttry {\n\t\t\tif (!(await oauth.check({ ctx: authContext, credential: effectiveCredential, signal }))) return undefined;\n\t\t} catch (error) {\n\t\t\tthrow new ModelsError(\"auth\", `OAuth auth check failed for provider ${providerId}`, { cause: error });\n\t\t}\n\t}\n\n\ttry {\n\t\treturn {\n\t\t\tauth: await oauth.toAuth(effectiveCredential),\n\t\t\t...(effectiveEnv ? { env: effectiveEnv } : {}),\n\t\t\tsource: \"OAuth\",\n\t\t};\n\t} catch (error) {\n\t\tthrow new ModelsError(\"oauth\", `OAuth auth derivation failed for ${providerId}`, { cause: error });\n\t}\n}\n\nfunction credentialEnvironment(credential: OAuthCredential): ProviderEnv | undefined {\n\tconst value = credential.env;\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) return undefined;\n\tconst environment: ProviderEnv = {};\n\tfor (const [name, entry] of Object.entries(value)) {\n\t\tif (typeof entry !== \"string\") return undefined;\n\t\tenvironment[name] = entry;\n\t}\n\treturn environment;\n}\n\nasync function resolveApiKey(\n\tauthContext: AuthContext,\n\tapiKey: ApiKeyAuth,\n\tproviderId: string,\n\tcredential: ApiKeyCredential | undefined,\n\tsignal: AbortSignal,\n): Promise<AuthResult | undefined> {\n\ttry {\n\t\treturn await apiKey.resolve({ ctx: authContext, credential, signal });\n\t} catch (error) {\n\t\tthrow new ModelsError(\"auth\", `API key auth failed for provider ${providerId}`, { cause: error });\n\t}\n}\n\nasync function readCredential(\n\tcredentials: CredentialStore,\n\tproviderId: string,\n\tsignal: AbortSignal,\n): Promise<Credential | undefined> {\n\ttry {\n\t\treturn await credentials.read(providerId, { signal });\n\t} catch (error) {\n\t\tthrow new ModelsError(\"auth\", `Credential store read failed for ${providerId}`, { cause: error });\n\t}\n}\n"]}
@@ -148,6 +148,12 @@ export type AuthEvent = {
148
148
  type: "progress";
149
149
  message: string;
150
150
  };
151
+ /** Secret-free receipt emitted only after the account write succeeds. */
152
+ export interface AccountLoginReceipt {
153
+ readonly providerId: string;
154
+ readonly name: string;
155
+ readonly origin: "generated" | "provider";
156
+ }
151
157
  /**
152
158
  * Login interaction callbacks serving both api-key and OAuth flows.
153
159
  *
@@ -157,11 +163,13 @@ export type AuthEvent = {
157
163
  */
158
164
  export interface AuthInteraction {
159
165
  signal?: AbortSignal;
166
+ /** Absent for provider-owned envelopes without one unambiguous new slot ID. */
167
+ onAccountCommitted?(receipt: AccountLoginReceipt): void;
160
168
  prompt(prompt: AuthPrompt): Promise<string>;
161
169
  notify(event: AuthEvent): void;
162
170
  }
163
171
  /** Normalized interaction passed to provider login implementations. */
164
- export type ProviderAuthInteraction = AuthInteraction & {
172
+ export type ProviderAuthInteraction = Omit<AuthInteraction, "onAccountCommitted"> & {
165
173
  signal: AbortSignal;
166
174
  };
167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GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;CACpC;AAED;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACzB,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IAEb,oFAAoF;IACpF,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB,6FAA6F;IAC7F,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,KAAK,CAAC,WAAW,EAAE,uBAAuB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAEtE;;;OAGG;IACH,OAAO,CAAC,UAAU,EAAE,eAAe,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAEpF;;;;;OAKG;IACH,KAAK,CAAC,CAAC,KAAK,EAAE;QACb,GAAG,EAAE,WAAW,CAAC;QACjB,UAAU,CAAC,EAAE,eAAe,CAAC;QAC7B,MAAM,EAAE,WAAW,CAAC;KACpB,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;IAEnC;;;;OAIG;IACH,MAAM,CAAC,UAAU,EAAE,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CACxD;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC5B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,KAAK,CAAC,EAAE,SAAS,CAAC;CAClB"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ProviderEnv, ProviderHeaders } from \"../types.ts\";\n\n/**\n * Request auth for a single model request. If a value cannot be expressed as\n * `apiKey`, `headers`, or `baseUrl`, it is provider config, not auth.\n */\nexport interface ModelAuth {\n\tapiKey?: string;\n\theaders?: ProviderHeaders;\n\tbaseUrl?: string;\n}\n\n/**\n * Stored api-key credential. `env` holds provider-scoped environment/config\n * values such as Cloudflare account/gateway ids.\n */\nexport interface ApiKeyCredential {\n\ttype: \"api_key\";\n\tkey?: string;\n\tenv?: ProviderEnv;\n}\n\n/** OAuth token data returned by extension compatibility flows. */\nexport interface OAuthCredentials {\n\trefresh: string;\n\taccess: string;\n\texpires: number;\n\t[key: string]: unknown;\n}\n\n/** Stored canonical OAuth credential. */\nexport interface OAuthCredential extends OAuthCredentials {\n\ttype: \"oauth\";\n}\n\n/** One type-tagged credential per provider — the shape of today's auth.json. */\nexport type Credential = ApiKeyCredential | OAuthCredential;\n\n/** Non-secret credential metadata for account/status enumeration. */\nexport interface CredentialInfo {\n\tproviderId: string;\n\ttype: Credential[\"type\"];\n}\n\n/** Optional cancellation for public auth and credential operations. */\nexport interface AuthOperationOptions {\n\tsignal?: AbortSignal;\n}\n\n/**\n * App-owned credential storage, keyed by `Provider.id`, one entry per\n * provider; an entry may pool sibling slots under `accounts` while its flat\n * fields remain a valid credential. `modify` is the only write path, so every mutation is a\n * serialized read-modify-write; `Models.getAuth()` runs OAuth refresh inside\n * `modify` so concurrent requests cannot double-refresh a rotated token. The\n * app persists a credential after login via\n * `modify(provider.id, async () => credential)`. Login/logout orchestration\n * is app-owned.\n *\n * Error semantics: `read` resolves `undefined` for missing entries. Methods\n * reject only on storage failure; `Models` wraps such rejections in\n * `ModelsError` with code \"auth\". Best-effort stores that serve an in-memory\n * view and record persistence errors internally (like coding-agent's\n * AuthStorage) are valid implementations.\n */\nexport interface CredentialStore {\n\t/**\n\t * Read the stored credential, possibly expired. Display/status use;\n\t * resolved request auth comes from `Models.getAuth()`.\n\t */\n\tread(providerId: string, options?: AuthOperationOptions): Promise<Credential | undefined>;\n\n\t/**\n\t * List stored credential metadata without resolving or exposing secrets.\n\t * Implementations must not execute configured API-key commands while listing.\n\t */\n\tlist(options?: AuthOperationOptions): Promise<readonly CredentialInfo[]>;\n\n\t/**\n\t * Serialized write — the only write path. `fn` sees the current credential\n\t * because correct writes (refresh, login-during-refresh) depend on it;\n\t * return the new credential, or undefined to leave the entry unchanged.\n\t * Mutual exclusion per provider id, cross-process too where the backing\n\t * store supports it (e.g. a file lock). Resolves with the post-write\n\t * credential. Rejections from `fn` propagate.\n\t */\n\tmodify(\n\t\tproviderId: string,\n\t\tfn: (current: Credential | undefined) => Promise<Credential | undefined>,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<Credential | undefined>;\n\n\t/** Remove a credential (logout). Implementations serialize this against `modify`. */\n\tdelete(providerId: string, options?: AuthOperationOptions): Promise<void>;\n}\n\n/** Environment access for auth resolution. Injectable for tests and browsers. */\nexport interface AuthContext {\n\tenv(name: string): Promise<string | undefined>;\n\t/** Check whether a file exists. Supports a leading `~`. Always false in browsers. */\n\tfileExists(path: string): Promise<boolean>;\n}\n\n/** Result of resolving auth for a model. */\nexport interface AuthResult {\n\tauth: ModelAuth;\n\t/** Provider-scoped environment/config values resolved from credentials and ambient context. */\n\tenv?: ProviderEnv;\n\t/** Human-readable label for status UI: \"ANTHROPIC_API_KEY\", \"OAuth\", \"~/.aws/credentials\". */\n\tsource?: string;\n}\n\nexport interface AuthCheck {\n\tsource?: string;\n\ttype: \"api_key\" | \"oauth\";\n}\n\nexport type AuthType = \"api_key\" | \"oauth\";\n\n/**\n * Prompt shown to the user during login. `signal` lets the flow cancel a\n * pending prompt when an out-of-band event resolves the step, e.g. a\n * `manual_code` prompt raced against a callback server, aborted when the\n * callback wins.\n */\nexport type AuthPrompt = { signal?: AbortSignal } & (\n\t| { type: \"text\"; message: string; placeholder?: string }\n\t| { type: \"secret\"; message: string; placeholder?: string }\n\t| { type: \"select\"; message: string; options: readonly { id: string; label: string; description?: string }[] }\n\t| { type: \"manual_code\"; message: string; placeholder?: string }\n);\n\nexport interface AuthInfoLink {\n\turl: string;\n\tlabel?: string;\n}\n\nexport type AuthEvent =\n\t| { type: \"info\"; message: string; links?: readonly AuthInfoLink[] }\n\t| { type: \"auth_url\"; url: string; instructions?: string }\n\t| {\n\t\t\ttype: \"device_code\";\n\t\t\tuserCode: string;\n\t\t\tverificationUri: string;\n\t\t\tintervalSeconds?: number;\n\t\t\texpiresInSeconds?: number;\n\t }\n\t| { type: \"progress\"; message: string };\n\n/**\n * Login interaction callbacks serving both api-key and OAuth flows.\n *\n * `prompt()` returns the entered/selected string (`select` returns the option\n * id). Rejects on cancel/abort. `signal` aborts the whole login flow;\n * per-prompt cancellation uses `AuthPrompt.signal`.\n */\nexport interface AuthInteraction {\n\tsignal?: AbortSignal;\n\n\tprompt(prompt: AuthPrompt): Promise<string>;\n\tnotify(event: AuthEvent): void;\n}\n\n/** Normalized interaction passed to provider login implementations. */\nexport type ProviderAuthInteraction = AuthInteraction & { signal: AbortSignal };\n\n/**\n * Api-key auth: stored key/provider env plus ambient sources (env vars, AWS\n * profiles, ADC files). Ambient-only providers omit `login`.\n */\nexport interface ApiKeyAuth {\n\t/** Display name, e.g. \"Anthropic API key\". */\n\tname: string;\n\n\t/** Ambient compatibility adapter that must not outrank a stored OAuth credential. */\n\tambientOnly?: boolean;\n\n\t/** Interactive setup (prompt for key/provider env). Absent = ambient-only. */\n\tlogin?(interaction: ProviderAuthInteraction): Promise<ApiKeyCredential>;\n\n\t/**\n\t * Optional side-effect-free availability check. Use this when `resolve()` may\n\t * execute commands or perform other request-time work. Missing means Models\n\t * checks availability by resolving auth.\n\t */\n\tcheck?(input: {\n\t\tctx: AuthContext;\n\t\tcredential?: ApiKeyCredential;\n\t\tsignal: AbortSignal;\n\t}): Promise<AuthCheck | undefined>;\n\n\t/**\n\t * Resolve auth from the stored credential and/or ambient sources, merging\n\t * per field (`credential.key ?? env(\"...\")`, `credential.env?.NAME ?? env(\"...\")`).\n\t * undefined = not configured. Resolution is provider-scoped; model-specific\n\t * endpoint preparation happens after auth has been resolved.\n\t */\n\tresolve(input: {\n\t\tctx: AuthContext;\n\t\tcredential?: ApiKeyCredential;\n\t\tsignal: AbortSignal;\n\t}): Promise<AuthResult | undefined>;\n}\n\n/**\n * OAuth auth. The `refresh`/`toAuth` split lets `Models` own the locked\n * refresh pattern: `refresh` produces a credential, `toAuth` derives request\n * auth from whatever credential ends up stored.\n */\nexport interface OAuthAuth {\n\t/** Display name, e.g. \"Anthropic (Claude Pro/Max)\". */\n\tname: string;\n\n\t/** Whether access through this auth method is backed by a provider subscription. */\n\tisSubscription?: boolean;\n\n\t/** Selector label for the OAuth login option, e.g. \"Sign in with SuperGrok or X Premium\". */\n\tloginLabel?: string;\n\n\tlogin(interaction: ProviderAuthInteraction): Promise<OAuthCredential>;\n\n\t/**\n\t * Exchange the refresh token. Network call; throws on failure\n\t * (invalid_grant etc.). `Models` runs this under the store lock.\n\t */\n\trefresh(credential: OAuthCredential, signal: AbortSignal): Promise<OAuthCredential>;\n\n\t/**\n\t * Optional side-effect-free availability check, mirroring `ApiKeyAuth.check`.\n\t * Supply this when a stored OAuth credential does not by itself imply the\n\t * provider is usable — for example a sentinel envelope that carries zero\n\t * accounts. When absent, any stored OAuth credential counts as configured.\n\t */\n\tcheck?(input: {\n\t\tctx: AuthContext;\n\t\tcredential?: OAuthCredential;\n\t\tsignal: AbortSignal;\n\t}): Promise<AuthCheck | undefined>;\n\n\t/**\n\t * Side-effect-free derivation of request auth from a valid credential.\n\t * Covers per-credential baseUrl (GitHub Copilot). Async so lazy wrappers\n\t * can load the implementation on first use.\n\t */\n\ttoAuth(credential: OAuthCredential): Promise<ModelAuth>;\n}\n\n/**\n * Provider auth. At least one of `apiKey`/`oauth` must be present: even\n * ambient-credential providers and keyless local servers provide `apiKey`\n * auth whose `resolve()` reports whether the provider is configured.\n */\nexport interface ProviderAuth {\n\tapiKey?: ApiKeyAuth;\n\toauth?: OAuthAuth;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ProviderEnv, ProviderHeaders } from \"../types.ts\";\n\n/**\n * Request auth for a single model request. If a value cannot be expressed as\n * `apiKey`, `headers`, or `baseUrl`, it is provider config, not auth.\n */\nexport interface ModelAuth {\n\tapiKey?: string;\n\theaders?: ProviderHeaders;\n\tbaseUrl?: string;\n}\n\n/**\n * Stored api-key credential. `env` holds provider-scoped environment/config\n * values such as Cloudflare account/gateway ids.\n */\nexport interface ApiKeyCredential {\n\ttype: \"api_key\";\n\tkey?: string;\n\tenv?: ProviderEnv;\n}\n\n/** OAuth token data returned by extension compatibility flows. */\nexport interface OAuthCredentials {\n\trefresh: string;\n\taccess: string;\n\texpires: number;\n\t[key: string]: unknown;\n}\n\n/** Stored canonical OAuth credential. */\nexport interface OAuthCredential extends OAuthCredentials {\n\ttype: \"oauth\";\n}\n\n/** One type-tagged credential per provider — the shape of today's auth.json. */\nexport type Credential = ApiKeyCredential | OAuthCredential;\n\n/** Non-secret credential metadata for account/status enumeration. */\nexport interface CredentialInfo {\n\tproviderId: string;\n\ttype: Credential[\"type\"];\n}\n\n/** Optional cancellation for public auth and credential operations. */\nexport interface AuthOperationOptions {\n\tsignal?: AbortSignal;\n}\n\n/**\n * App-owned credential storage, keyed by `Provider.id`, one entry per\n * provider; an entry may pool sibling slots under `accounts` while its flat\n * fields remain a valid credential. `modify` is the only write path, so every mutation is a\n * serialized read-modify-write; `Models.getAuth()` runs OAuth refresh inside\n * `modify` so concurrent requests cannot double-refresh a rotated token. The\n * app persists a credential after login via\n * `modify(provider.id, async () => credential)`. Login/logout orchestration\n * is app-owned.\n *\n * Error semantics: `read` resolves `undefined` for missing entries. Methods\n * reject only on storage failure; `Models` wraps such rejections in\n * `ModelsError` with code \"auth\". Best-effort stores that serve an in-memory\n * view and record persistence errors internally (like coding-agent's\n * AuthStorage) are valid implementations.\n */\nexport interface CredentialStore {\n\t/**\n\t * Read the stored credential, possibly expired. Display/status use;\n\t * resolved request auth comes from `Models.getAuth()`.\n\t */\n\tread(providerId: string, options?: AuthOperationOptions): Promise<Credential | undefined>;\n\n\t/**\n\t * List stored credential metadata without resolving or exposing secrets.\n\t * Implementations must not execute configured API-key commands while listing.\n\t */\n\tlist(options?: AuthOperationOptions): Promise<readonly CredentialInfo[]>;\n\n\t/**\n\t * Serialized write — the only write path. `fn` sees the current credential\n\t * because correct writes (refresh, login-during-refresh) depend on it;\n\t * return the new credential, or undefined to leave the entry unchanged.\n\t * Mutual exclusion per provider id, cross-process too where the backing\n\t * store supports it (e.g. a file lock). Resolves with the post-write\n\t * credential. Rejections from `fn` propagate.\n\t */\n\tmodify(\n\t\tproviderId: string,\n\t\tfn: (current: Credential | undefined) => Promise<Credential | undefined>,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<Credential | undefined>;\n\n\t/** Remove a credential (logout). Implementations serialize this against `modify`. */\n\tdelete(providerId: string, options?: AuthOperationOptions): Promise<void>;\n}\n\n/** Environment access for auth resolution. Injectable for tests and browsers. */\nexport interface AuthContext {\n\tenv(name: string): Promise<string | undefined>;\n\t/** Check whether a file exists. Supports a leading `~`. Always false in browsers. */\n\tfileExists(path: string): Promise<boolean>;\n}\n\n/** Result of resolving auth for a model. */\nexport interface AuthResult {\n\tauth: ModelAuth;\n\t/** Provider-scoped environment/config values resolved from credentials and ambient context. */\n\tenv?: ProviderEnv;\n\t/** Human-readable label for status UI: \"ANTHROPIC_API_KEY\", \"OAuth\", \"~/.aws/credentials\". */\n\tsource?: string;\n}\n\nexport interface AuthCheck {\n\tsource?: string;\n\ttype: \"api_key\" | \"oauth\";\n}\n\nexport type AuthType = \"api_key\" | \"oauth\";\n\n/**\n * Prompt shown to the user during login. `signal` lets the flow cancel a\n * pending prompt when an out-of-band event resolves the step, e.g. a\n * `manual_code` prompt raced against a callback server, aborted when the\n * callback wins.\n */\nexport type AuthPrompt = { signal?: AbortSignal } & (\n\t| { type: \"text\"; message: string; placeholder?: string }\n\t| { type: \"secret\"; message: string; placeholder?: string }\n\t| { type: \"select\"; message: string; options: readonly { id: string; label: string; description?: string }[] }\n\t| { type: \"manual_code\"; message: string; placeholder?: string }\n);\n\nexport interface AuthInfoLink {\n\turl: string;\n\tlabel?: string;\n}\n\nexport type AuthEvent =\n\t| { type: \"info\"; message: string; links?: readonly AuthInfoLink[] }\n\t| { type: \"auth_url\"; url: string; instructions?: string }\n\t| {\n\t\t\ttype: \"device_code\";\n\t\t\tuserCode: string;\n\t\t\tverificationUri: string;\n\t\t\tintervalSeconds?: number;\n\t\t\texpiresInSeconds?: number;\n\t }\n\t| { type: \"progress\"; message: string };\n\n/** Secret-free receipt emitted only after the account write succeeds. */\nexport interface AccountLoginReceipt {\n\treadonly providerId: string;\n\treadonly name: string;\n\treadonly origin: \"generated\" | \"provider\";\n}\n\n/**\n * Login interaction callbacks serving both api-key and OAuth flows.\n *\n * `prompt()` returns the entered/selected string (`select` returns the option\n * id). Rejects on cancel/abort. `signal` aborts the whole login flow;\n * per-prompt cancellation uses `AuthPrompt.signal`.\n */\nexport interface AuthInteraction {\n\tsignal?: AbortSignal;\n\t/** Absent for provider-owned envelopes without one unambiguous new slot ID. */\n\tonAccountCommitted?(receipt: AccountLoginReceipt): void;\n\n\tprompt(prompt: AuthPrompt): Promise<string>;\n\tnotify(event: AuthEvent): void;\n}\n\n/** Normalized interaction passed to provider login implementations. */\nexport type ProviderAuthInteraction = Omit<AuthInteraction, \"onAccountCommitted\"> & { signal: AbortSignal };\n\n/**\n * Api-key auth: stored key/provider env plus ambient sources (env vars, AWS\n * profiles, ADC files). Ambient-only providers omit `login`.\n */\nexport interface ApiKeyAuth {\n\t/** Display name, e.g. \"Anthropic API key\". */\n\tname: string;\n\n\t/** Ambient compatibility adapter that must not outrank a stored OAuth credential. */\n\tambientOnly?: boolean;\n\n\t/** Interactive setup (prompt for key/provider env). Absent = ambient-only. */\n\tlogin?(interaction: ProviderAuthInteraction): Promise<ApiKeyCredential>;\n\n\t/**\n\t * Optional side-effect-free availability check. Use this when `resolve()` may\n\t * execute commands or perform other request-time work. Missing means Models\n\t * checks availability by resolving auth.\n\t */\n\tcheck?(input: {\n\t\tctx: AuthContext;\n\t\tcredential?: ApiKeyCredential;\n\t\tsignal: AbortSignal;\n\t}): Promise<AuthCheck | undefined>;\n\n\t/**\n\t * Resolve auth from the stored credential and/or ambient sources, merging\n\t * per field (`credential.key ?? env(\"...\")`, `credential.env?.NAME ?? env(\"...\")`).\n\t * undefined = not configured. Resolution is provider-scoped; model-specific\n\t * endpoint preparation happens after auth has been resolved.\n\t */\n\tresolve(input: {\n\t\tctx: AuthContext;\n\t\tcredential?: ApiKeyCredential;\n\t\tsignal: AbortSignal;\n\t}): Promise<AuthResult | undefined>;\n}\n\n/**\n * OAuth auth. The `refresh`/`toAuth` split lets `Models` own the locked\n * refresh pattern: `refresh` produces a credential, `toAuth` derives request\n * auth from whatever credential ends up stored.\n */\nexport interface OAuthAuth {\n\t/** Display name, e.g. \"Anthropic (Claude Pro/Max)\". */\n\tname: string;\n\n\t/** Whether access through this auth method is backed by a provider subscription. */\n\tisSubscription?: boolean;\n\n\t/** Selector label for the OAuth login option, e.g. \"Sign in with SuperGrok or X Premium\". */\n\tloginLabel?: string;\n\n\tlogin(interaction: ProviderAuthInteraction): Promise<OAuthCredential>;\n\n\t/**\n\t * Exchange the refresh token. Network call; throws on failure\n\t * (invalid_grant etc.). `Models` runs this under the store lock.\n\t */\n\trefresh(credential: OAuthCredential, signal: AbortSignal): Promise<OAuthCredential>;\n\n\t/**\n\t * Optional side-effect-free availability check, mirroring `ApiKeyAuth.check`.\n\t * Supply this when a stored OAuth credential does not by itself imply the\n\t * provider is usable — for example a sentinel envelope that carries zero\n\t * accounts. When absent, any stored OAuth credential counts as configured.\n\t */\n\tcheck?(input: {\n\t\tctx: AuthContext;\n\t\tcredential?: OAuthCredential;\n\t\tsignal: AbortSignal;\n\t}): Promise<AuthCheck | undefined>;\n\n\t/**\n\t * Side-effect-free derivation of request auth from a valid credential.\n\t * Covers per-credential baseUrl (GitHub Copilot). Async so lazy wrappers\n\t * can load the implementation on first use.\n\t */\n\ttoAuth(credential: OAuthCredential): Promise<ModelAuth>;\n}\n\n/**\n * Provider auth. At least one of `apiKey`/`oauth` must be present: even\n * ambient-credential providers and keyless local servers provide `apiKey`\n * auth whose `resolve()` reports whether the provider is configured.\n */\nexport interface ProviderAuth {\n\tapiKey?: ApiKeyAuth;\n\toauth?: OAuthAuth;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"bun-oauth.d.ts","sourceRoot":"","sources":["../src/bun-oauth.ts"],"names":[],"mappings":"AAUA,6EAA6E;AAC7E,wBAAgB,qBAAqB,IAAI,IAAI,CAW5C"}
1
+ {"version":3,"file":"bun-oauth.d.ts","sourceRoot":"","sources":["../src/bun-oauth.ts"],"names":[],"mappings":"AAWA,6EAA6E;AAC7E,wBAAgB,qBAAqB,IAAI,IAAI,CAY5C"}
@@ -1,5 +1,6 @@
1
1
  import { anthropicOAuth } from "./auth/oauth/anthropic.js";
2
2
  import { cursorOAuth } from "./auth/oauth/cursor.js";
3
+ import { devinOAuth } from "./auth/oauth/devin.js";
3
4
  import { githubCopilotOAuth } from "./auth/oauth/github-copilot.js";
4
5
  import { kimiCodingOAuth } from "./auth/oauth/kimi-coding.js";
5
6
  import { registerBundledOAuthFlowLoaders } from "./auth/oauth/load.js";
@@ -17,6 +18,7 @@ export function registerBunOAuthFlows() {
17
18
  kimiCoding: () => kimiCodingOAuth,
18
19
  xai: () => xaiOAuth,
19
20
  cursor: () => cursorOAuth,
21
+ devin: () => devinOAuth,
20
22
  radius: createRadiusOAuth,
21
23
  });
22
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bun-oauth.js","sourceRoot":"","sources":["../src/bun-oauth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,6EAA6E;AAC7E,MAAM,UAAU,qBAAqB;IACpC,+BAA+B,CAAC;QAC/B,SAAS,EAAE,GAAG,EAAE,CAAC,cAAc;QAC/B,WAAW,EAAE,GAAG,EAAE,CAAC,gBAAgB;QACnC,aAAa,EAAE,GAAG,EAAE,CAAC,kBAAkB;QACvC,UAAU,EAAE,GAAG,EAAE,CAAC,eAAe;QACjC,UAAU,EAAE,GAAG,EAAE,CAAC,eAAe;QACjC,GAAG,EAAE,GAAG,EAAE,CAAC,QAAQ;QACnB,MAAM,EAAE,GAAG,EAAE,CAAC,WAAW;QACzB,MAAM,EAAE,iBAAiB;KACzB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { anthropicOAuth } from \"./auth/oauth/anthropic.ts\";\nimport { cursorOAuth } from \"./auth/oauth/cursor.ts\";\nimport { githubCopilotOAuth } from \"./auth/oauth/github-copilot.ts\";\nimport { kimiCodingOAuth } from \"./auth/oauth/kimi-coding.ts\";\nimport { registerBundledOAuthFlowLoaders } from \"./auth/oauth/load.ts\";\nimport { openaiCodexOAuth } from \"./auth/oauth/openai-codex.ts\";\nimport { openRouterOAuth } from \"./auth/oauth/openrouter.ts\";\nimport { createRadiusOAuth } from \"./auth/oauth/radius.ts\";\nimport { xaiOAuth } from \"./auth/oauth/xai.ts\";\n\n/** Register OAuth flows statically embedded in the standalone Bun binary. */\nexport function registerBunOAuthFlows(): void {\n\tregisterBundledOAuthFlowLoaders({\n\t\tanthropic: () => anthropicOAuth,\n\t\topenaiCodex: () => openaiCodexOAuth,\n\t\tgithubCopilot: () => githubCopilotOAuth,\n\t\topenrouter: () => openRouterOAuth,\n\t\tkimiCoding: () => kimiCodingOAuth,\n\t\txai: () => xaiOAuth,\n\t\tcursor: () => cursorOAuth,\n\t\tradius: createRadiusOAuth,\n\t});\n}\n"]}
1
+ {"version":3,"file":"bun-oauth.js","sourceRoot":"","sources":["../src/bun-oauth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,6EAA6E;AAC7E,MAAM,UAAU,qBAAqB;IACpC,+BAA+B,CAAC;QAC/B,SAAS,EAAE,GAAG,EAAE,CAAC,cAAc;QAC/B,WAAW,EAAE,GAAG,EAAE,CAAC,gBAAgB;QACnC,aAAa,EAAE,GAAG,EAAE,CAAC,kBAAkB;QACvC,UAAU,EAAE,GAAG,EAAE,CAAC,eAAe;QACjC,UAAU,EAAE,GAAG,EAAE,CAAC,eAAe;QACjC,GAAG,EAAE,GAAG,EAAE,CAAC,QAAQ;QACnB,MAAM,EAAE,GAAG,EAAE,CAAC,WAAW;QACzB,KAAK,EAAE,GAAG,EAAE,CAAC,UAAU;QACvB,MAAM,EAAE,iBAAiB;KACzB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { anthropicOAuth } from \"./auth/oauth/anthropic.ts\";\nimport { cursorOAuth } from \"./auth/oauth/cursor.ts\";\nimport { devinOAuth } from \"./auth/oauth/devin.ts\";\nimport { githubCopilotOAuth } from \"./auth/oauth/github-copilot.ts\";\nimport { kimiCodingOAuth } from \"./auth/oauth/kimi-coding.ts\";\nimport { registerBundledOAuthFlowLoaders } from \"./auth/oauth/load.ts\";\nimport { openaiCodexOAuth } from \"./auth/oauth/openai-codex.ts\";\nimport { openRouterOAuth } from \"./auth/oauth/openrouter.ts\";\nimport { createRadiusOAuth } from \"./auth/oauth/radius.ts\";\nimport { xaiOAuth } from \"./auth/oauth/xai.ts\";\n\n/** Register OAuth flows statically embedded in the standalone Bun binary. */\nexport function registerBunOAuthFlows(): void {\n\tregisterBundledOAuthFlowLoaders({\n\t\tanthropic: () => anthropicOAuth,\n\t\topenaiCodex: () => openaiCodexOAuth,\n\t\tgithubCopilot: () => githubCopilotOAuth,\n\t\topenrouter: () => openRouterOAuth,\n\t\tkimiCoding: () => kimiCodingOAuth,\n\t\txai: () => xaiOAuth,\n\t\tcursor: () => cursorOAuth,\n\t\tdevin: () => devinOAuth,\n\t\tradius: createRadiusOAuth,\n\t});\n}\n"]}
@@ -13,6 +13,7 @@ export * from "./api/anthropic-messages.lazy.ts";
13
13
  export * from "./api/azure-openai-responses.lazy.ts";
14
14
  export * from "./api/bedrock-converse-stream.lazy.ts";
15
15
  export * from "./api/cursor-agent.lazy.ts";
16
+ export * from "./api/devin-agent.lazy.ts";
16
17
  export * from "./api/google-generative-ai.lazy.ts";
17
18
  export * from "./api/google-vertex.lazy.ts";
18
19
  export * from "./api/mistral-conversations.lazy.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"compat.d.ts","sourceRoot":"","sources":["../src/compat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,cAAc,kCAAkC,CAAC;AACjD,cAAc,sCAAsC,CAAC;AACrD,cAAc,uCAAuC,CAAC;AACtD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qCAAqC,CAAC;AACpD,cAAc,sCAAsC,CAAC;AACrD,cAAc,kCAAkC,CAAC;AACjD,cAAc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E,OAAO,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC7B,OAAO,CAAC,gBAAgB,CAAC,CAG3B;AAED,wBAAgB,YAAY,CAAC,IAAI,SAAS,GAAG,EAC5C,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,2BAA2B,CAkB7B;AAED,wBAAsB,cAAc,CAAC,IAAI,SAAS,GAAG,EACpD,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,gBAAgB,CAAC,CAG3B"}
@@ -13,6 +13,7 @@ export * from "./api/anthropic-messages.lazy.js";
13
13
  export * from "./api/azure-openai-responses.lazy.js";
14
14
  export * from "./api/bedrock-converse-stream.lazy.js";
15
15
  export * from "./api/cursor-agent.lazy.js";
16
+ export * from "./api/devin-agent.lazy.js";
16
17
  export * from "./api/google-generative-ai.lazy.js";
17
18
  export * from "./api/google-vertex.lazy.js";
18
19
  export * from "./api/mistral-conversations.lazy.js";
@@ -32,6 +33,7 @@ import { anthropicMessagesApi } from "./api/anthropic-messages.lazy.js";
32
33
  import { azureOpenAIResponsesApi } from "./api/azure-openai-responses.lazy.js";
33
34
  import { bedrockConverseStreamApi } from "./api/bedrock-converse-stream.lazy.js";
34
35
  import { cursorAgentApi } from "./api/cursor-agent.lazy.js";
36
+ import { devinAgentApi } from "./api/devin-agent.lazy.js";
35
37
  import { googleGenerativeAIApi } from "./api/google-generative-ai.lazy.js";
36
38
  import { googleVertexApi } from "./api/google-vertex.lazy.js";
37
39
  import { mistralConversationsApi } from "./api/mistral-conversations.lazy.js";
@@ -75,6 +77,7 @@ const BUILTIN_APIS = [
75
77
  ["openai-responses", openAIResponsesApi()],
76
78
  ["openai-codex-responses", openAICodexResponsesApi()],
77
79
  ["cursor-agent", cursorAgentApi()],
80
+ ["devin-agent", devinAgentApi()],
78
81
  ["azure-openai-responses", azureOpenAIResponsesApi()],
79
82
  ["google-generative-ai", googleGenerativeAIApi()],
80
83
  ["google-vertex", googleVertexApi()],
@@ -1 +1 @@
1
- {"version":3,"file":"compat.js","sourceRoot":"","sources":["../src/compat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,cAAc,kCAAkC,CAAC;AACjD,cAAc,sCAAsC,CAAC;AACrD,cAAc,uCAAuC,CAAC;AACtD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qCAAqC,CAAC;AACpD,cAAc,sCAAsC,CAAC;AACrD,cAAc,kCAAkC,CAAC;AACjD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,yCAAyC,CAAC;AACxD,OAAO,EACN,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,gCAAgC,GAChC,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAE,oBAAoB,EA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AE,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/E,CAAC;IAED,MAAM,eAAe,GAAG,0BAA0B,CAAC,KAAK,CAAC,CAAC;IAC1D,IAAI,eAAe,EAAE,CAAC;QACrB,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC,yBAAyB,CAAC,OAAO,CAAC,EAAE,CAAC;YACrF,OAAO,YAAY,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC3D,CAAC;QACD,OAAO,eAAe,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;IACpF,CAAC;IACD,MAAM,QAAQ,GAAG,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/C,OAAO,QAAQ,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,KAAkB,EAClB,OAAgB,EAChB,OAA6B;IAE7B,MAAM,CAAC,GAAG,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAChD,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;AACnB,CAAC","sourcesContent":["/**\n * Temporary compatibility entrypoint preserving the old global pi-ai API\n * surface: api-dispatch `stream()`/`complete()` with env API key injection,\n * the api-registry, generated catalog reads (`getModel`/`getModels`/\n * `getProviders`), per-API lazy stream wrappers, and image generation.\n *\n * Existing apps switch imports from \"@earendil-works/pi-ai\" to\n * \"@earendil-works/pi-ai/compat\" unchanged; new code uses `createModels()`\n * and the provider factories. This module is deleted with the coding-agent\n * ModelManager migration.\n */\n\nexport * from \"./api/anthropic-messages.lazy.ts\";\nexport * from \"./api/azure-openai-responses.lazy.ts\";\nexport * from \"./api/bedrock-converse-stream.lazy.ts\";\nexport * from \"./api/cursor-agent.lazy.ts\";\nexport * from \"./api/google-generative-ai.lazy.ts\";\nexport * from \"./api/google-vertex.lazy.ts\";\nexport * from \"./api/mistral-conversations.lazy.ts\";\nexport * from \"./api/openai-codex-responses.lazy.ts\";\nexport * from \"./api/openai-completions.lazy.ts\";\nexport * from \"./api/openai-responses.lazy.ts\";\nexport * from \"./api/pi-messages.lazy.ts\";\nexport * from \"./env-api-keys.ts\";\nexport * from \"./image-models.ts\";\nexport * from \"./images.ts\";\nexport * from \"./images-api-registry.ts\";\nexport * from \"./index.ts\";\nexport * from \"./legacy-api-aliases.ts\";\nexport * from \"./providers/images/register-builtins.ts\";\nexport {\n\tgetProtocol,\n\tgetToolCallFormat,\n\ttransformContext,\n\twrapStreamWithToolCallMiddleware,\n} from \"./tool-call-middleware/index.ts\";\n\nimport { anthropicMessagesApi } from \"./api/anthropic-messages.lazy.ts\";\nimport { azureOpenAIResponsesApi } from \"./api/azure-openai-responses.lazy.ts\";\nimport { bedrockConverseStreamApi } from \"./api/bedrock-converse-stream.lazy.ts\";\nimport { cursorAgentApi } from \"./api/cursor-agent.lazy.ts\";\nimport { googleGenerativeAIApi } from \"./api/google-generative-ai.lazy.ts\";\nimport { googleVertexApi } from \"./api/google-vertex.lazy.ts\";\nimport { mistralConversationsApi } from \"./api/mistral-conversations.lazy.ts\";\nimport { openAICodexResponsesApi } from \"./api/openai-codex-responses.lazy.ts\";\nimport { openAICompletionsApi } from \"./api/openai-completions.lazy.ts\";\nimport { openAIResponsesApi } from \"./api/openai-responses.lazy.ts\";\nimport { piMessagesApi } from \"./api/pi-messages.lazy.ts\";\nimport { getEnvApiKey } from \"./env-api-keys.ts\";\nimport type { ModelsApiStreamOptions } from \"./models.ts\";\nimport { builtinModels, getBuiltinModel, getBuiltinModels, getBuiltinProviders } from \"./providers/all.ts\";\n\nexport type { BuiltinProvider } from \"./providers/all.ts\";\n\nimport { createFauxCore, type FauxProviderRegistration, type RegisterFauxProviderOptions } from \"./providers/faux.ts\";\nimport {\n\tgetProtocol,\n\tgetToolCallFormat,\n\ttransformContext,\n\twrapStreamWithToolCallMiddleware,\n} from \"./tool-call-middleware/index.ts\";\nimport type {\n\tApi,\n\tApiStreamOptions,\n\tAssistantMessage,\n\tAssistantMessageEventStream,\n\tContext,\n\tModel,\n\tProviderStreamOptions,\n\tProviderStreams,\n\tSimpleStreamOptions,\n\tStreamOptions,\n} from \"./types.ts\";\n\n/** @deprecated Static catalog read. Use `getBuiltinModel` from \"@earendil-works/pi-ai/providers/all\" or `Models.getModel()`. */\nexport const getModel = getBuiltinModel;\n\n/** @deprecated Static catalog read. Use `getBuiltinModels` from \"@earendil-works/pi-ai/providers/all\" or `Models.getModels()`. */\nexport const getModels = getBuiltinModels;\n\n/** @deprecated Static catalog read. Use `getBuiltinProviders` from \"@earendil-works/pi-ai/providers/all\" or `Models.getProviders()`. */\nexport const getProviders = getBuiltinProviders;\n\nexport {\n\ttype ApiProvider,\n\ttype ApiProviderInternal,\n\ttype ApiStreamFunction,\n\ttype ApiStreamSimpleFunction,\n\tgetApiProvider,\n\tgetApiProviders,\n\tregisterApiProvider,\n\tunregisterApiProviders,\n} from \"./api-registry.ts\";\n\nimport {\n\tclearApiProviders,\n\tgetApiProvider,\n\tregisterApiProvider,\n\tregisterBuiltinApiProvider,\n\tunregisterApiProviders,\n} from \"./api-registry.ts\";\n\nexport function registerFauxProvider(options: RegisterFauxProviderOptions = {}): FauxProviderRegistration {\n\tconst core = createFauxCore(options);\n\tconst sourceId = `faux-provider-${Math.random().toString(36).slice(2, 10)}`;\n\tregisterApiProvider({ api: core.api, stream: core.stream, streamSimple: core.streamSimple }, sourceId);\n\treturn {\n\t\tapi: core.api,\n\t\tmodels: core.models,\n\t\tgetModel: core.getModel,\n\t\tstate: core.state,\n\t\tsetResponses: core.setResponses,\n\t\tappendResponses: core.appendResponses,\n\t\tgetPendingResponseCount: core.getPendingResponseCount,\n\t\tgetCallLog: core.getCallLog,\n\t\tunregister() {\n\t\t\tunregisterApiProviders(sourceId);\n\t\t},\n\t};\n}\n\nconst BUILTIN_APIS: [Api, ProviderStreams][] = [\n\t[\"anthropic-messages\", anthropicMessagesApi()],\n\t[\"openai-completions\", openAICompletionsApi()],\n\t[\"openai-responses\", openAIResponsesApi()],\n\t[\"openai-codex-responses\", openAICodexResponsesApi()],\n\t[\"cursor-agent\", cursorAgentApi()],\n\t[\"azure-openai-responses\", azureOpenAIResponsesApi()],\n\t[\"google-generative-ai\", googleGenerativeAIApi()],\n\t[\"google-vertex\", googleVertexApi()],\n\t[\"mistral-conversations\", mistralConversationsApi()],\n\t[\"bedrock-converse-stream\", bedrockConverseStreamApi()],\n\t[\"pi-messages\", piMessagesApi()],\n];\n\nconst builtinApiProviderInstances = new Map<Api, ReturnType<typeof getApiProvider>>();\n\n/**\n * Registers the builtin API implementations into the api-registry without\n * clobbering existing entries: compat may load after a test or extension has\n * already registered an override for a builtin api id.\n */\nexport function registerBuiltInApiProviders(): void {\n\tfor (const [api, streams] of BUILTIN_APIS) {\n\t\tregisterBuiltinApiProvider({ api, stream: streams.stream, streamSimple: streams.streamSimple });\n\t\tif (!getApiProvider(api)) {\n\t\t\tregisterApiProvider({ api, stream: streams.stream, streamSimple: streams.streamSimple });\n\t\t}\n\t\tbuiltinApiProviderInstances.set(api, getApiProvider(api));\n\t}\n}\n\nexport function resetApiProviders(): void {\n\tclearApiProviders();\n\tbuiltinApiProviderInstances.clear();\n\tregisterBuiltInApiProviders();\n}\n\nregisterBuiltInApiProviders();\n\nconst compatModels = builtinModels();\nconst AMBIENT_AUTH_MARKER = \"<authenticated>\";\n\nfunction hasExplicitApiKey(apiKey: string | undefined): apiKey is string {\n\treturn typeof apiKey === \"string\" && apiKey.trim().length > 0;\n}\n\nfunction withEnvApiKey<TOptions extends StreamOptions>(\n\tmodel: Model<Api>,\n\toptions: TOptions | undefined,\n): TOptions | undefined {\n\tif (hasExplicitApiKey(options?.apiKey)) return options;\n\tconst apiKey = getEnvApiKey(model.provider, options?.env);\n\tif (!apiKey || apiKey === AMBIENT_AUTH_MARKER) return options;\n\treturn { ...options, apiKey } as TOptions;\n}\n\nfunction hasResolvedCloudflareAuth(options: StreamOptions | undefined): boolean {\n\treturn hasExplicitApiKey(options?.apiKey) || typeof options?.headers?.[\"cf-aig-authorization\"] === \"string\";\n}\n\nfunction getBuiltinProviderForModel(model: Model<Api>) {\n\tif (getApiProvider(model.api) !== builtinApiProviderInstances.get(model.api)) return undefined;\n\tconst provider = compatModels.getProvider(model.provider);\n\treturn provider?.getModels().some((candidate) => candidate.api === model.api) ? provider : undefined;\n}\n\nfunction resolveApiProvider(api: Api) {\n\tconst provider = getApiProvider(api);\n\tif (!provider) {\n\t\tthrow new Error(`No API provider registered for api: ${api}`);\n\t}\n\treturn provider;\n}\n\nexport function stream<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: ProviderStreamOptions,\n): AssistantMessageEventStream {\n\tconst format = getToolCallFormat(model);\n\tif (format && context.tools && context.tools.length > 0) {\n\t\tconst protocol = getProtocol(format);\n\t\tconst transformedContext = transformContext(context, protocol);\n\t\tconst innerStream = stream(model, transformedContext, options);\n\t\treturn wrapStreamWithToolCallMiddleware(innerStream, protocol, context.tools);\n\t}\n\n\tconst builtinProvider = getBuiltinProviderForModel(model);\n\tif (builtinProvider) {\n\t\tif (model.provider.startsWith(\"cloudflare-\") && !hasResolvedCloudflareAuth(options)) {\n\t\t\treturn compatModels.stream(model, context, options as ModelsApiStreamOptions<TApi> | undefined);\n\t\t}\n\t\treturn builtinProvider.stream(model, context, withEnvApiKey(model, options) as ApiStreamOptions<TApi>);\n\t}\n\tconst provider = resolveApiProvider(model.api);\n\treturn provider.stream(model, context, withEnvApiKey(model, options) as StreamOptions);\n}\n\nexport async function complete<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: ProviderStreamOptions,\n): Promise<AssistantMessage> {\n\tconst s = stream(model, context, options);\n\treturn s.result();\n}\n\nexport function streamSimple<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream {\n\tconst format = getToolCallFormat(model);\n\tif (format && context.tools && context.tools.length > 0) {\n\t\tconst protocol = getProtocol(format);\n\t\tconst transformedContext = transformContext(context, protocol);\n\t\tconst innerStream = streamSimple(model, transformedContext, options);\n\t\treturn wrapStreamWithToolCallMiddleware(innerStream, protocol, context.tools);\n\t}\n\n\tconst builtinProvider = getBuiltinProviderForModel(model);\n\tif (builtinProvider) {\n\t\tif (model.provider.startsWith(\"cloudflare-\") && !hasResolvedCloudflareAuth(options)) {\n\t\t\treturn compatModels.streamSimple(model, context, options);\n\t\t}\n\t\treturn builtinProvider.streamSimple(model, context, withEnvApiKey(model, options));\n\t}\n\tconst provider = resolveApiProvider(model.api);\n\treturn provider.streamSimple(model, context, withEnvApiKey(model, options));\n}\n\nexport async function completeSimple<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): Promise<AssistantMessage> {\n\tconst s = streamSimple(model, context, options);\n\treturn s.result();\n}\n"]}
1
+ {"version":3,"file":"compat.js","sourceRoot":"","sources":["../src/compat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,cAAc,kCAAkC,CAAC;AACjD,cAAc,sCAAsC,CAAC;AACrD,cAAc,uCAAuC,CAAC;AACtD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qCAAqC,CAAC;AACpD,cAAc,sCAAsC,CAAC;AACrD,cAAc,kCAAkC,CAAC;AACjD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC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,CAAC,CAAC;IAC/C,OAAO,QAAQ,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,KAAkB,EAClB,OAAgB,EAChB,OAA6B;IAE7B,MAAM,CAAC,GAAG,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAChD,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;AACnB,CAAC","sourcesContent":["/**\n * Temporary compatibility entrypoint preserving the old global pi-ai API\n * surface: api-dispatch `stream()`/`complete()` with env API key injection,\n * the api-registry, generated catalog reads (`getModel`/`getModels`/\n * `getProviders`), per-API lazy stream wrappers, and image generation.\n *\n * Existing apps switch imports from \"@earendil-works/pi-ai\" to\n * \"@earendil-works/pi-ai/compat\" unchanged; new code uses `createModels()`\n * and the provider factories. This module is deleted with the coding-agent\n * ModelManager migration.\n */\n\nexport * from \"./api/anthropic-messages.lazy.ts\";\nexport * from \"./api/azure-openai-responses.lazy.ts\";\nexport * from \"./api/bedrock-converse-stream.lazy.ts\";\nexport * from \"./api/cursor-agent.lazy.ts\";\nexport * from \"./api/devin-agent.lazy.ts\";\nexport * from \"./api/google-generative-ai.lazy.ts\";\nexport * from \"./api/google-vertex.lazy.ts\";\nexport * from \"./api/mistral-conversations.lazy.ts\";\nexport * from \"./api/openai-codex-responses.lazy.ts\";\nexport * from \"./api/openai-completions.lazy.ts\";\nexport * from \"./api/openai-responses.lazy.ts\";\nexport * from \"./api/pi-messages.lazy.ts\";\nexport * from \"./env-api-keys.ts\";\nexport * from \"./image-models.ts\";\nexport * from \"./images.ts\";\nexport * from \"./images-api-registry.ts\";\nexport * from \"./index.ts\";\nexport * from \"./legacy-api-aliases.ts\";\nexport * from \"./providers/images/register-builtins.ts\";\nexport {\n\tgetProtocol,\n\tgetToolCallFormat,\n\ttransformContext,\n\twrapStreamWithToolCallMiddleware,\n} from \"./tool-call-middleware/index.ts\";\n\nimport { anthropicMessagesApi } from \"./api/anthropic-messages.lazy.ts\";\nimport { azureOpenAIResponsesApi } from \"./api/azure-openai-responses.lazy.ts\";\nimport { bedrockConverseStreamApi } from \"./api/bedrock-converse-stream.lazy.ts\";\nimport { cursorAgentApi } from \"./api/cursor-agent.lazy.ts\";\nimport { devinAgentApi } from \"./api/devin-agent.lazy.ts\";\nimport { googleGenerativeAIApi } from \"./api/google-generative-ai.lazy.ts\";\nimport { googleVertexApi } from \"./api/google-vertex.lazy.ts\";\nimport { mistralConversationsApi } from \"./api/mistral-conversations.lazy.ts\";\nimport { openAICodexResponsesApi } from \"./api/openai-codex-responses.lazy.ts\";\nimport { openAICompletionsApi } from \"./api/openai-completions.lazy.ts\";\nimport { openAIResponsesApi } from \"./api/openai-responses.lazy.ts\";\nimport { piMessagesApi } from \"./api/pi-messages.lazy.ts\";\nimport { getEnvApiKey } from \"./env-api-keys.ts\";\nimport type { ModelsApiStreamOptions } from \"./models.ts\";\nimport { builtinModels, getBuiltinModel, getBuiltinModels, getBuiltinProviders } from \"./providers/all.ts\";\n\nexport type { BuiltinProvider } from \"./providers/all.ts\";\n\nimport { createFauxCore, type FauxProviderRegistration, type RegisterFauxProviderOptions } from \"./providers/faux.ts\";\nimport {\n\tgetProtocol,\n\tgetToolCallFormat,\n\ttransformContext,\n\twrapStreamWithToolCallMiddleware,\n} from \"./tool-call-middleware/index.ts\";\nimport type {\n\tApi,\n\tApiStreamOptions,\n\tAssistantMessage,\n\tAssistantMessageEventStream,\n\tContext,\n\tModel,\n\tProviderStreamOptions,\n\tProviderStreams,\n\tSimpleStreamOptions,\n\tStreamOptions,\n} from \"./types.ts\";\n\n/** @deprecated Static catalog read. Use `getBuiltinModel` from \"@earendil-works/pi-ai/providers/all\" or `Models.getModel()`. */\nexport const getModel = getBuiltinModel;\n\n/** @deprecated Static catalog read. Use `getBuiltinModels` from \"@earendil-works/pi-ai/providers/all\" or `Models.getModels()`. */\nexport const getModels = getBuiltinModels;\n\n/** @deprecated Static catalog read. Use `getBuiltinProviders` from \"@earendil-works/pi-ai/providers/all\" or `Models.getProviders()`. */\nexport const getProviders = getBuiltinProviders;\n\nexport {\n\ttype ApiProvider,\n\ttype ApiProviderInternal,\n\ttype ApiStreamFunction,\n\ttype ApiStreamSimpleFunction,\n\tgetApiProvider,\n\tgetApiProviders,\n\tregisterApiProvider,\n\tunregisterApiProviders,\n} from \"./api-registry.ts\";\n\nimport {\n\tclearApiProviders,\n\tgetApiProvider,\n\tregisterApiProvider,\n\tregisterBuiltinApiProvider,\n\tunregisterApiProviders,\n} from \"./api-registry.ts\";\n\nexport function registerFauxProvider(options: RegisterFauxProviderOptions = {}): FauxProviderRegistration {\n\tconst core = createFauxCore(options);\n\tconst sourceId = `faux-provider-${Math.random().toString(36).slice(2, 10)}`;\n\tregisterApiProvider({ api: core.api, stream: core.stream, streamSimple: core.streamSimple }, sourceId);\n\treturn {\n\t\tapi: core.api,\n\t\tmodels: core.models,\n\t\tgetModel: core.getModel,\n\t\tstate: core.state,\n\t\tsetResponses: core.setResponses,\n\t\tappendResponses: core.appendResponses,\n\t\tgetPendingResponseCount: core.getPendingResponseCount,\n\t\tgetCallLog: core.getCallLog,\n\t\tunregister() {\n\t\t\tunregisterApiProviders(sourceId);\n\t\t},\n\t};\n}\n\nconst BUILTIN_APIS: [Api, ProviderStreams][] = [\n\t[\"anthropic-messages\", anthropicMessagesApi()],\n\t[\"openai-completions\", openAICompletionsApi()],\n\t[\"openai-responses\", openAIResponsesApi()],\n\t[\"openai-codex-responses\", openAICodexResponsesApi()],\n\t[\"cursor-agent\", cursorAgentApi()],\n\t[\"devin-agent\", devinAgentApi()],\n\t[\"azure-openai-responses\", azureOpenAIResponsesApi()],\n\t[\"google-generative-ai\", googleGenerativeAIApi()],\n\t[\"google-vertex\", googleVertexApi()],\n\t[\"mistral-conversations\", mistralConversationsApi()],\n\t[\"bedrock-converse-stream\", bedrockConverseStreamApi()],\n\t[\"pi-messages\", piMessagesApi()],\n];\n\nconst builtinApiProviderInstances = new Map<Api, ReturnType<typeof getApiProvider>>();\n\n/**\n * Registers the builtin API implementations into the api-registry without\n * clobbering existing entries: compat may load after a test or extension has\n * already registered an override for a builtin api id.\n */\nexport function registerBuiltInApiProviders(): void {\n\tfor (const [api, streams] of BUILTIN_APIS) {\n\t\tregisterBuiltinApiProvider({ api, stream: streams.stream, streamSimple: streams.streamSimple });\n\t\tif (!getApiProvider(api)) {\n\t\t\tregisterApiProvider({ api, stream: streams.stream, streamSimple: streams.streamSimple });\n\t\t}\n\t\tbuiltinApiProviderInstances.set(api, getApiProvider(api));\n\t}\n}\n\nexport function resetApiProviders(): void {\n\tclearApiProviders();\n\tbuiltinApiProviderInstances.clear();\n\tregisterBuiltInApiProviders();\n}\n\nregisterBuiltInApiProviders();\n\nconst compatModels = builtinModels();\nconst AMBIENT_AUTH_MARKER = \"<authenticated>\";\n\nfunction hasExplicitApiKey(apiKey: string | undefined): apiKey is string {\n\treturn typeof apiKey === \"string\" && apiKey.trim().length > 0;\n}\n\nfunction withEnvApiKey<TOptions extends StreamOptions>(\n\tmodel: Model<Api>,\n\toptions: TOptions | undefined,\n): TOptions | undefined {\n\tif (hasExplicitApiKey(options?.apiKey)) return options;\n\tconst apiKey = getEnvApiKey(model.provider, options?.env);\n\tif (!apiKey || apiKey === AMBIENT_AUTH_MARKER) return options;\n\treturn { ...options, apiKey } as TOptions;\n}\n\nfunction hasResolvedCloudflareAuth(options: StreamOptions | undefined): boolean {\n\treturn hasExplicitApiKey(options?.apiKey) || typeof options?.headers?.[\"cf-aig-authorization\"] === \"string\";\n}\n\nfunction getBuiltinProviderForModel(model: Model<Api>) {\n\tif (getApiProvider(model.api) !== builtinApiProviderInstances.get(model.api)) return undefined;\n\tconst provider = compatModels.getProvider(model.provider);\n\treturn provider?.getModels().some((candidate) => candidate.api === model.api) ? provider : undefined;\n}\n\nfunction resolveApiProvider(api: Api) {\n\tconst provider = getApiProvider(api);\n\tif (!provider) {\n\t\tthrow new Error(`No API provider registered for api: ${api}`);\n\t}\n\treturn provider;\n}\n\nexport function stream<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: ProviderStreamOptions,\n): AssistantMessageEventStream {\n\tconst format = getToolCallFormat(model);\n\tif (format && context.tools && context.tools.length > 0) {\n\t\tconst protocol = getProtocol(format);\n\t\tconst transformedContext = transformContext(context, protocol);\n\t\tconst innerStream = stream(model, transformedContext, options);\n\t\treturn wrapStreamWithToolCallMiddleware(innerStream, protocol, context.tools);\n\t}\n\n\tconst builtinProvider = getBuiltinProviderForModel(model);\n\tif (builtinProvider) {\n\t\tif (model.provider.startsWith(\"cloudflare-\") && !hasResolvedCloudflareAuth(options)) {\n\t\t\treturn compatModels.stream(model, context, options as ModelsApiStreamOptions<TApi> | undefined);\n\t\t}\n\t\treturn builtinProvider.stream(model, context, withEnvApiKey(model, options) as ApiStreamOptions<TApi>);\n\t}\n\tconst provider = resolveApiProvider(model.api);\n\treturn provider.stream(model, context, withEnvApiKey(model, options) as StreamOptions);\n}\n\nexport async function complete<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: ProviderStreamOptions,\n): Promise<AssistantMessage> {\n\tconst s = stream(model, context, options);\n\treturn s.result();\n}\n\nexport function streamSimple<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream {\n\tconst format = getToolCallFormat(model);\n\tif (format && context.tools && context.tools.length > 0) {\n\t\tconst protocol = getProtocol(format);\n\t\tconst transformedContext = transformContext(context, protocol);\n\t\tconst innerStream = streamSimple(model, transformedContext, options);\n\t\treturn wrapStreamWithToolCallMiddleware(innerStream, protocol, context.tools);\n\t}\n\n\tconst builtinProvider = getBuiltinProviderForModel(model);\n\tif (builtinProvider) {\n\t\tif (model.provider.startsWith(\"cloudflare-\") && !hasResolvedCloudflareAuth(options)) {\n\t\t\treturn compatModels.streamSimple(model, context, options);\n\t\t}\n\t\treturn builtinProvider.streamSimple(model, context, withEnvApiKey(model, options));\n\t}\n\tconst provider = resolveApiProvider(model.api);\n\treturn provider.streamSimple(model, context, withEnvApiKey(model, options));\n}\n\nexport async function completeSimple<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): Promise<AssistantMessage> {\n\tconst s = streamSimple(model, context, options);\n\treturn s.result();\n}\n"]}
@@ -324,7 +324,7 @@ export const IMAGE_MODELS = {
324
324
  },
325
325
  "microsoft/mai-image-2.5": {
326
326
  id: "microsoft/mai-image-2.5",
327
- name: "MicrosoftAI: MAI-Image-2.5",
327
+ name: "Microsoft AI: MAI-Image-2.5",
328
328
  api: "openrouter-images",
329
329
  provider: "openrouter",
330
330
  baseUrl: "https://openrouter.ai/api/v1",
@@ -339,7 +339,7 @@ export const IMAGE_MODELS = {
339
339
  },
340
340
  "microsoft/mai-image-2.5-pro": {
341
341
  id: "microsoft/mai-image-2.5-pro",
342
- name: "MicrosoftAI: MAI-Image-2.5 Pro",
342
+ name: "Microsoft AI: MAI-Image-2.5 Pro",
343
343
  api: "openrouter-images",
344
344
  provider: "openrouter",
345
345
  baseUrl: "https://openrouter.ai/api/v1",
@@ -354,7 +354,7 @@ export const IMAGE_MODELS = {
354
354
  },
355
355
  "microsoft/mai-image-2.6": {
356
356
  id: "microsoft/mai-image-2.6",
357
- name: "MicrosoftAI: MAI-Image-2.6",
357
+ name: "Microsoft AI: MAI-Image-2.6",
358
358
  api: "openrouter-images",
359
359
  provider: "openrouter",
360
360
  baseUrl: "https://openrouter.ai/api/v1",
@@ -369,7 +369,7 @@ export const IMAGE_MODELS = {
369
369
  },
370
370
  "microsoft/mai-image-2.6-flash": {
371
371
  id: "microsoft/mai-image-2.6-flash",
372
- name: "MicrosoftAI: MAI-Image-2.6 Flash",
372
+ name: "Microsoft AI: MAI-Image-2.6 Flash",
373
373
  api: "openrouter-images",
374
374
  provider: "openrouter",
375
375
  baseUrl: "https://openrouter.ai/api/v1",