@draht/coding-agent 2026.11.5 → 2026.11.14-1

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 (328) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/dist/bundle/chunks/anthropic-messages-C5ZJVCKX.js +6 -0
  3. package/dist/bundle/chunks/{azure-openai-responses-5YLWRJ4E.js → azure-openai-responses-TNRID5YC.js} +1 -1
  4. package/dist/bundle/chunks/bedrock-converse-stream.js +22 -22
  5. package/dist/bundle/chunks/chunk-2CHTECAU.js +2 -0
  6. package/dist/bundle/chunks/{chunk-MKVW4KK2.js → chunk-2IQVBLH6.js} +1 -1
  7. package/dist/bundle/chunks/chunk-2JZLKNZ4.js +3 -0
  8. package/dist/bundle/chunks/{chunk-LJ3SEGWI.js → chunk-4FPBO5KP.js} +6 -2
  9. package/dist/bundle/chunks/{chunk-3LFBXSCO.js → chunk-5C4MAPF6.js} +1 -1
  10. package/dist/bundle/chunks/chunk-5WEOWREV.js +82 -0
  11. package/dist/bundle/chunks/chunk-6M3D4XVD.js +2 -0
  12. package/dist/bundle/chunks/{chunk-KVH4HR57.js → chunk-6WESOD4H.js} +1 -1
  13. package/dist/bundle/chunks/{chunk-UQSONZLL.js → chunk-ATYP3OSV.js} +3 -1
  14. package/dist/bundle/chunks/chunk-B6S2UR4T.js +2 -0
  15. package/dist/bundle/chunks/chunk-EBTEI43G.js +20 -0
  16. package/dist/bundle/chunks/{chunk-EXZUXBS5.js → chunk-GAABJAG4.js} +13 -16
  17. package/dist/bundle/chunks/chunk-GBFVS2SF.js +12 -0
  18. package/dist/bundle/chunks/{chunk-ITP6IDBA.js → chunk-GQXRTK54.js} +2 -2
  19. package/dist/bundle/chunks/{chunk-YUBUKEPQ.js → chunk-JHKMYVPC.js} +187 -148
  20. package/dist/bundle/chunks/{chunk-QVGSXIKT.js → chunk-KFREX3FS.js} +1 -1
  21. package/dist/bundle/chunks/{chunk-PRT3JHOZ.js → chunk-LCTFXH4P.js} +1 -1
  22. package/dist/bundle/chunks/chunk-LO6CVU2L.js +6 -0
  23. package/dist/bundle/chunks/{chunk-ABW2JATG.js → chunk-MPJIXESS.js} +1 -1
  24. package/dist/bundle/chunks/{chunk-PZKD35UB.js → chunk-MXA4WY3C.js} +1 -1
  25. package/dist/bundle/chunks/chunk-O2XYFH2E.js +30 -0
  26. package/dist/bundle/chunks/{chunk-CLNF6E5P.js → chunk-OUXJRC2W.js} +1 -1
  27. package/dist/bundle/chunks/{chunk-SKQFE2GA.js → chunk-RI7HJ6AF.js} +10 -10
  28. package/dist/bundle/chunks/chunk-RVXTPNXQ.js +44 -0
  29. package/dist/bundle/chunks/{chunk-SPVE2GM7.js → chunk-SXHVGWCU.js} +1 -1
  30. package/dist/bundle/chunks/chunk-WNZ64GW3.js +2 -0
  31. package/dist/bundle/chunks/chunk-XWZLYE4L.js +9 -0
  32. package/dist/bundle/chunks/{chunk-JAT7HEFU.js → chunk-YSE3VKKB.js} +2 -2
  33. package/dist/bundle/chunks/{cli-7AMCJ2UG.js → cli-2QKCAPPD.js} +3 -3
  34. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-QBCV2OWJ.js → cloudflare-workers-ai-system-one-UCG6T3XP.js} +1 -1
  35. package/dist/bundle/chunks/codemode-worker.js +2 -0
  36. package/dist/bundle/chunks/{execute-VOIPQMCI.js → execute-KGJOWTPG.js} +2 -2
  37. package/dist/bundle/chunks/github-copilot.js +1 -1
  38. package/dist/bundle/chunks/google-generative-ai-GPBKPOXA.js +2 -0
  39. package/dist/bundle/chunks/google-vertex-USZY53NF.js +2 -0
  40. package/dist/bundle/chunks/https-proxy-agent-WQIRL24U.js +13 -0
  41. package/dist/bundle/chunks/lib-ULKZYRGD.js +9 -0
  42. package/dist/bundle/chunks/{llama-cpp-classify-WGVYEPG2.js → llama-cpp-classify-7DEQ4ZUF.js} +1 -1
  43. package/dist/bundle/chunks/{mistral-conversations-PV6RDK65.js → mistral-conversations-UOGXPDZ3.js} +1 -1
  44. package/dist/bundle/chunks/{multipart-parser-AZP5BX2W.js → multipart-parser-HMCXZ4BD.js} +1 -1
  45. package/dist/bundle/chunks/{node-BZAVEWJ3.js → node-DXZFQBEO.js} +1 -1
  46. package/dist/bundle/chunks/{node-C2JGH2OB.js → node-LBZLUIBE.js} +1 -1
  47. package/dist/bundle/chunks/{openai-codex-responses-SEOL3EDF.js → openai-codex-responses-VUDXQ3EU.js} +1 -1
  48. package/dist/bundle/chunks/{openai-completions-U32QPS37.js → openai-completions-UQOOS7NM.js} +3 -3
  49. package/dist/bundle/chunks/{openai-decisions-ULSYFV2A.js → openai-decisions-24WNXO2R.js} +1 -1
  50. package/dist/bundle/chunks/{openai-responses-5MYZJYPK.js → openai-responses-5AF6MZ5L.js} +1 -1
  51. package/dist/bundle/chunks/{openrouter-images-SGOP5SDW.js → openrouter-images-OUXVVTYQ.js} +1 -1
  52. package/dist/bundle/chunks/{pi-messages-QALFE2BD.js → pi-messages-DRMOEO6B.js} +1 -1
  53. package/dist/bundle/chunks/{runtime-Z74VFUDD.js → runtime-FZKS2BWI.js} +1 -1
  54. package/dist/bundle/chunks/{runtime-GDH3ZURV.js → runtime-L23MZBKL.js} +1 -1
  55. package/dist/bundle/chunks/{settings-manager-T6UJFO2F.js → settings-manager-CWRQW6PZ.js} +1 -1
  56. package/dist/bundle/chunks/src-KDGO7EGF.js +4 -0
  57. package/dist/bundle/chunks/{typesafe-system-one-GTGS5MG6.js → typesafe-system-one-K63EBJDD.js} +1 -1
  58. package/dist/bundle/chunks/virtual-modules-JZV35VDE.js +2 -0
  59. package/dist/bundle/cli-runtime.js +1 -1
  60. package/dist/bundle/index.js +1 -1
  61. package/dist/bundle/rpc-entry.js +1 -1
  62. package/dist/cli/args.d.ts.map +1 -1
  63. package/dist/cli/args.js +5 -3
  64. package/dist/cli/args.js.map +1 -1
  65. package/dist/cli/auth-command.d.ts.map +1 -1
  66. package/dist/cli/auth-command.js +30 -6
  67. package/dist/cli/auth-command.js.map +1 -1
  68. package/dist/cli/auth-login.d.ts +15 -0
  69. package/dist/cli/auth-login.d.ts.map +1 -0
  70. package/dist/cli/auth-login.js +232 -0
  71. package/dist/cli/auth-login.js.map +1 -0
  72. package/dist/cli/auth-logout.d.ts +14 -0
  73. package/dist/cli/auth-logout.d.ts.map +1 -0
  74. package/dist/cli/auth-logout.js +57 -0
  75. package/dist/cli/auth-logout.js.map +1 -0
  76. package/dist/cli/auth-terminal.d.ts +17 -0
  77. package/dist/cli/auth-terminal.d.ts.map +1 -0
  78. package/dist/cli/auth-terminal.js +63 -0
  79. package/dist/cli/auth-terminal.js.map +1 -0
  80. package/dist/core/agent-session-runtime.d.ts +5 -0
  81. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  82. package/dist/core/agent-session-runtime.js +16 -2
  83. package/dist/core/agent-session-runtime.js.map +1 -1
  84. package/dist/core/agent-session.d.ts +20 -9
  85. package/dist/core/agent-session.d.ts.map +1 -1
  86. package/dist/core/agent-session.js +71 -29
  87. package/dist/core/agent-session.js.map +1 -1
  88. package/dist/core/ai-schemas.d.ts +1 -0
  89. package/dist/core/ai-schemas.d.ts.map +1 -1
  90. package/dist/core/builtins/budgets.d.ts.map +1 -1
  91. package/dist/core/builtins/budgets.js +6 -3
  92. package/dist/core/builtins/budgets.js.map +1 -1
  93. package/dist/core/cache-warmer.d.ts +4 -37
  94. package/dist/core/cache-warmer.d.ts.map +1 -1
  95. package/dist/core/cache-warmer.js +11 -91
  96. package/dist/core/cache-warmer.js.map +1 -1
  97. package/dist/core/compaction/utils.d.ts.map +1 -1
  98. package/dist/core/compaction/utils.js +2 -1
  99. package/dist/core/compaction/utils.js.map +1 -1
  100. package/dist/core/exec.d.ts +1 -0
  101. package/dist/core/exec.d.ts.map +1 -1
  102. package/dist/core/exec.js +4 -1
  103. package/dist/core/exec.js.map +1 -1
  104. package/dist/core/export-html/ansi-to-html.d.ts +5 -0
  105. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  106. package/dist/core/export-html/ansi-to-html.js +57 -20
  107. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  108. package/dist/core/export-html/template.js +1 -1
  109. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  110. package/dist/core/export-html/tool-renderer.js +2 -3
  111. package/dist/core/export-html/tool-renderer.js.map +1 -1
  112. package/dist/core/extensions/types.d.ts +3 -2
  113. package/dist/core/extensions/types.d.ts.map +1 -1
  114. package/dist/core/extensions/types.js.map +1 -1
  115. package/dist/core/model-config.d.ts +13 -0
  116. package/dist/core/model-config.d.ts.map +1 -1
  117. package/dist/core/model-resolver.d.ts +0 -1
  118. package/dist/core/model-resolver.d.ts.map +1 -1
  119. package/dist/core/model-resolver.js +17 -24
  120. package/dist/core/model-resolver.js.map +1 -1
  121. package/dist/core/model-runtime.d.ts +5 -0
  122. package/dist/core/model-runtime.d.ts.map +1 -1
  123. package/dist/core/model-runtime.js +7 -0
  124. package/dist/core/model-runtime.js.map +1 -1
  125. package/dist/core/polyphase/render/format.d.ts +2 -0
  126. package/dist/core/polyphase/render/format.d.ts.map +1 -1
  127. package/dist/core/polyphase/render/format.js +6 -0
  128. package/dist/core/polyphase/render/format.js.map +1 -1
  129. package/dist/core/polyphase/render/run-block.d.ts +4 -0
  130. package/dist/core/polyphase/render/run-block.d.ts.map +1 -1
  131. package/dist/core/polyphase/render/run-block.js +71 -12
  132. package/dist/core/polyphase/render/run-block.js.map +1 -1
  133. package/dist/core/polyphase/render/snapshot.d.ts +1 -1
  134. package/dist/core/polyphase/render/snapshot.d.ts.map +1 -1
  135. package/dist/core/polyphase/render/snapshot.js +22 -7
  136. package/dist/core/polyphase/render/snapshot.js.map +1 -1
  137. package/dist/core/polyphase/ui/dock.d.ts.map +1 -1
  138. package/dist/core/polyphase/ui/dock.js +34 -2
  139. package/dist/core/polyphase/ui/dock.js.map +1 -1
  140. package/dist/core/polyphase/ui/inspector.d.ts +18 -6
  141. package/dist/core/polyphase/ui/inspector.d.ts.map +1 -1
  142. package/dist/core/polyphase/ui/inspector.js +125 -44
  143. package/dist/core/polyphase/ui/inspector.js.map +1 -1
  144. package/dist/core/polyphase/ui/transcript-layout.d.ts.map +1 -1
  145. package/dist/core/polyphase/ui/transcript-layout.js +5 -1
  146. package/dist/core/polyphase/ui/transcript-layout.js.map +1 -1
  147. package/dist/core/preferred-providers.d.ts +17 -0
  148. package/dist/core/preferred-providers.d.ts.map +1 -0
  149. package/dist/core/preferred-providers.js +24 -0
  150. package/dist/core/preferred-providers.js.map +1 -0
  151. package/dist/core/prompt-templates.d.ts.map +1 -1
  152. package/dist/core/prompt-templates.js +18 -2
  153. package/dist/core/prompt-templates.js.map +1 -1
  154. package/dist/core/provider-composer.d.ts.map +1 -1
  155. package/dist/core/provider-composer.js +2 -0
  156. package/dist/core/provider-composer.js.map +1 -1
  157. package/dist/core/provider-matching.d.ts +6 -0
  158. package/dist/core/provider-matching.d.ts.map +1 -0
  159. package/dist/core/provider-matching.js +8 -0
  160. package/dist/core/provider-matching.js.map +1 -0
  161. package/dist/core/radius-mcp.d.ts +13 -0
  162. package/dist/core/radius-mcp.d.ts.map +1 -0
  163. package/dist/core/radius-mcp.js +29 -0
  164. package/dist/core/radius-mcp.js.map +1 -0
  165. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  166. package/dist/core/remote-catalog-provider.js +2 -0
  167. package/dist/core/remote-catalog-provider.js.map +1 -1
  168. package/dist/core/runtime-credentials.d.ts +8 -0
  169. package/dist/core/runtime-credentials.d.ts.map +1 -1
  170. package/dist/core/runtime-credentials.js +15 -1
  171. package/dist/core/runtime-credentials.js.map +1 -1
  172. package/dist/core/session-cwd.d.ts +7 -0
  173. package/dist/core/session-cwd.d.ts.map +1 -1
  174. package/dist/core/session-cwd.js +9 -1
  175. package/dist/core/session-cwd.js.map +1 -1
  176. package/dist/core/session-manager.d.ts.map +1 -1
  177. package/dist/core/session-manager.js +45 -36
  178. package/dist/core/session-manager.js.map +1 -1
  179. package/dist/core/settings-defaults.d.ts +1 -1
  180. package/dist/core/settings-defaults.d.ts.map +1 -1
  181. package/dist/core/settings-defaults.js +1 -1
  182. package/dist/core/settings-defaults.js.map +1 -1
  183. package/dist/core/tools/bash.d.ts.map +1 -1
  184. package/dist/core/tools/bash.js +35 -5
  185. package/dist/core/tools/bash.js.map +1 -1
  186. package/dist/core/tools/edit-diff.d.ts +23 -14
  187. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  188. package/dist/core/tools/edit-diff.js +182 -41
  189. package/dist/core/tools/edit-diff.js.map +1 -1
  190. package/dist/core/tools/edit.d.ts.map +1 -1
  191. package/dist/core/tools/edit.js +8 -7
  192. package/dist/core/tools/edit.js.map +1 -1
  193. package/dist/core/tools/find.d.ts.map +1 -1
  194. package/dist/core/tools/find.js +57 -16
  195. package/dist/core/tools/find.js.map +1 -1
  196. package/dist/core/tools/grep.d.ts +4 -0
  197. package/dist/core/tools/grep.d.ts.map +1 -1
  198. package/dist/core/tools/grep.js +20 -8
  199. package/dist/core/tools/grep.js.map +1 -1
  200. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  201. package/dist/core/tools/output-accumulator.js +4 -1
  202. package/dist/core/tools/output-accumulator.js.map +1 -1
  203. package/dist/core/tools/powershell.d.ts.map +1 -1
  204. package/dist/core/tools/powershell.js +15 -2
  205. package/dist/core/tools/powershell.js.map +1 -1
  206. package/dist/core/tools/read.d.ts +13 -0
  207. package/dist/core/tools/read.d.ts.map +1 -1
  208. package/dist/core/tools/read.js +146 -35
  209. package/dist/core/tools/read.js.map +1 -1
  210. package/dist/core/tools/renderers/read.d.ts.map +1 -1
  211. package/dist/core/tools/renderers/read.js +6 -2
  212. package/dist/core/tools/renderers/read.js.map +1 -1
  213. package/dist/core/tools/truncate.d.ts +4 -0
  214. package/dist/core/tools/truncate.d.ts.map +1 -1
  215. package/dist/core/tools/truncate.js +24 -1
  216. package/dist/core/tools/truncate.js.map +1 -1
  217. package/dist/extensions/codemode/execute.js +4 -4
  218. package/dist/extensions/codemode/execute.js.map +1 -1
  219. package/dist/extensions/codemode/tool.d.ts.map +1 -1
  220. package/dist/extensions/codemode/tool.js +34 -12
  221. package/dist/extensions/codemode/tool.js.map +1 -1
  222. package/dist/extensions/llama/provider.d.ts +1 -1
  223. package/dist/extensions/llama/provider.js +1 -1
  224. package/dist/extensions/llama/provider.js.map +1 -1
  225. package/dist/extensions/llama/ui.d.ts.map +1 -1
  226. package/dist/extensions/llama/ui.js +15 -3
  227. package/dist/extensions/llama/ui.js.map +1 -1
  228. package/dist/extensions/mcp/cli.js +5 -8
  229. package/dist/extensions/mcp/cli.js.map +1 -1
  230. package/dist/extensions/mcp/index.d.ts.map +1 -1
  231. package/dist/extensions/mcp/index.js +2 -1
  232. package/dist/extensions/mcp/index.js.map +1 -1
  233. package/dist/extensions/mcp/runtime.d.ts.map +1 -1
  234. package/dist/extensions/mcp/runtime.js +3 -2
  235. package/dist/extensions/mcp/runtime.js.map +1 -1
  236. package/dist/extensions/tool-search/tool.d.ts.map +1 -1
  237. package/dist/extensions/tool-search/tool.js +18 -6
  238. package/dist/extensions/tool-search/tool.js.map +1 -1
  239. package/dist/main.d.ts.map +1 -1
  240. package/dist/main.js +67 -15
  241. package/dist/main.js.map +1 -1
  242. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  243. package/dist/modes/interactive/components/login-dialog.js +2 -19
  244. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  245. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  246. package/dist/modes/interactive/components/model-selector.js +14 -6
  247. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  248. package/dist/modes/interactive/components/oauth-selector.d.ts +10 -3
  249. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  250. package/dist/modes/interactive/components/oauth-selector.js +32 -5
  251. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  252. package/dist/modes/interactive/components/provider-brand.d.ts +14 -0
  253. package/dist/modes/interactive/components/provider-brand.d.ts.map +1 -0
  254. package/dist/modes/interactive/components/provider-brand.js +66 -0
  255. package/dist/modes/interactive/components/provider-brand.js.map +1 -0
  256. package/dist/modes/interactive/components/radius-login-selector.d.ts +1 -2
  257. package/dist/modes/interactive/components/radius-login-selector.d.ts.map +1 -1
  258. package/dist/modes/interactive/components/radius-login-selector.js +6 -37
  259. package/dist/modes/interactive/components/radius-login-selector.js.map +1 -1
  260. package/dist/modes/interactive/components/session-selector.d.ts +6 -1
  261. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  262. package/dist/modes/interactive/components/session-selector.js +23 -5
  263. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  264. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  265. package/dist/modes/interactive/components/tool-execution.js +3 -1
  266. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  267. package/dist/modes/interactive/interactive-mode.d.ts +11 -1
  268. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  269. package/dist/modes/interactive/interactive-mode.js +133 -78
  270. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  271. package/dist/modes/interactive/session-share.js +2 -0
  272. package/dist/modes/interactive/session-share.js.map +1 -1
  273. package/dist/package-manager-cli.d.ts.map +1 -1
  274. package/dist/package-manager-cli.js +27 -4
  275. package/dist/package-manager-cli.js.map +1 -1
  276. package/dist/prompts/commands/test-audit.md +84 -0
  277. package/dist/utils/image-resize.d.ts.map +1 -1
  278. package/dist/utils/image-resize.js +3 -1
  279. package/dist/utils/image-resize.js.map +1 -1
  280. package/dist/utils/terminal-question.d.ts +8 -0
  281. package/dist/utils/terminal-question.d.ts.map +1 -0
  282. package/dist/utils/terminal-question.js +24 -0
  283. package/dist/utils/terminal-question.js.map +1 -0
  284. package/dist/utils/web-url.d.ts +12 -0
  285. package/dist/utils/web-url.d.ts.map +1 -0
  286. package/dist/utils/web-url.js +20 -0
  287. package/dist/utils/web-url.js.map +1 -0
  288. package/docs/cli.md +14 -1
  289. package/docs/extensions.md +6 -4
  290. package/docs/llama-cpp.md +5 -5
  291. package/docs/models-configuration.md +2 -1
  292. package/docs/nvidia-rtx-llama-cpp.md +5 -5
  293. package/docs/polyphase.md +13 -1
  294. package/docs/prompt-templates.md +1 -1
  295. package/docs/providers.md +4 -2
  296. package/docs/quickstart.md +1 -1
  297. package/docs/rpc-commands.md +1 -1
  298. package/docs/rpc.md +1 -1
  299. package/docs/sessions.md +7 -1
  300. package/docs/settings.md +1 -1
  301. package/docs/tui.md +1 -1
  302. package/examples/extensions/gondolin/index.ts +4 -7
  303. package/examples/extensions/subagent/index.ts +5 -1
  304. package/package.json +10 -10
  305. package/prompts/commands/test-audit.md +84 -0
  306. package/schemas/models.schema.json +5 -1
  307. package/schemas/settings.schema.json +1 -1
  308. package/dist/bundle/chunks/anthropic-messages-TXQXPH4S.js +0 -6
  309. package/dist/bundle/chunks/chunk-6MSE6LZ3.js +0 -6
  310. package/dist/bundle/chunks/chunk-736QBNUZ.js +0 -12
  311. package/dist/bundle/chunks/chunk-AOCWORXE.js +0 -2
  312. package/dist/bundle/chunks/chunk-BIBUE2PO.js +0 -2
  313. package/dist/bundle/chunks/chunk-DQ4G4IS4.js +0 -20
  314. package/dist/bundle/chunks/chunk-J7QTCDIN.js +0 -2
  315. package/dist/bundle/chunks/chunk-NNYZSIKR.js +0 -9
  316. package/dist/bundle/chunks/chunk-SUVMF4W5.js +0 -2
  317. package/dist/bundle/chunks/chunk-THDNEOXP.js +0 -44
  318. package/dist/bundle/chunks/chunk-TIA2T6EO.js +0 -3
  319. package/dist/bundle/chunks/chunk-TK3LS5QZ.js +0 -82
  320. package/dist/bundle/chunks/chunk-TYAEYYRA.js +0 -30
  321. package/dist/bundle/chunks/google-generative-ai-NC5KHHW3.js +0 -2
  322. package/dist/bundle/chunks/google-vertex-GAPUJEF7.js +0 -2
  323. package/dist/bundle/chunks/https-proxy-agent-O2PVUIOI.js +0 -13
  324. package/dist/bundle/chunks/lib-XOG5PI3Y.js +0 -9
  325. package/dist/bundle/chunks/src-TIBHS42X.js +0 -4
  326. package/dist/bundle/chunks/virtual-modules-ZUI2T3XR.js +0 -2
  327. /package/dist/bundle/chunks/{chunk-PX3CDFUB.js → chunk-ITKDPD4D.js} +0 -0
  328. /package/dist/bundle/chunks/{chunk-ZZD35WKM.js → chunk-MOOADNVS.js} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"provider-composer.js","sourceRoot":"","sources":["../../src/core/provider-composer.ts"],"names":[],"mappings":"AAAA,OAAO,EAYN,WAAW,EACX,UAAU,GAcV,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAE3F,OAAO,EACN,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,EACzB,qBAAqB,GACrB,MAAM,2BAA2B,CAAC;AA+EnC,MAAM,CAAC,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAEtD,SAAS,oBAAoB,CAAC,QAA8B;IAC3D,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,YAAY,EAAE,EAAE,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5E,CAAC;AAED,SAAS,WAAW,CACnB,IAA0B,EAC1B,QAAkE;IAElE,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,MAAM,MAAM,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,EAAuC,CAAC;IAC7E,MAAM,UAAU,GAAG,IAA2C,CAAC;IAC/D,MAAM,cAAc,GAAG,QAAmC,CAAC;IAC3D,MAAM,YAAY,GAAG,MAAiC,CAAC;IACvD,KAAK,MAAM,GAAG,IAAI,CAAC,mBAAmB,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,kBAAkB,CAAU,EAAE,CAAC;QACpH,MA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AC,CAAC;IAClD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,IAAI,oBAAoB,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAAC;IAC5F,MAAM,KAAK,GAAG,yBAAyB,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,uBAAuB,CAAC,KAAK,CAAC;YACpC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACtE,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC1B,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;AACvG,CAAC","sourcesContent":["import {\n\ttype AnyModel,\n\ttype Api,\n\ttype ApiKeyAuth,\n\ttype AssistantMessageEventStream,\n\ttype AuthContext,\n\ttype AuthInteraction,\n\ttype AuthResult,\n\ttype ClassifierApi,\n\ttype ClassifierModel,\n\ttype Credential,\n\ttype ImageApi,\n\tisModelType,\n\tlazyStream,\n\ttype Model,\n\ttype ModelAuth,\n\ttype OAuthAuth,\n\ttype OAuthCredentials,\n\ttype OAuthLoginCallbacks,\n\ttype Provider,\n\ttype ProviderClassifier,\n\ttype ProviderHeaders,\n\ttype ProviderImages,\n\ttype RefreshModelsContext,\n\ttype SimpleStreamOptions,\n\ttype StreamOptions,\n\ttype TranscriptContext,\n} from \"@draht/ai\";\nimport { getApiProvider } from \"@draht/ai/compat\";\nimport { classifierErrorResult, imageErrorResult } from \"@draht/ai/utils/model-operations\";\nimport type { ModelConfig, ModelsJsonModel, ModelsJsonModelOverride, ModelsJsonProvider } from \"./model-config.ts\";\nimport {\n\tclearConfigValueCache,\n\tgetConfigValueEnvVarNames,\n\tisCommandConfigValue,\n\tisConfigValueConfigured,\n\tresolveConfigValueOrThrow,\n\tresolveHeadersOrThrow,\n} from \"./resolve-config-value.ts\";\n\nexport interface ExtensionOAuthConfig {\n\tname: string;\n\t/** Whether access through this auth method is backed by a provider subscription. */\n\tisSubscription?: boolean;\n\t/** @deprecated Retained for extension source compatibility; ignored by canonical auth flows. */\n\tusesCallbackServer?: boolean;\n\tlogin(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;\n\trefreshToken(credentials: OAuthCredentials, signal: AbortSignal): Promise<OAuthCredentials>;\n\tgetApiKey(credentials: OAuthCredentials): string;\n\tmodifyModels?(models: Model<Api>[], credentials: OAuthCredentials): Model<Api>[];\n}\n\ninterface ProviderModelConfigBase {\n\tid: string;\n\tname: string;\n\tapi?: string;\n\tbaseUrl?: string;\n\tinput: (\"text\" | \"image\")[];\n\tinputLimits?: AnyModel[\"inputLimits\"];\n\tcost: AnyModel[\"cost\"];\n\theaders?: Record<string, string>;\n}\n\nexport interface ProviderChatModelConfig extends ProviderModelConfigBase {\n\ttype?: \"chat\";\n\tapi?: Api;\n\treasoning: boolean;\n\tthinkingLevelMap?: Model<Api>[\"thinkingLevelMap\"];\n\tpromptCache?: Model<Api>[\"promptCache\"];\n\tcontextWindow: number;\n\tmaxTokens: number;\n\tsamplingParams?: Model<Api>[\"samplingParams\"];\n\tsamplingParamsByThinkingLevel?: Model<Api>[\"samplingParamsByThinkingLevel\"];\n\tcompat?: Model<Api>[\"compat\"];\n}\n\nexport interface ProviderImageModelConfig extends ProviderModelConfigBase {\n\ttype: \"image\";\n\tapi?: ImageApi;\n\toutput: (\"text\" | \"image\")[];\n}\n\nexport interface ProviderClassifierModelConfig extends ProviderModelConfigBase {\n\ttype: \"classifier\";\n\tapi?: ClassifierApi;\n\tcontextWindow: number;\n\tcompat?: ClassifierModel<ClassifierApi>[\"compat\"];\n}\n\nexport type ProviderModelConfig = ProviderChatModelConfig | ProviderImageModelConfig | ProviderClassifierModelConfig;\n\n/** Input type for the extension registerProvider API. */\nexport interface ProviderConfigInput {\n\tname?: string;\n\tbaseUrl?: string;\n\tapiKey?: string;\n\tapi?: Api;\n\tstreamSimple?: (\n\t\tmodel: Model<Api>,\n\t\tcontext: TranscriptContext,\n\t\toptions?: SimpleStreamOptions,\n\t) => AssistantMessageEventStream;\n\timages?: Partial<Record<ImageApi, ProviderImages>>;\n\tclassifiers?: Partial<Record<ClassifierApi, ProviderClassifier>>;\n\theaders?: Record<string, string>;\n\tauthHeader?: boolean;\n\toauth?: ExtensionOAuthConfig;\n\tmodels?: ProviderModelConfig[];\n\trefreshModels?(context: RefreshModelsContext): Promise<ProviderModelConfig[]>;\n}\n\nexport type AuthStatus = {\n\tconfigured: boolean;\n\tsource?: \"stored\" | \"runtime\" | \"environment\" | \"fallback\" | \"models_json_key\" | \"models_json_command\";\n\tlabel?: string;\n};\n\nexport const clearApiKeyCache = clearConfigValueCache;\n\nfunction getAllProviderModels(provider: Provider | undefined): readonly AnyModel[] {\n\treturn provider ? (provider.getAllModels?.() ?? provider.getModels()) : [];\n}\n\nfunction mergeCompat(\n\tbase: Model<Api>[\"compat\"],\n\toverride: Model<Api>[\"compat\"] | ModelsJsonModelOverride[\"compat\"],\n): Model<Api>[\"compat\"] {\n\tif (!override) return base;\n\tconst merged = { ...base, ...override } as NonNullable<Model<Api>[\"compat\"]>;\n\tconst baseNested = base as Record<string, unknown> | undefined;\n\tconst overrideNested = override as Record<string, unknown>;\n\tconst mergedNested = merged as Record<string, unknown>;\n\tfor (const key of [\"openRouterRouting\", \"vercelGatewayRouting\", \"chatTemplateKwargs\", \"chatTemplateArgs\"] as const) {\n\t\tconst baseValue = baseNested?.[key];\n\t\tconst overrideValue = overrideNested[key];\n\t\tif (\n\t\t\t(typeof baseValue === \"object\" && baseValue !== null) ||\n\t\t\t(typeof overrideValue === \"object\" && overrideValue !== null)\n\t\t) {\n\t\t\tmergedNested[key] = { ...(baseValue as object | undefined), ...(overrideValue as object | undefined) };\n\t\t}\n\t}\n\treturn merged;\n}\n\nfunction mergeInputLimits(\n\tbase: Model<Api>[\"inputLimits\"],\n\toverride: ModelsJsonModelOverride[\"inputLimits\"],\n): Model<Api>[\"inputLimits\"] {\n\tif (!override) return base;\n\treturn {\n\t\t...base,\n\t\t...override,\n\t\timages: override.images\n\t\t\t? {\n\t\t\t\t\t...base?.images,\n\t\t\t\t\t...override.images,\n\t\t\t\t\tresize: override.images.resize\n\t\t\t\t\t\t? { ...base?.images?.resize, ...override.images.resize }\n\t\t\t\t\t\t: base?.images?.resize,\n\t\t\t\t}\n\t\t\t: base?.images,\n\t};\n}\n\nfunction mergeSamplingParamsByThinkingLevel(\n\tbase: Model<Api>[\"samplingParamsByThinkingLevel\"],\n\toverride: Model<Api>[\"samplingParamsByThinkingLevel\"],\n): Model<Api>[\"samplingParamsByThinkingLevel\"] {\n\tif (!override) return base;\n\tconst merged = { ...base };\n\tfor (const level of [\"off\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\"] as const) {\n\t\tconst params = override[level];\n\t\tif (params) merged[level] = { ...base?.[level], ...params };\n\t}\n\treturn merged;\n}\n\nfunction applyModelOverride(model: Model<Api>, override: ModelsJsonModelOverride): Model<Api> {\n\treturn {\n\t\t...model,\n\t\tname: override.name ?? model.name,\n\t\treasoning: override.reasoning ?? model.reasoning,\n\t\tthinkingLevelMap: override.thinkingLevelMap\n\t\t\t? { ...model.thinkingLevelMap, ...override.thinkingLevelMap }\n\t\t\t: model.thinkingLevelMap,\n\t\tinput: (override.input as (\"text\" | \"image\")[] | undefined) ?? model.input,\n\t\tinputLimits: mergeInputLimits(model.inputLimits, override.inputLimits),\n\t\tcost: override.cost\n\t\t\t? {\n\t\t\t\t\tinput: override.cost.input ?? model.cost.input,\n\t\t\t\t\toutput: override.cost.output ?? model.cost.output,\n\t\t\t\t\tcacheRead: override.cost.cacheRead ?? model.cost.cacheRead,\n\t\t\t\t\tcacheWrite: override.cost.cacheWrite ?? model.cost.cacheWrite,\n\t\t\t\t\ttiers: override.cost.tiers ?? model.cost.tiers,\n\t\t\t\t}\n\t\t\t: model.cost,\n\t\tpromptCache: override.promptCache ? { ...model.promptCache, ...override.promptCache } : model.promptCache,\n\t\tcontextWindow: override.contextWindow ?? model.contextWindow,\n\t\tmaxTokens: override.maxTokens ?? model.maxTokens,\n\t\tsamplingParams: override.samplingParams\n\t\t\t? { ...model.samplingParams, ...override.samplingParams }\n\t\t\t: model.samplingParams,\n\t\tsamplingParamsByThinkingLevel: mergeSamplingParamsByThinkingLevel(\n\t\t\tmodel.samplingParamsByThinkingLevel,\n\t\t\toverride.samplingParamsByThinkingLevel,\n\t\t),\n\t\tcompat: mergeCompat(model.compat, override.compat),\n\t};\n}\n\nfunction modelFromJson(\n\tproviderId: string,\n\tdefinition: ModelsJsonModel,\n\tproviderConfig: ModelsJsonProvider,\n\tdefaults: Model<Api> | undefined,\n): Model<Api> {\n\tconst api = definition.api ?? providerConfig.api ?? defaults?.api;\n\tif (!api) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}, model ${definition.id}: no \"api\" specified. Set at provider or model level.`,\n\t\t);\n\t}\n\tconst baseUrl = definition.baseUrl ?? providerConfig.baseUrl ?? defaults?.baseUrl;\n\tif (!baseUrl) throw new Error(`Provider ${providerId}: \"baseUrl\" is required when defining custom models.`);\n\tif (definition.contextWindow !== undefined && definition.contextWindow <= 0) {\n\t\tthrow new Error(`Provider ${providerId}, model ${definition.id}: invalid contextWindow`);\n\t}\n\tif (definition.maxTokens !== undefined && definition.maxTokens <= 0) {\n\t\tthrow new Error(`Provider ${providerId}, model ${definition.id}: invalid maxTokens`);\n\t}\n\treturn {\n\t\tid: definition.id,\n\t\tname: definition.name ?? definition.id,\n\t\tapi: api as Api,\n\t\tprovider: providerId,\n\t\tbaseUrl,\n\t\treasoning: definition.reasoning ?? false,\n\t\tthinkingLevelMap: definition.thinkingLevelMap,\n\t\tinput: (definition.input ?? [\"text\"]) as (\"text\" | \"image\")[],\n\t\tinputLimits: definition.inputLimits,\n\t\tcost: definition.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tpromptCache: definition.promptCache,\n\t\tcontextWindow: definition.contextWindow ?? 128000,\n\t\tmaxTokens: definition.maxTokens ?? 16384,\n\t\tsamplingParams: definition.samplingParams,\n\t\tsamplingParamsByThinkingLevel: definition.samplingParamsByThinkingLevel,\n\t\theaders: undefined,\n\t\tcompat: mergeCompat(providerConfig.compat, definition.compat),\n\t};\n}\n\nfunction findModelDefaults(models: readonly AnyModel[], modelId: string, api?: Api): Model<Api> | undefined {\n\tconst chatModels = models.filter((model) => isModelType(model, \"chat\"));\n\treturn (\n\t\tchatModels.find((model) => model.id === modelId) ??\n\t\t(api ? chatModels.find((model) => model.api === api) : undefined) ??\n\t\tchatModels.find((model) => model.api === \"openai-completions\") ??\n\t\tchatModels[0]\n\t);\n}\n\nfunction findExtensionModelDefaults(\n\tmodels: readonly AnyModel[],\n\tdefinition: ProviderModelConfig,\n): AnyModel | undefined {\n\tconst type = definition.type ?? \"chat\";\n\tconst candidates = models.filter((model) => isModelType(model, type));\n\treturn (\n\t\tcandidates.find((model) => model.id === definition.id) ??\n\t\t(definition.api ? candidates.find((model) => model.api === definition.api) : undefined) ??\n\t\t(type === \"chat\" ? candidates.find((model) => model.api === \"openai-completions\") : undefined) ??\n\t\tcandidates[0]\n\t);\n}\n\nfunction extensionModelFromDefinition(\n\tproviderId: string,\n\tmodels: readonly AnyModel[],\n\tconfig: ProviderConfigInput,\n\tdefinition: ProviderModelConfig,\n): AnyModel {\n\tconst type = definition.type ?? \"chat\";\n\tconst defaults = findExtensionModelDefaults(models, definition);\n\tconst api = definition.api ?? (type === \"chat\" ? config.api : undefined) ?? defaults?.api;\n\tif (!api) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}, model ${definition.id}: no \"api\" specified. Set it at model level${type === \"chat\" ? \" or provider level\" : \"\"}.`,\n\t\t);\n\t}\n\tconst baseUrl = definition.baseUrl ?? config.baseUrl ?? defaults?.baseUrl;\n\tif (!baseUrl) throw new Error(`Provider ${providerId}: \"baseUrl\" is required when defining custom models.`);\n\tif (definition.type === \"image\") {\n\t\treturn { ...definition, api: api as ImageApi, provider: providerId, baseUrl, headers: undefined };\n\t}\n\tif (definition.type === \"classifier\") {\n\t\treturn { ...definition, api: api as ClassifierApi, provider: providerId, baseUrl, headers: undefined };\n\t}\n\treturn { ...definition, api: api as Api, provider: providerId, baseUrl, headers: undefined };\n}\n\nfunction applyModelsJson(\n\tproviderId: string,\n\tbaseModels: readonly AnyModel[],\n\tconfig: ModelsJsonProvider | undefined,\n): AnyModel[] {\n\tif (!config) return [...baseModels];\n\tif (config.oauth && !config.baseUrl) {\n\t\tthrow new Error(`Provider ${providerId}: \"baseUrl\" is required when \"oauth\" is set.`);\n\t}\n\tconst hasOverrides = config.modelOverrides && Object.keys(config.modelOverrides).length > 0;\n\tif (\n\t\t!config.models?.length &&\n\t\t!config.baseUrl &&\n\t\t!config.headers &&\n\t\t!config.compat &&\n\t\t!hasOverrides &&\n\t\t!config.apiKey &&\n\t\t!config.oauth &&\n\t\tconfig.authHeader === undefined\n\t) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}: must specify \"baseUrl\", \"headers\", \"compat\", \"modelOverrides\", or \"models\".`,\n\t\t);\n\t}\n\n\tconst models: AnyModel[] = baseModels.map((model) => {\n\t\tconst baseUrl = config.oauth === \"radius\" ? model.baseUrl : (config.baseUrl ?? model.baseUrl);\n\t\tif (isModelType(model, \"chat\")) return { ...model, baseUrl, compat: mergeCompat(model.compat, config.compat) };\n\t\t// Classifier APIs read their own compat fields, such as how a System One service takes images.\n\t\tif (isModelType(model, \"classifier\") && config.compat) {\n\t\t\treturn { ...model, baseUrl, compat: { ...model.compat, ...config.compat } };\n\t\t}\n\t\treturn { ...model, baseUrl };\n\t});\n\tfor (const definition of config.models ?? []) {\n\t\tconst existingIndex = models.findIndex((model) => isModelType(model, \"chat\") && model.id === definition.id);\n\t\tconst defaults = findModelDefaults(models, definition.id, definition.api ?? config.api);\n\t\tconst model = modelFromJson(providerId, definition, config, defaults);\n\t\tif (existingIndex >= 0) models[existingIndex] = model;\n\t\telse models.push(model);\n\t}\n\treturn models;\n}\n\nfunction applyExtension(\n\tproviderId: string,\n\tmodels: readonly AnyModel[],\n\tconfig: ProviderConfigInput | undefined,\n): AnyModel[] {\n\tif (!config) return [...models];\n\tif (!config.models) {\n\t\treturn config.baseUrl ? models.map((model) => ({ ...model, baseUrl: config.baseUrl! })) : [...models];\n\t}\n\treturn config.models.map((definition) => extensionModelFromDefinition(providerId, models, config, definition));\n}\n\nfunction adaptOAuth(config: ExtensionOAuthConfig): OAuthAuth {\n\treturn {\n\t\tname: config.name,\n\t\tisSubscription: config.isSubscription,\n\t\tlogin: async (callbacks) => {\n\t\t\tconst credential = await config.login({\n\t\t\t\tonAuth: (info) => callbacks.notify({ type: \"auth_url\", ...info }),\n\t\t\t\tonDeviceCode: (info) => callbacks.notify({ type: \"device_code\", ...info }),\n\t\t\t\tonPrompt: (prompt) => callbacks.prompt({ type: \"text\", ...prompt }),\n\t\t\t\tonProgress: (message) => callbacks.notify({ type: \"progress\", message }),\n\t\t\t\tonManualCodeInput: () => callbacks.prompt({ type: \"manual_code\", message: \"Paste the authorization code\" }),\n\t\t\t\tonSelect: (prompt) => callbacks.prompt({ type: \"select\", ...prompt }),\n\t\t\t\tsignal: callbacks.signal,\n\t\t\t});\n\t\t\treturn { ...credential, type: \"oauth\" };\n\t\t},\n\t\trefresh: async (credential, signal) => ({ ...(await config.refreshToken(credential, signal)), type: \"oauth\" }),\n\t\ttoAuth: async (credential) => ({ apiKey: config.getApiKey(credential) }),\n\t};\n}\n\nfunction withConfiguredAuth(\n\tauth: ModelAuth,\n\theaders: Record<string, string> | undefined,\n\tauthHeader: boolean,\n): ModelAuth {\n\tlet mergedHeaders: ProviderHeaders | undefined =\n\t\tauth.headers || headers ? { ...auth.headers, ...headers } : undefined;\n\tif (authHeader) {\n\t\tif (!auth.apiKey) throw new Error(\"authHeader requires a resolved API key\");\n\t\tmergedHeaders = { ...mergedHeaders, Authorization: `Bearer ${auth.apiKey}` };\n\t}\n\treturn { ...auth, headers: mergedHeaders };\n}\n\nfunction configuredApiKey(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): string | undefined {\n\treturn extension?.apiKey ?? config?.apiKey;\n}\n\nfunction configuredHeaders(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): Record<string, string> | undefined {\n\tif (!config?.headers && !extension?.headers) return undefined;\n\treturn { ...config?.headers, ...extension?.headers };\n}\n\nasync function configContextEnv(\n\tvalues: readonly string[],\n\tctx: AuthContext,\n\texplicit?: Record<string, string>,\n): Promise<Record<string, string> | undefined> {\n\tconst env = { ...explicit };\n\tfor (const name of new Set(values.flatMap(getConfigValueEnvVarNames))) {\n\t\tif (env[name] !== undefined) continue;\n\t\tconst value = await ctx.env(name);\n\t\tif (value !== undefined) env[name] = value;\n\t}\n\treturn Object.keys(env).length > 0 ? env : undefined;\n}\n\nfunction composeApiKeyAuth(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): ApiKeyAuth | undefined {\n\tconst inherited = base?.auth.apiKey;\n\tconst rawKey = configuredApiKey(config, extension);\n\tconst oauth = extension?.oauth ?? base?.auth.oauth;\n\t// OAuth-only providers get no fabricated API-key login method.\n\tif (!inherited && rawKey === undefined && oauth) return undefined;\n\tconst rawHeaders = configuredHeaders(config, extension);\n\tconst authHeader = extension?.authHeader ?? config?.authHeader ?? false;\n\treturn {\n\t\tname: inherited?.name ?? \"API key\",\n\t\tlogin:\n\t\t\tinherited?.login ??\n\t\t\t(async (interaction: AuthInteraction) => ({\n\t\t\t\ttype: \"api_key\",\n\t\t\t\tkey: await interaction.prompt({ type: \"secret\", message: \"Enter API key\" }),\n\t\t\t})),\n\t\tcheck: async (input) => {\n\t\t\tif (input.credential) {\n\t\t\t\tif (inherited?.check) return inherited.check(input);\n\t\t\t\tif (input.credential.key) return { type: \"api_key\", source: \"stored credential\" };\n\t\t\t\tconst resolved = await inherited?.resolve(input);\n\t\t\t\treturn resolved ? { type: \"api_key\", source: resolved.source } : undefined;\n\t\t\t}\n\t\t\tif (rawKey !== undefined) {\n\t\t\t\tif (isCommandConfigValue(rawKey)) return { type: \"api_key\", source: \"configured API key\" };\n\t\t\t\tconst envNames = getConfigValueEnvVarNames(rawKey);\n\t\t\t\tfor (const name of envNames) {\n\t\t\t\t\tif ((await input.ctx.env(name)) === undefined) return undefined;\n\t\t\t\t}\n\t\t\t\treturn { type: \"api_key\", source: \"configured API key\" };\n\t\t\t}\n\t\t\tif (inherited?.check) return inherited.check(input);\n\t\t\tconst resolved = await inherited?.resolve(input);\n\t\t\treturn resolved ? { type: \"api_key\", source: resolved.source } : undefined;\n\t\t},\n\t\tresolve: async (input) => {\n\t\t\tlet result: AuthResult | undefined;\n\t\t\tif (input.credential) {\n\t\t\t\tresult = inherited\n\t\t\t\t\t? await inherited.resolve(input)\n\t\t\t\t\t: input.credential.key\n\t\t\t\t\t\t? { auth: { apiKey: input.credential.key }, env: input.credential.env, source: \"stored credential\" }\n\t\t\t\t\t\t: undefined;\n\t\t\t} else if (rawKey !== undefined) {\n\t\t\t\tconst env = await configContextEnv([rawKey], input.ctx);\n\t\t\t\tconst key = resolveConfigValueOrThrow(rawKey, `API key for provider \"${providerId}\"`, env);\n\t\t\t\tresult = inherited\n\t\t\t\t\t? await inherited.resolve({ ...input, credential: { type: \"api_key\", key } })\n\t\t\t\t\t: { auth: { apiKey: key }, source: \"configured API key\" };\n\t\t\t} else {\n\t\t\t\tresult = await inherited?.resolve(input);\n\t\t\t}\n\t\t\tif (!result) return undefined;\n\t\t\tconst explicitEnv = { ...(input.credential?.env ?? {}), ...(result.env ?? {}) };\n\t\t\tconst headerEnv = await configContextEnv(Object.values(rawHeaders ?? {}), input.ctx, explicitEnv);\n\t\t\tconst headers = resolveHeadersOrThrow(rawHeaders, `provider \"${providerId}\"`, headerEnv);\n\t\t\treturn { ...result, auth: withConfiguredAuth(result.auth, headers, authHeader) };\n\t\t},\n\t};\n}\n\nfunction composeOAuthAuth(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): OAuthAuth | undefined {\n\tconst oauth = extension?.oauth ? adaptOAuth(extension.oauth) : base?.auth.oauth;\n\tif (!oauth) return undefined;\n\tconst rawHeaders = configuredHeaders(config, extension);\n\tconst authHeader = extension?.authHeader ?? config?.authHeader ?? false;\n\treturn {\n\t\t...oauth,\n\t\ttoAuth: async (credential) => {\n\t\t\tconst auth = await oauth.toAuth(credential);\n\t\t\tconst env = credential.env;\n\t\t\tconst headers = resolveHeadersOrThrow(\n\t\t\t\trawHeaders,\n\t\t\t\t`provider \"${providerId}\"`,\n\t\t\t\ttypeof env === \"object\" && env !== null ? (env as Record<string, string>) : undefined,\n\t\t\t);\n\t\t\treturn withConfiguredAuth(auth, headers, authHeader);\n\t\t},\n\t};\n}\n\nfunction rawModelHeaders(\n\tmodel: AnyModel,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): Record<string, string> | undefined {\n\t// models.json definitions and overrides are chat-only. Extension definitions\n\t// are matched by operation and id so colliding models cannot share headers.\n\tconst chatDefinition = isModelType(model, \"chat\")\n\t\t? config?.models?.find((entry) => entry.id === model.id)\n\t\t: undefined;\n\tconst extensionModel = extension?.models?.find(\n\t\t(entry) => (entry.type ?? \"chat\") === (model.type ?? \"chat\") && entry.id === model.id,\n\t);\n\tconst headers = {\n\t\t...(isModelType(model, \"chat\") ? config?.modelOverrides?.[model.id]?.headers : undefined),\n\t\t...chatDefinition?.headers,\n\t\t...extensionModel?.headers,\n\t};\n\treturn Object.keys(headers).length > 0 ? headers : undefined;\n}\n\nexport function validateExtensionProvider(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tmodelsConfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput,\n): void {\n\tif (extension.streamSimple && !extension.api) {\n\t\tthrow new Error(`Provider ${providerId}: \"api\" is required when registering streamSimple.`);\n\t}\n\tapplyExtension(providerId, applyModelsJson(providerId, getAllProviderModels(base), modelsConfig), extension);\n}\n\n/** Compose built-in, models.json, and extension layers without reading credentials. */\nexport function composeModelProvider(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tmodelConfig: ModelConfig,\n\textension: ProviderConfigInput | undefined,\n): Provider {\n\tconst config = modelConfig.getProvider(providerId);\n\tlet extensionOAuthCredential: OAuthCredentials | undefined;\n\tlet refreshedExtensionModels: ProviderConfigInput[\"models\"];\n\tconst currentExtension = (): ProviderConfigInput | undefined =>\n\t\textension && refreshedExtensionModels ? { ...extension, models: refreshedExtensionModels } : extension;\n\t// models.json modelOverrides are the topmost user-config layer: they apply once,\n\t// after custom-model upserts, extension model replacement, and legacy OAuth projection.\n\tconst getAllModels = (): AnyModel[] => {\n\t\tlet models = applyExtension(\n\t\t\tproviderId,\n\t\t\tapplyModelsJson(providerId, getAllProviderModels(base), config),\n\t\t\tcurrentExtension(),\n\t\t);\n\t\tif (extensionOAuthCredential && extension?.oauth?.modifyModels) {\n\t\t\t// The extension hook is chat-only; other model types pass through untouched.\n\t\t\tmodels = [\n\t\t\t\t...extension.oauth.modifyModels(\n\t\t\t\t\tmodels.filter((model) => isModelType(model, \"chat\")),\n\t\t\t\t\textensionOAuthCredential,\n\t\t\t\t),\n\t\t\t\t...models.filter((model) => !isModelType(model, \"chat\")),\n\t\t\t];\n\t\t}\n\t\treturn models.map((model) => {\n\t\t\tconst override = config?.modelOverrides?.[model.id];\n\t\t\treturn override && isModelType(model, \"chat\") ? applyModelOverride(model, override) : model;\n\t\t});\n\t};\n\t// Validate eagerly so registration/reload reports structural errors immediately.\n\tgetAllModels();\n\tconst apiKey = composeApiKeyAuth(providerId, base, config, extension);\n\tconst oauth = composeOAuthAuth(providerId, base, config, extension);\n\tif (!apiKey && !oauth) throw new Error(`Provider ${providerId}: no authentication method configured.`);\n\n\tconst supportsBaseApi = (model: Model<Api>) => base?.getModels().some((entry) => entry.api === model.api) ?? false;\n\tconst streamWith = (\n\t\tmodel: Model<Api>,\n\t\tcontext: TranscriptContext,\n\t\toptions: StreamOptions | undefined,\n\t\tsimple: boolean,\n\t): AssistantMessageEventStream =>\n\t\tlazyStream(\n\t\t\tmodel,\n\t\t\tasync () => {\n\t\t\t\tif (extension?.streamSimple && model.api === extension.api) {\n\t\t\t\t\treturn extension.streamSimple(model, context, options as SimpleStreamOptions);\n\t\t\t\t}\n\t\t\t\tif (base && supportsBaseApi(model)) {\n\t\t\t\t\treturn simple\n\t\t\t\t\t\t? base.streamSimple(model, context, options as SimpleStreamOptions)\n\t\t\t\t\t\t: base.stream(model, context, options);\n\t\t\t\t}\n\t\t\t\tconst api = getApiProvider(model.api);\n\t\t\t\tif (!api) throw new Error(`No API provider registered for api: ${model.api}`);\n\t\t\t\treturn simple\n\t\t\t\t\t? api.streamSimple(model, context, options as SimpleStreamOptions)\n\t\t\t\t\t: api.stream(model, context, options);\n\t\t\t},\n\t\t\tundefined,\n\t\t\toptions?.signal,\n\t\t);\n\n\tconst provider: Provider = {\n\t\tid: providerId,\n\t\tname: extension?.name ?? config?.name ?? base?.name ?? extension?.oauth?.name ?? providerId,\n\t\tbaseUrl: extension?.baseUrl ?? config?.baseUrl ?? base?.baseUrl,\n\t\theaders: base?.headers,\n\t\tauth: { ...(apiKey ? { apiKey } : {}), ...(oauth ? { oauth } : {}) },\n\t\tgetModels: () => getAllModels().filter((model) => isModelType(model, \"chat\")),\n\t\tgetAllModels,\n\t\trefreshModels:\n\t\t\tbase?.refreshModels || extension?.refreshModels || extension?.oauth?.modifyModels\n\t\t\t\t? async (context) => {\n\t\t\t\t\t\tawait base?.refreshModels?.(context);\n\t\t\t\t\t\tlet refreshed: NonNullable<ProviderConfigInput[\"models\"]> | undefined;\n\t\t\t\t\t\tif (extension?.refreshModels) refreshed = await extension.refreshModels(context);\n\t\t\t\t\t\tif (context.signal.aborted) return;\n\t\t\t\t\t\tconst oauthCredential = context.credential?.type === \"oauth\" ? context.credential : undefined;\n\t\t\t\t\t\tawait context.publish({\n\t\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\t\tif (refreshed) {\n\t\t\t\t\t\t\t\t\t// Validate before publishing the new synchronous list.\n\t\t\t\t\t\t\t\t\tapplyExtension(providerId, applyModelsJson(providerId, getAllProviderModels(base), config), {\n\t\t\t\t\t\t\t\t\t\t...extension,\n\t\t\t\t\t\t\t\t\t\tmodels: refreshed,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\trefreshedExtensionModels = refreshed;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\textensionOAuthCredential = oauthCredential;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\tfilterModels: base?.filterModels\n\t\t\t? (models, credential: Credential | undefined) => base.filterModels!(models, credential)\n\t\t\t: undefined,\n\t\tfilterAllModels: base?.filterAllModels\n\t\t\t? (models, credential: Credential | undefined) => base.filterAllModels!(models, credential)\n\t\t\t: undefined,\n\t\tstream: (model, context, options) => streamWith(model, context, options, false),\n\t\tstreamSimple: (model, context, options) => streamWith(model, context, options, true),\n\t};\n\n\tconst fetchDeferred = base?.fetchDeferred;\n\tif (fetchDeferred) {\n\t\tprovider.fetchDeferred = (model, handle, options) => fetchDeferred(model, handle, options);\n\t}\n\tconst cancelDeferred = base?.cancelDeferred;\n\tif (cancelDeferred) {\n\t\tprovider.cancelDeferred = (model, handle, options) => cancelDeferred(model, handle, options);\n\t}\n\tconst extensionImages = extension?.images;\n\tconst generateImages = base?.generateImages;\n\tif (generateImages || Object.keys(extensionImages ?? {}).length > 0) {\n\t\tprovider.generateImages = (model, context, options) => {\n\t\t\tconst implementation = extensionImages?.[model.api];\n\t\t\tif (implementation) return implementation.generateImages(model, context, options);\n\t\t\tif (generateImages) return generateImages(model, context, options);\n\t\t\treturn Promise.resolve(\n\t\t\t\timageErrorResult(model, new Error(`Provider ${providerId} has no image implementation for \"${model.api}\"`)),\n\t\t\t);\n\t\t};\n\t}\n\tconst extensionClassifiers = extension?.classifiers;\n\tconst classify = base?.classify;\n\tif (classify || Object.keys(extensionClassifiers ?? {}).length > 0) {\n\t\tprovider.classify = (model, context, options) => {\n\t\t\tconst implementation = extensionClassifiers?.[model.api];\n\t\t\tif (implementation) return implementation.classify(model, context, options);\n\t\t\tif (classify) return classify(model, context, options);\n\t\t\treturn Promise.resolve(\n\t\t\t\tclassifierErrorResult(\n\t\t\t\t\tmodel,\n\t\t\t\t\tnew Error(`Provider ${providerId} has no classifier implementation for \"${model.api}\"`),\n\t\t\t\t),\n\t\t\t);\n\t\t};\n\t}\n\n\treturn provider;\n}\n\nexport function resolveConfiguredModelHeaders(\n\tmodel: AnyModel,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n\tenv?: Record<string, string>,\n): Record<string, string> | undefined {\n\treturn resolveHeadersOrThrow(\n\t\trawModelHeaders(model, config, extension),\n\t\t`model \"${model.provider}/${model.id}\"`,\n\t\tenv,\n\t);\n}\n\nexport interface CompatibilityRequestConfig {\n\theaders?: ProviderHeaders;\n\tauthHeader: boolean;\n}\n\nexport function resolveCompatibilityRequestConfig(\n\tmodel: AnyModel,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): CompatibilityRequestConfig {\n\tconst configured = resolveHeadersOrThrow(\n\t\t{ ...configuredHeaders(config, extension), ...rawModelHeaders(model, config, extension) },\n\t\t`model \"${model.provider}/${model.id}\"`,\n\t);\n\treturn {\n\t\theaders: model.headers || configured ? { ...model.headers, ...configured } : undefined,\n\t\tauthHeader: extension?.authHeader ?? config?.authHeader ?? false,\n\t};\n}\n\nexport function configuredRequestAuthStatus(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): AuthStatus | undefined {\n\tconst value = configuredApiKey(config, extension);\n\tif (value === undefined) return undefined;\n\tif (isCommandConfigValue(value)) return { configured: true, source: \"models_json_command\" };\n\tconst names = getConfigValueEnvVarNames(value);\n\tif (names.length > 0) {\n\t\treturn isConfigValueConfigured(value)\n\t\t\t? { configured: true, source: \"environment\", label: names.join(\", \") }\n\t\t\t: { configured: false };\n\t}\n\treturn { configured: true, source: extension?.apiKey !== undefined ? \"fallback\" : \"models_json_key\" };\n}\n"]}
1
+ {"version":3,"file":"provider-composer.js","sourceRoot":"","sources":["../../src/core/provider-composer.ts"],"names":[],"mappings":"AAAA,OAAO,EAYN,WAAW,EACX,UAAU,GAcV,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAE3F,OAAO,EACN,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,EACzB,qBAAqB,GACrB,MAAM,2BAA2B,CAAC;AA+EnC,MAAM,CAAC,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAEtD,SAAS,oBAAoB,CAAC,QAA8B;IAC3D,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,YAAY,EAAE,EAAE,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5E,CAAC;AAED,SAAS,WAAW,CACnB,IAA0B,EAC1B,QAAkE;IAElE,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,MAAM,MAAM,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,EAA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AAC,EAAE,GAAG,CACvC,CAAC;IACF,OAAO;QACN,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS;QACtF,UAAU,EAAE,SAAS,EAAE,UAAU,IAAI,MAAM,EAAE,UAAU,IAAI,KAAK;KAChE,CAAC;AACH,CAAC;AAED,MAAM,UAAU,2BAA2B,CAC1C,MAAsC,EACtC,SAA0C;IAE1C,MAAM,KAAK,GAAG,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAClD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,IAAI,oBAAoB,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAAC;IAC5F,MAAM,KAAK,GAAG,yBAAyB,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,uBAAuB,CAAC,KAAK,CAAC;YACpC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACtE,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC1B,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;AACvG,CAAC","sourcesContent":["import {\n\ttype AnyModel,\n\ttype Api,\n\ttype ApiKeyAuth,\n\ttype AssistantMessageEventStream,\n\ttype AuthContext,\n\ttype AuthInteraction,\n\ttype AuthResult,\n\ttype ClassifierApi,\n\ttype ClassifierModel,\n\ttype Credential,\n\ttype ImageApi,\n\tisModelType,\n\tlazyStream,\n\ttype Model,\n\ttype ModelAuth,\n\ttype OAuthAuth,\n\ttype OAuthCredentials,\n\ttype OAuthLoginCallbacks,\n\ttype Provider,\n\ttype ProviderClassifier,\n\ttype ProviderHeaders,\n\ttype ProviderImages,\n\ttype RefreshModelsContext,\n\ttype SimpleStreamOptions,\n\ttype StreamOptions,\n\ttype TranscriptContext,\n} from \"@draht/ai\";\nimport { getApiProvider } from \"@draht/ai/compat\";\nimport { classifierErrorResult, imageErrorResult } from \"@draht/ai/utils/model-operations\";\nimport type { ModelConfig, ModelsJsonModel, ModelsJsonModelOverride, ModelsJsonProvider } from \"./model-config.ts\";\nimport {\n\tclearConfigValueCache,\n\tgetConfigValueEnvVarNames,\n\tisCommandConfigValue,\n\tisConfigValueConfigured,\n\tresolveConfigValueOrThrow,\n\tresolveHeadersOrThrow,\n} from \"./resolve-config-value.ts\";\n\nexport interface ExtensionOAuthConfig {\n\tname: string;\n\t/** Whether access through this auth method is backed by a provider subscription. */\n\tisSubscription?: boolean;\n\t/** @deprecated Retained for extension source compatibility; ignored by canonical auth flows. */\n\tusesCallbackServer?: boolean;\n\tlogin(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;\n\trefreshToken(credentials: OAuthCredentials, signal: AbortSignal): Promise<OAuthCredentials>;\n\tgetApiKey(credentials: OAuthCredentials): string;\n\tmodifyModels?(models: Model<Api>[], credentials: OAuthCredentials): Model<Api>[];\n}\n\ninterface ProviderModelConfigBase {\n\tid: string;\n\tname: string;\n\tapi?: string;\n\tbaseUrl?: string;\n\tinput: (\"text\" | \"image\")[];\n\tinputLimits?: AnyModel[\"inputLimits\"];\n\tcost: AnyModel[\"cost\"];\n\theaders?: Record<string, string>;\n}\n\nexport interface ProviderChatModelConfig extends ProviderModelConfigBase {\n\ttype?: \"chat\";\n\tapi?: Api;\n\treasoning: boolean;\n\tthinkingLevelMap?: Model<Api>[\"thinkingLevelMap\"];\n\tpromptCache?: Model<Api>[\"promptCache\"];\n\tcontextWindow: number;\n\tmaxTokens: number;\n\tsamplingParams?: Model<Api>[\"samplingParams\"];\n\tsamplingParamsByThinkingLevel?: Model<Api>[\"samplingParamsByThinkingLevel\"];\n\tcompat?: Model<Api>[\"compat\"];\n}\n\nexport interface ProviderImageModelConfig extends ProviderModelConfigBase {\n\ttype: \"image\";\n\tapi?: ImageApi;\n\toutput: (\"text\" | \"image\")[];\n}\n\nexport interface ProviderClassifierModelConfig extends ProviderModelConfigBase {\n\ttype: \"classifier\";\n\tapi?: ClassifierApi;\n\tcontextWindow: number;\n\tcompat?: ClassifierModel<ClassifierApi>[\"compat\"];\n}\n\nexport type ProviderModelConfig = ProviderChatModelConfig | ProviderImageModelConfig | ProviderClassifierModelConfig;\n\n/** Input type for the extension registerProvider API. */\nexport interface ProviderConfigInput {\n\tname?: string;\n\tbaseUrl?: string;\n\tapiKey?: string;\n\tapi?: Api;\n\tstreamSimple?: (\n\t\tmodel: Model<Api>,\n\t\tcontext: TranscriptContext,\n\t\toptions?: SimpleStreamOptions,\n\t) => AssistantMessageEventStream;\n\timages?: Partial<Record<ImageApi, ProviderImages>>;\n\tclassifiers?: Partial<Record<ClassifierApi, ProviderClassifier>>;\n\theaders?: Record<string, string>;\n\tauthHeader?: boolean;\n\toauth?: ExtensionOAuthConfig;\n\tmodels?: ProviderModelConfig[];\n\trefreshModels?(context: RefreshModelsContext): Promise<ProviderModelConfig[]>;\n}\n\nexport type AuthStatus = {\n\tconfigured: boolean;\n\tsource?: \"stored\" | \"runtime\" | \"environment\" | \"fallback\" | \"models_json_key\" | \"models_json_command\";\n\tlabel?: string;\n};\n\nexport const clearApiKeyCache = clearConfigValueCache;\n\nfunction getAllProviderModels(provider: Provider | undefined): readonly AnyModel[] {\n\treturn provider ? (provider.getAllModels?.() ?? provider.getModels()) : [];\n}\n\nfunction mergeCompat(\n\tbase: Model<Api>[\"compat\"],\n\toverride: Model<Api>[\"compat\"] | ModelsJsonModelOverride[\"compat\"],\n): Model<Api>[\"compat\"] {\n\tif (!override) return base;\n\tconst merged = { ...base, ...override } as NonNullable<Model<Api>[\"compat\"]>;\n\tconst baseNested = base as Record<string, unknown> | undefined;\n\tconst overrideNested = override as Record<string, unknown>;\n\tconst mergedNested = merged as Record<string, unknown>;\n\tfor (const key of [\"openRouterRouting\", \"vercelGatewayRouting\", \"chatTemplateKwargs\", \"chatTemplateArgs\"] as const) {\n\t\tconst baseValue = baseNested?.[key];\n\t\tconst overrideValue = overrideNested[key];\n\t\tif (\n\t\t\t(typeof baseValue === \"object\" && baseValue !== null) ||\n\t\t\t(typeof overrideValue === \"object\" && overrideValue !== null)\n\t\t) {\n\t\t\tmergedNested[key] = { ...(baseValue as object | undefined), ...(overrideValue as object | undefined) };\n\t\t}\n\t}\n\treturn merged;\n}\n\nfunction mergeInputLimits(\n\tbase: Model<Api>[\"inputLimits\"],\n\toverride: ModelsJsonModelOverride[\"inputLimits\"],\n): Model<Api>[\"inputLimits\"] {\n\tif (!override) return base;\n\treturn {\n\t\t...base,\n\t\t...override,\n\t\timages: override.images\n\t\t\t? {\n\t\t\t\t\t...base?.images,\n\t\t\t\t\t...override.images,\n\t\t\t\t\tresize: override.images.resize\n\t\t\t\t\t\t? { ...base?.images?.resize, ...override.images.resize }\n\t\t\t\t\t\t: base?.images?.resize,\n\t\t\t\t}\n\t\t\t: base?.images,\n\t};\n}\n\nfunction mergeSamplingParamsByThinkingLevel(\n\tbase: Model<Api>[\"samplingParamsByThinkingLevel\"],\n\toverride: Model<Api>[\"samplingParamsByThinkingLevel\"],\n): Model<Api>[\"samplingParamsByThinkingLevel\"] {\n\tif (!override) return base;\n\tconst merged = { ...base };\n\tfor (const level of [\"off\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\"] as const) {\n\t\tconst params = override[level];\n\t\tif (params) merged[level] = { ...base?.[level], ...params };\n\t}\n\treturn merged;\n}\n\nfunction applyModelOverride(model: Model<Api>, override: ModelsJsonModelOverride): Model<Api> {\n\treturn {\n\t\t...model,\n\t\tname: override.name ?? model.name,\n\t\treasoning: override.reasoning ?? model.reasoning,\n\t\tthinkingLevelMap: override.thinkingLevelMap\n\t\t\t? { ...model.thinkingLevelMap, ...override.thinkingLevelMap }\n\t\t\t: model.thinkingLevelMap,\n\t\tinput: (override.input as (\"text\" | \"image\")[] | undefined) ?? model.input,\n\t\tinputLimits: mergeInputLimits(model.inputLimits, override.inputLimits),\n\t\tcost: override.cost\n\t\t\t? {\n\t\t\t\t\tinput: override.cost.input ?? model.cost.input,\n\t\t\t\t\toutput: override.cost.output ?? model.cost.output,\n\t\t\t\t\tcacheRead: override.cost.cacheRead ?? model.cost.cacheRead,\n\t\t\t\t\tcacheWrite: override.cost.cacheWrite ?? model.cost.cacheWrite,\n\t\t\t\t\ttiers: override.cost.tiers ?? model.cost.tiers,\n\t\t\t\t}\n\t\t\t: model.cost,\n\t\tpromptCache: override.promptCache ? { ...model.promptCache, ...override.promptCache } : model.promptCache,\n\t\tcontextWindow: override.contextWindow ?? model.contextWindow,\n\t\tmaxTokens: override.maxTokens ?? model.maxTokens,\n\t\tsamplingParams: override.samplingParams\n\t\t\t? { ...model.samplingParams, ...override.samplingParams }\n\t\t\t: model.samplingParams,\n\t\tsamplingParamsByThinkingLevel: mergeSamplingParamsByThinkingLevel(\n\t\t\tmodel.samplingParamsByThinkingLevel,\n\t\t\toverride.samplingParamsByThinkingLevel,\n\t\t),\n\t\tcompat: mergeCompat(model.compat, override.compat),\n\t};\n}\n\nfunction modelFromJson(\n\tproviderId: string,\n\tdefinition: ModelsJsonModel,\n\tproviderConfig: ModelsJsonProvider,\n\tdefaults: Model<Api> | undefined,\n): Model<Api> {\n\tconst api = definition.api ?? providerConfig.api ?? defaults?.api;\n\tif (!api) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}, model ${definition.id}: no \"api\" specified. Set at provider or model level.`,\n\t\t);\n\t}\n\tconst baseUrl = definition.baseUrl ?? providerConfig.baseUrl ?? defaults?.baseUrl;\n\tif (!baseUrl) throw new Error(`Provider ${providerId}: \"baseUrl\" is required when defining custom models.`);\n\tif (definition.contextWindow !== undefined && definition.contextWindow <= 0) {\n\t\tthrow new Error(`Provider ${providerId}, model ${definition.id}: invalid contextWindow`);\n\t}\n\tif (definition.maxTokens !== undefined && definition.maxTokens <= 0) {\n\t\tthrow new Error(`Provider ${providerId}, model ${definition.id}: invalid maxTokens`);\n\t}\n\treturn {\n\t\tid: definition.id,\n\t\tname: definition.name ?? definition.id,\n\t\tapi: api as Api,\n\t\tprovider: providerId,\n\t\tbaseUrl,\n\t\treasoning: definition.reasoning ?? false,\n\t\tthinkingLevelMap: definition.thinkingLevelMap,\n\t\tinput: (definition.input ?? [\"text\"]) as (\"text\" | \"image\")[],\n\t\tinputLimits: definition.inputLimits,\n\t\tcost: definition.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tpromptCache: definition.promptCache,\n\t\tcontextWindow: definition.contextWindow ?? 128000,\n\t\tmaxTokens: definition.maxTokens ?? 16384,\n\t\tsamplingParams: definition.samplingParams,\n\t\tsamplingParamsByThinkingLevel: definition.samplingParamsByThinkingLevel,\n\t\theaders: undefined,\n\t\tcompat: mergeCompat(providerConfig.compat, definition.compat),\n\t};\n}\n\nfunction findModelDefaults(models: readonly AnyModel[], modelId: string, api?: Api): Model<Api> | undefined {\n\tconst chatModels = models.filter((model) => isModelType(model, \"chat\"));\n\treturn (\n\t\tchatModels.find((model) => model.id === modelId) ??\n\t\t(api ? chatModels.find((model) => model.api === api) : undefined) ??\n\t\tchatModels.find((model) => model.api === \"openai-completions\") ??\n\t\tchatModels[0]\n\t);\n}\n\nfunction findExtensionModelDefaults(\n\tmodels: readonly AnyModel[],\n\tdefinition: ProviderModelConfig,\n): AnyModel | undefined {\n\tconst type = definition.type ?? \"chat\";\n\tconst candidates = models.filter((model) => isModelType(model, type));\n\treturn (\n\t\tcandidates.find((model) => model.id === definition.id) ??\n\t\t(definition.api ? candidates.find((model) => model.api === definition.api) : undefined) ??\n\t\t(type === \"chat\" ? candidates.find((model) => model.api === \"openai-completions\") : undefined) ??\n\t\tcandidates[0]\n\t);\n}\n\nfunction extensionModelFromDefinition(\n\tproviderId: string,\n\tmodels: readonly AnyModel[],\n\tconfig: ProviderConfigInput,\n\tdefinition: ProviderModelConfig,\n): AnyModel {\n\tconst type = definition.type ?? \"chat\";\n\tconst defaults = findExtensionModelDefaults(models, definition);\n\tconst api = definition.api ?? (type === \"chat\" ? config.api : undefined) ?? defaults?.api;\n\tif (!api) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}, model ${definition.id}: no \"api\" specified. Set it at model level${type === \"chat\" ? \" or provider level\" : \"\"}.`,\n\t\t);\n\t}\n\tconst baseUrl = definition.baseUrl ?? config.baseUrl ?? defaults?.baseUrl;\n\tif (!baseUrl) throw new Error(`Provider ${providerId}: \"baseUrl\" is required when defining custom models.`);\n\tif (definition.type === \"image\") {\n\t\treturn { ...definition, api: api as ImageApi, provider: providerId, baseUrl, headers: undefined };\n\t}\n\tif (definition.type === \"classifier\") {\n\t\treturn { ...definition, api: api as ClassifierApi, provider: providerId, baseUrl, headers: undefined };\n\t}\n\treturn { ...definition, api: api as Api, provider: providerId, baseUrl, headers: undefined };\n}\n\nfunction applyModelsJson(\n\tproviderId: string,\n\tbaseModels: readonly AnyModel[],\n\tconfig: ModelsJsonProvider | undefined,\n): AnyModel[] {\n\tif (!config) return [...baseModels];\n\tif (config.oauth && !config.baseUrl) {\n\t\tthrow new Error(`Provider ${providerId}: \"baseUrl\" is required when \"oauth\" is set.`);\n\t}\n\tconst hasOverrides = config.modelOverrides && Object.keys(config.modelOverrides).length > 0;\n\tif (\n\t\t!config.models?.length &&\n\t\t!config.baseUrl &&\n\t\t!config.headers &&\n\t\t!config.compat &&\n\t\t!hasOverrides &&\n\t\t!config.apiKey &&\n\t\t!config.oauth &&\n\t\tconfig.authHeader === undefined\n\t) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}: must specify \"baseUrl\", \"headers\", \"compat\", \"modelOverrides\", or \"models\".`,\n\t\t);\n\t}\n\n\tconst models: AnyModel[] = baseModels.map((model) => {\n\t\tconst baseUrl = config.oauth === \"radius\" ? model.baseUrl : (config.baseUrl ?? model.baseUrl);\n\t\tif (isModelType(model, \"chat\")) return { ...model, baseUrl, compat: mergeCompat(model.compat, config.compat) };\n\t\t// Classifier APIs read their own compat fields, such as how a System One service takes images.\n\t\tif (isModelType(model, \"classifier\") && config.compat) {\n\t\t\treturn { ...model, baseUrl, compat: { ...model.compat, ...config.compat } };\n\t\t}\n\t\treturn { ...model, baseUrl };\n\t});\n\tfor (const definition of config.models ?? []) {\n\t\tconst existingIndex = models.findIndex((model) => isModelType(model, \"chat\") && model.id === definition.id);\n\t\tconst defaults = findModelDefaults(models, definition.id, definition.api ?? config.api);\n\t\tconst model = modelFromJson(providerId, definition, config, defaults);\n\t\tif (existingIndex >= 0) models[existingIndex] = model;\n\t\telse models.push(model);\n\t}\n\treturn models;\n}\n\nfunction applyExtension(\n\tproviderId: string,\n\tmodels: readonly AnyModel[],\n\tconfig: ProviderConfigInput | undefined,\n): AnyModel[] {\n\tif (!config) return [...models];\n\tif (!config.models) {\n\t\treturn config.baseUrl ? models.map((model) => ({ ...model, baseUrl: config.baseUrl! })) : [...models];\n\t}\n\treturn config.models.map((definition) => extensionModelFromDefinition(providerId, models, config, definition));\n}\n\nfunction adaptOAuth(config: ExtensionOAuthConfig): OAuthAuth {\n\treturn {\n\t\tname: config.name,\n\t\tisSubscription: config.isSubscription,\n\t\tlogin: async (callbacks) => {\n\t\t\tconst credential = await config.login({\n\t\t\t\tonAuth: (info) => callbacks.notify({ type: \"auth_url\", ...info }),\n\t\t\t\tonDeviceCode: (info) => callbacks.notify({ type: \"device_code\", ...info }),\n\t\t\t\tonPrompt: (prompt) => callbacks.prompt({ type: \"text\", ...prompt }),\n\t\t\t\tonProgress: (message) => callbacks.notify({ type: \"progress\", message }),\n\t\t\t\tonManualCodeInput: () => callbacks.prompt({ type: \"manual_code\", message: \"Paste the authorization code\" }),\n\t\t\t\tonSelect: (prompt) => callbacks.prompt({ type: \"select\", ...prompt }),\n\t\t\t\tsignal: callbacks.signal,\n\t\t\t});\n\t\t\treturn { ...credential, type: \"oauth\" };\n\t\t},\n\t\trefresh: async (credential, signal) => ({ ...(await config.refreshToken(credential, signal)), type: \"oauth\" }),\n\t\ttoAuth: async (credential) => ({ apiKey: config.getApiKey(credential) }),\n\t};\n}\n\nfunction withConfiguredAuth(\n\tauth: ModelAuth,\n\theaders: Record<string, string> | undefined,\n\tauthHeader: boolean,\n): ModelAuth {\n\tlet mergedHeaders: ProviderHeaders | undefined =\n\t\tauth.headers || headers ? { ...auth.headers, ...headers } : undefined;\n\tif (authHeader) {\n\t\tif (!auth.apiKey) throw new Error(\"authHeader requires a resolved API key\");\n\t\tmergedHeaders = { ...mergedHeaders, Authorization: `Bearer ${auth.apiKey}` };\n\t}\n\treturn { ...auth, headers: mergedHeaders };\n}\n\nfunction configuredApiKey(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): string | undefined {\n\treturn extension?.apiKey ?? config?.apiKey;\n}\n\nfunction configuredHeaders(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): Record<string, string> | undefined {\n\tif (!config?.headers && !extension?.headers) return undefined;\n\treturn { ...config?.headers, ...extension?.headers };\n}\n\nasync function configContextEnv(\n\tvalues: readonly string[],\n\tctx: AuthContext,\n\texplicit?: Record<string, string>,\n): Promise<Record<string, string> | undefined> {\n\tconst env = { ...explicit };\n\tfor (const name of new Set(values.flatMap(getConfigValueEnvVarNames))) {\n\t\tif (env[name] !== undefined) continue;\n\t\tconst value = await ctx.env(name);\n\t\tif (value !== undefined) env[name] = value;\n\t}\n\treturn Object.keys(env).length > 0 ? env : undefined;\n}\n\nfunction composeApiKeyAuth(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): ApiKeyAuth | undefined {\n\tconst inherited = base?.auth.apiKey;\n\tconst rawKey = configuredApiKey(config, extension);\n\tconst oauth = extension?.oauth ?? base?.auth.oauth;\n\t// OAuth-only providers get no fabricated API-key login method.\n\tif (!inherited && rawKey === undefined && oauth) return undefined;\n\tconst rawHeaders = configuredHeaders(config, extension);\n\tconst authHeader = extension?.authHeader ?? config?.authHeader ?? false;\n\treturn {\n\t\tname: inherited?.name ?? \"API key\",\n\t\tlogin:\n\t\t\tinherited?.login ??\n\t\t\t(async (interaction: AuthInteraction) => ({\n\t\t\t\ttype: \"api_key\",\n\t\t\t\tkey: await interaction.prompt({ type: \"secret\", message: \"Enter API key\" }),\n\t\t\t})),\n\t\tcheck: async (input) => {\n\t\t\tif (input.credential) {\n\t\t\t\tif (inherited?.check) return inherited.check(input);\n\t\t\t\tif (input.credential.key) return { type: \"api_key\", source: \"stored credential\" };\n\t\t\t\tconst resolved = await inherited?.resolve(input);\n\t\t\t\treturn resolved ? { type: \"api_key\", source: resolved.source } : undefined;\n\t\t\t}\n\t\t\tif (rawKey !== undefined) {\n\t\t\t\tif (isCommandConfigValue(rawKey)) return { type: \"api_key\", source: \"configured API key\" };\n\t\t\t\tconst envNames = getConfigValueEnvVarNames(rawKey);\n\t\t\t\tfor (const name of envNames) {\n\t\t\t\t\tif ((await input.ctx.env(name)) === undefined) return undefined;\n\t\t\t\t}\n\t\t\t\treturn { type: \"api_key\", source: \"configured API key\" };\n\t\t\t}\n\t\t\tif (inherited?.check) return inherited.check(input);\n\t\t\tconst resolved = await inherited?.resolve(input);\n\t\t\treturn resolved ? { type: \"api_key\", source: resolved.source } : undefined;\n\t\t},\n\t\tresolve: async (input) => {\n\t\t\tlet result: AuthResult | undefined;\n\t\t\tif (input.credential) {\n\t\t\t\tresult = inherited\n\t\t\t\t\t? await inherited.resolve(input)\n\t\t\t\t\t: input.credential.key\n\t\t\t\t\t\t? { auth: { apiKey: input.credential.key }, env: input.credential.env, source: \"stored credential\" }\n\t\t\t\t\t\t: undefined;\n\t\t\t} else if (rawKey !== undefined) {\n\t\t\t\tconst env = await configContextEnv([rawKey], input.ctx);\n\t\t\t\tconst key = resolveConfigValueOrThrow(rawKey, `API key for provider \"${providerId}\"`, env);\n\t\t\t\tresult = inherited\n\t\t\t\t\t? await inherited.resolve({ ...input, credential: { type: \"api_key\", key } })\n\t\t\t\t\t: { auth: { apiKey: key }, source: \"configured API key\" };\n\t\t\t} else {\n\t\t\t\tresult = await inherited?.resolve(input);\n\t\t\t}\n\t\t\tif (!result) return undefined;\n\t\t\tconst explicitEnv = { ...(input.credential?.env ?? {}), ...(result.env ?? {}) };\n\t\t\tconst headerEnv = await configContextEnv(Object.values(rawHeaders ?? {}), input.ctx, explicitEnv);\n\t\t\tconst headers = resolveHeadersOrThrow(rawHeaders, `provider \"${providerId}\"`, headerEnv);\n\t\t\treturn { ...result, auth: withConfiguredAuth(result.auth, headers, authHeader) };\n\t\t},\n\t};\n}\n\nfunction composeOAuthAuth(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): OAuthAuth | undefined {\n\tconst oauth = extension?.oauth ? adaptOAuth(extension.oauth) : base?.auth.oauth;\n\tif (!oauth) return undefined;\n\tconst rawHeaders = configuredHeaders(config, extension);\n\tconst authHeader = extension?.authHeader ?? config?.authHeader ?? false;\n\treturn {\n\t\t...oauth,\n\t\ttoAuth: async (credential) => {\n\t\t\tconst auth = await oauth.toAuth(credential);\n\t\t\tconst env = credential.env;\n\t\t\tconst headers = resolveHeadersOrThrow(\n\t\t\t\trawHeaders,\n\t\t\t\t`provider \"${providerId}\"`,\n\t\t\t\ttypeof env === \"object\" && env !== null ? (env as Record<string, string>) : undefined,\n\t\t\t);\n\t\t\treturn withConfiguredAuth(auth, headers, authHeader);\n\t\t},\n\t};\n}\n\nfunction rawModelHeaders(\n\tmodel: AnyModel,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): Record<string, string> | undefined {\n\t// models.json definitions and overrides are chat-only. Extension definitions\n\t// are matched by operation and id so colliding models cannot share headers.\n\tconst chatDefinition = isModelType(model, \"chat\")\n\t\t? config?.models?.find((entry) => entry.id === model.id)\n\t\t: undefined;\n\tconst extensionModel = extension?.models?.find(\n\t\t(entry) => (entry.type ?? \"chat\") === (model.type ?? \"chat\") && entry.id === model.id,\n\t);\n\tconst headers = {\n\t\t...(isModelType(model, \"chat\") ? config?.modelOverrides?.[model.id]?.headers : undefined),\n\t\t...chatDefinition?.headers,\n\t\t...extensionModel?.headers,\n\t};\n\treturn Object.keys(headers).length > 0 ? headers : undefined;\n}\n\nexport function validateExtensionProvider(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tmodelsConfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput,\n): void {\n\tif (extension.streamSimple && !extension.api) {\n\t\tthrow new Error(`Provider ${providerId}: \"api\" is required when registering streamSimple.`);\n\t}\n\tapplyExtension(providerId, applyModelsJson(providerId, getAllProviderModels(base), modelsConfig), extension);\n}\n\n/** Compose built-in, models.json, and extension layers without reading credentials. */\nexport function composeModelProvider(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tmodelConfig: ModelConfig,\n\textension: ProviderConfigInput | undefined,\n): Provider {\n\tconst config = modelConfig.getProvider(providerId);\n\tlet extensionOAuthCredential: OAuthCredentials | undefined;\n\tlet refreshedExtensionModels: ProviderConfigInput[\"models\"];\n\tconst currentExtension = (): ProviderConfigInput | undefined =>\n\t\textension && refreshedExtensionModels ? { ...extension, models: refreshedExtensionModels } : extension;\n\t// models.json modelOverrides are the topmost user-config layer: they apply once,\n\t// after custom-model upserts, extension model replacement, and legacy OAuth projection.\n\tconst getAllModels = (): AnyModel[] => {\n\t\tlet models = applyExtension(\n\t\t\tproviderId,\n\t\t\tapplyModelsJson(providerId, getAllProviderModels(base), config),\n\t\t\tcurrentExtension(),\n\t\t);\n\t\tif (extensionOAuthCredential && extension?.oauth?.modifyModels) {\n\t\t\t// The extension hook is chat-only; other model types pass through untouched.\n\t\t\tmodels = [\n\t\t\t\t...extension.oauth.modifyModels(\n\t\t\t\t\tmodels.filter((model) => isModelType(model, \"chat\")),\n\t\t\t\t\textensionOAuthCredential,\n\t\t\t\t),\n\t\t\t\t...models.filter((model) => !isModelType(model, \"chat\")),\n\t\t\t];\n\t\t}\n\t\treturn models.map((model) => {\n\t\t\tconst override = config?.modelOverrides?.[model.id];\n\t\t\treturn override && isModelType(model, \"chat\") ? applyModelOverride(model, override) : model;\n\t\t});\n\t};\n\t// Validate eagerly so registration/reload reports structural errors immediately.\n\tgetAllModels();\n\tconst apiKey = composeApiKeyAuth(providerId, base, config, extension);\n\tconst oauth = composeOAuthAuth(providerId, base, config, extension);\n\tif (!apiKey && !oauth) throw new Error(`Provider ${providerId}: no authentication method configured.`);\n\n\tconst supportsBaseApi = (model: Model<Api>) => base?.getModels().some((entry) => entry.api === model.api) ?? false;\n\tconst streamWith = (\n\t\tmodel: Model<Api>,\n\t\tcontext: TranscriptContext,\n\t\toptions: StreamOptions | undefined,\n\t\tsimple: boolean,\n\t): AssistantMessageEventStream =>\n\t\tlazyStream(\n\t\t\tmodel,\n\t\t\tasync () => {\n\t\t\t\tif (extension?.streamSimple && model.api === extension.api) {\n\t\t\t\t\treturn extension.streamSimple(model, context, options as SimpleStreamOptions);\n\t\t\t\t}\n\t\t\t\tif (base && supportsBaseApi(model)) {\n\t\t\t\t\treturn simple\n\t\t\t\t\t\t? base.streamSimple(model, context, options as SimpleStreamOptions)\n\t\t\t\t\t\t: base.stream(model, context, options);\n\t\t\t\t}\n\t\t\t\tconst api = getApiProvider(model.api);\n\t\t\t\tif (!api) throw new Error(`No API provider registered for api: ${model.api}`);\n\t\t\t\treturn simple\n\t\t\t\t\t? api.streamSimple(model, context, options as SimpleStreamOptions)\n\t\t\t\t\t: api.stream(model, context, options);\n\t\t\t},\n\t\t\tundefined,\n\t\t\toptions?.signal,\n\t\t);\n\n\tconst provider: Provider = {\n\t\tid: providerId,\n\t\tname: extension?.name ?? config?.name ?? base?.name ?? extension?.oauth?.name ?? providerId,\n\t\tbaseUrl: extension?.baseUrl ?? config?.baseUrl ?? base?.baseUrl,\n\t\theaders: base?.headers,\n\t\tauth: { ...(apiKey ? { apiKey } : {}), ...(oauth ? { oauth } : {}) },\n\t\tgetModels: () => getAllModels().filter((model) => isModelType(model, \"chat\")),\n\t\tgetAllModels,\n\t\t// Extension hooks read context.credential, so they need the default credential refresh.\n\t\trefreshModelsAuth:\n\t\t\textension?.refreshModels || extension?.oauth?.modifyModels ? undefined : base?.refreshModelsAuth,\n\t\trefreshModels:\n\t\t\tbase?.refreshModels || extension?.refreshModels || extension?.oauth?.modifyModels\n\t\t\t\t? async (context) => {\n\t\t\t\t\t\tawait base?.refreshModels?.(context);\n\t\t\t\t\t\tlet refreshed: NonNullable<ProviderConfigInput[\"models\"]> | undefined;\n\t\t\t\t\t\tif (extension?.refreshModels) refreshed = await extension.refreshModels(context);\n\t\t\t\t\t\tif (context.signal.aborted) return;\n\t\t\t\t\t\tconst oauthCredential = context.credential?.type === \"oauth\" ? context.credential : undefined;\n\t\t\t\t\t\tawait context.publish({\n\t\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\t\tif (refreshed) {\n\t\t\t\t\t\t\t\t\t// Validate before publishing the new synchronous list.\n\t\t\t\t\t\t\t\t\tapplyExtension(providerId, applyModelsJson(providerId, getAllProviderModels(base), config), {\n\t\t\t\t\t\t\t\t\t\t...extension,\n\t\t\t\t\t\t\t\t\t\tmodels: refreshed,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\trefreshedExtensionModels = refreshed;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\textensionOAuthCredential = oauthCredential;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\tfilterModels: base?.filterModels\n\t\t\t? (models, credential: Credential | undefined) => base.filterModels!(models, credential)\n\t\t\t: undefined,\n\t\tfilterAllModels: base?.filterAllModels\n\t\t\t? (models, credential: Credential | undefined) => base.filterAllModels!(models, credential)\n\t\t\t: undefined,\n\t\tstream: (model, context, options) => streamWith(model, context, options, false),\n\t\tstreamSimple: (model, context, options) => streamWith(model, context, options, true),\n\t};\n\n\tconst fetchDeferred = base?.fetchDeferred;\n\tif (fetchDeferred) {\n\t\tprovider.fetchDeferred = (model, handle, options) => fetchDeferred(model, handle, options);\n\t}\n\tconst cancelDeferred = base?.cancelDeferred;\n\tif (cancelDeferred) {\n\t\tprovider.cancelDeferred = (model, handle, options) => cancelDeferred(model, handle, options);\n\t}\n\tconst extensionImages = extension?.images;\n\tconst generateImages = base?.generateImages;\n\tif (generateImages || Object.keys(extensionImages ?? {}).length > 0) {\n\t\tprovider.generateImages = (model, context, options) => {\n\t\t\tconst implementation = extensionImages?.[model.api];\n\t\t\tif (implementation) return implementation.generateImages(model, context, options);\n\t\t\tif (generateImages) return generateImages(model, context, options);\n\t\t\treturn Promise.resolve(\n\t\t\t\timageErrorResult(model, new Error(`Provider ${providerId} has no image implementation for \"${model.api}\"`)),\n\t\t\t);\n\t\t};\n\t}\n\tconst extensionClassifiers = extension?.classifiers;\n\tconst classify = base?.classify;\n\tif (classify || Object.keys(extensionClassifiers ?? {}).length > 0) {\n\t\tprovider.classify = (model, context, options) => {\n\t\t\tconst implementation = extensionClassifiers?.[model.api];\n\t\t\tif (implementation) return implementation.classify(model, context, options);\n\t\t\tif (classify) return classify(model, context, options);\n\t\t\treturn Promise.resolve(\n\t\t\t\tclassifierErrorResult(\n\t\t\t\t\tmodel,\n\t\t\t\t\tnew Error(`Provider ${providerId} has no classifier implementation for \"${model.api}\"`),\n\t\t\t\t),\n\t\t\t);\n\t\t};\n\t}\n\n\treturn provider;\n}\n\nexport function resolveConfiguredModelHeaders(\n\tmodel: AnyModel,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n\tenv?: Record<string, string>,\n): Record<string, string> | undefined {\n\treturn resolveHeadersOrThrow(\n\t\trawModelHeaders(model, config, extension),\n\t\t`model \"${model.provider}/${model.id}\"`,\n\t\tenv,\n\t);\n}\n\nexport interface CompatibilityRequestConfig {\n\theaders?: ProviderHeaders;\n\tauthHeader: boolean;\n}\n\nexport function resolveCompatibilityRequestConfig(\n\tmodel: AnyModel,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): CompatibilityRequestConfig {\n\tconst configured = resolveHeadersOrThrow(\n\t\t{ ...configuredHeaders(config, extension), ...rawModelHeaders(model, config, extension) },\n\t\t`model \"${model.provider}/${model.id}\"`,\n\t);\n\treturn {\n\t\theaders: model.headers || configured ? { ...model.headers, ...configured } : undefined,\n\t\tauthHeader: extension?.authHeader ?? config?.authHeader ?? false,\n\t};\n}\n\nexport function configuredRequestAuthStatus(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): AuthStatus | undefined {\n\tconst value = configuredApiKey(config, extension);\n\tif (value === undefined) return undefined;\n\tif (isCommandConfigValue(value)) return { configured: true, source: \"models_json_command\" };\n\tconst names = getConfigValueEnvVarNames(value);\n\tif (names.length > 0) {\n\t\treturn isConfigValueConfigured(value)\n\t\t\t? { configured: true, source: \"environment\", label: names.join(\", \") }\n\t\t\t: { configured: false };\n\t}\n\treturn { configured: true, source: extension?.apiKey !== undefined ? \"fallback\" : \"models_json_key\" };\n}\n"]}
@@ -0,0 +1,6 @@
1
+ /** Match provider IDs and display names exactly, ignoring case and surrounding whitespace in the reference. */
2
+ export declare function findMatchingProviders<T extends {
3
+ id: string;
4
+ name: string;
5
+ }>(providers: readonly T[], providerRef: string): T[];
6
+ //# sourceMappingURL=provider-matching.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-matching.d.ts","sourceRoot":"","sources":["../../src/core/provider-matching.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,wBAAgB,qBAAqB,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAC3E,SAAS,EAAE,SAAS,CAAC,EAAE,EACvB,WAAW,EAAE,MAAM,GACjB,CAAC,EAAE,CAML"}
@@ -0,0 +1,8 @@
1
+ /** Match provider IDs and display names exactly, ignoring case and surrounding whitespace in the reference. */
2
+ export function findMatchingProviders(providers, providerRef) {
3
+ const normalized = providerRef.trim().toLowerCase();
4
+ if (!normalized)
5
+ return [];
6
+ return providers.filter((provider) => provider.id.toLowerCase() === normalized || provider.name.toLowerCase() === normalized);
7
+ }
8
+ //# sourceMappingURL=provider-matching.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-matching.js","sourceRoot":"","sources":["../../src/core/provider-matching.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,MAAM,UAAU,qBAAqB,CACpC,SAAuB,EACvB,WAAmB;IAEnB,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACpD,IAAI,CAAC,UAAU;QAAE,OAAO,EAAE,CAAC;IAC3B,OAAO,SAAS,CAAC,MAAM,CACtB,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,UAAU,IAAI,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,UAAU,CACpG,CAAC;AACH,CAAC","sourcesContent":["/** Match provider IDs and display names exactly, ignoring case and surrounding whitespace in the reference. */\nexport function findMatchingProviders<T extends { id: string; name: string }>(\n\tproviders: readonly T[],\n\tproviderRef: string,\n): T[] {\n\tconst normalized = providerRef.trim().toLowerCase();\n\tif (!normalized) return [];\n\treturn providers.filter(\n\t\t(provider) => provider.id.toLowerCase() === normalized || provider.name.toLowerCase() === normalized,\n\t);\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { McpHttpServerConfig } from "./mcp-servers.ts";
2
+ /** Change to the global mcp.json that points the Radius MCP server at a Radius login. */
3
+ export interface RadiusMcpServerPlan {
4
+ mcpPath: string;
5
+ name: string;
6
+ config: McpHttpServerConfig;
7
+ }
8
+ /**
9
+ * The global mcp.json entry that makes the Radius MCP server use the login of `providerId`, adding the server when
10
+ * missing, or undefined when a global server already uses that login.
11
+ */
12
+ export declare function planRadiusMcpServer(providerId: string, agentDir: string, cwd: string): RadiusMcpServerPlan | undefined;
13
+ //# sourceMappingURL=radius-mcp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"radius-mcp.d.ts","sourceRoot":"","sources":["../../src/core/radius-mcp.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAG5D,yFAAyF;AACzF,MAAM,WAAW,mBAAmB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,mBAAmB,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAClC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,GACT,mBAAmB,GAAG,SAAS,CAsBjC"}
@@ -0,0 +1,29 @@
1
+ import path from "node:path";
2
+ import { mcpNamespace } from "@draht/mcp";
3
+ import { loadMcpConfig } from "../extensions/mcp/config.js";
4
+ import { RADIUS_MCP_URL } from "./radius.js";
5
+ /**
6
+ * The global mcp.json entry that makes the Radius MCP server use the login of `providerId`, adding the server when
7
+ * missing, or undefined when a global server already uses that login.
8
+ */
9
+ export function planRadiusMcpServer(providerId, agentDir, cwd) {
10
+ const normalizeUrl = (url) => url.replace(/\/+$/u, "");
11
+ const { servers } = loadMcpConfig({ agentDir, cwd, projectTrusted: false });
12
+ const existing = servers.find((server) => "url" in server.config && normalizeUrl(server.config.url) === normalizeUrl(RADIUS_MCP_URL));
13
+ if (existing && "url" in existing.config && existing.config.auth?.provider === providerId)
14
+ return undefined;
15
+ let name = existing?.name ?? "radius";
16
+ if (!existing) {
17
+ const namespaces = new Set(servers.map((server) => mcpNamespace(server.name)));
18
+ for (let suffix = 1; namespaces.has(mcpNamespace(name)); suffix++) {
19
+ name = suffix === 1 ? "radius-mcp" : `radius-mcp-${suffix}`;
20
+ }
21
+ }
22
+ const config = existing && "url" in existing.config
23
+ ? { ...existing.config, auth: { provider: providerId } }
24
+ : { url: RADIUS_MCP_URL, auth: { provider: providerId } };
25
+ // `auth` replaces the MCP OAuth sign-in.
26
+ delete config.oauth;
27
+ return { mcpPath: path.join(agentDir, "mcp.json"), name, config };
28
+ }
29
+ //# sourceMappingURL=radius-mcp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"radius-mcp.js","sourceRoot":"","sources":["../../src/core/radius-mcp.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAS7C;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAClC,UAAkB,EAClB,QAAgB,EAChB,GAAW;IAEX,MAAM,YAAY,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC/D,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5E,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAC5B,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,IAAI,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,YAAY,CAAC,cAAc,CAAC,CACtG,CAAC;IACF,IAAI,QAAQ,IAAI,KAAK,IAAI,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,KAAK,UAAU;QAAE,OAAO,SAAS,CAAC;IAE5G,IAAI,IAAI,GAAG,QAAQ,EAAE,IAAI,IAAI,QAAQ,CAAC;IACtC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACf,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC/E,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;YACnE,IAAI,GAAG,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,cAAc,MAAM,EAAE,CAAC;QAC7D,CAAC;IACF,CAAC;IACD,MAAM,MAAM,GACX,QAAQ,IAAI,KAAK,IAAI,QAAQ,CAAC,MAAM;QACnC,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE;QACxD,CAAC,CAAC,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,CAAC;IAC5D,yCAAyC;IACzC,OAAO,MAAM,CAAC,KAAK,CAAC;IACpB,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AACnE,CAAC","sourcesContent":["import path from \"node:path\";\nimport { mcpNamespace } from \"@draht/mcp\";\nimport { loadMcpConfig } from \"../extensions/mcp/config.ts\";\nimport type { McpHttpServerConfig } from \"./mcp-servers.ts\";\nimport { RADIUS_MCP_URL } from \"./radius.ts\";\n\n/** Change to the global mcp.json that points the Radius MCP server at a Radius login. */\nexport interface RadiusMcpServerPlan {\n\tmcpPath: string;\n\tname: string;\n\tconfig: McpHttpServerConfig;\n}\n\n/**\n * The global mcp.json entry that makes the Radius MCP server use the login of `providerId`, adding the server when\n * missing, or undefined when a global server already uses that login.\n */\nexport function planRadiusMcpServer(\n\tproviderId: string,\n\tagentDir: string,\n\tcwd: string,\n): RadiusMcpServerPlan | undefined {\n\tconst normalizeUrl = (url: string) => url.replace(/\\/+$/u, \"\");\n\tconst { servers } = loadMcpConfig({ agentDir, cwd, projectTrusted: false });\n\tconst existing = servers.find(\n\t\t(server) => \"url\" in server.config && normalizeUrl(server.config.url) === normalizeUrl(RADIUS_MCP_URL),\n\t);\n\tif (existing && \"url\" in existing.config && existing.config.auth?.provider === providerId) return undefined;\n\n\tlet name = existing?.name ?? \"radius\";\n\tif (!existing) {\n\t\tconst namespaces = new Set(servers.map((server) => mcpNamespace(server.name)));\n\t\tfor (let suffix = 1; namespaces.has(mcpNamespace(name)); suffix++) {\n\t\t\tname = suffix === 1 ? \"radius-mcp\" : `radius-mcp-${suffix}`;\n\t\t}\n\t}\n\tconst config: McpHttpServerConfig =\n\t\texisting && \"url\" in existing.config\n\t\t\t? { ...existing.config, auth: { provider: providerId } }\n\t\t\t: { url: RADIUS_MCP_URL, auth: { provider: providerId } };\n\t// `auth` replaces the MCP OAuth sign-in.\n\tdelete config.oauth;\n\treturn { mcpPath: path.join(agentDir, \"mcp.json\"), name, config };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"remote-catalog-provider.d.ts","sourceRoot":"","sources":["../../src/core/remote-catalog-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,QAAQ,EAIb,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,oBAAoB,EACzB,MAAM,WAAW,CAAC;AAYnB,eAAO,MAAM,kCAAkC,QAAqB,CAAC;AACr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AgB,uBAAuB,CACtC,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,kBAAkB,EAC/B,cAAc,GAAE,MAAM,GAAG,SAA6C,EACtE,gBAAgB,CAAC,EAAE,MAAM,GACvB,QAAQ,CA0CV"}
@@ -77,6 +77,8 @@ export function withRemoteCatalog(provider, catalogBaseUrl = process.env[CATALOG
77
77
  ...provider,
78
78
  getModels: () => mergeModels(provider.getModels(), dynamicModels.filter((model) => isModelType(model, "chat"))),
79
79
  getAllModels: () => mergeModels(provider.getAllModels?.() ?? provider.getModels(), dynamicModels),
80
+ // A separate remote catalog service serves the catalog, so a stale provider login must not block or fail its refresh.
81
+ refreshModelsAuth: "configured",
80
82
  refreshModels: async (context) => {
81
83
  const stored = context.stored;
82
84
  const restored = remoteModels(stored, localGeneratedAt).filter((model) => model.provider === provider.id);
@@ -1 +1 @@
1
- {"version":3,"file":"remote-catalog-provider.js","sourceRoot":"","sources":["../../src/core/remote-catalog-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,YAAY,EACZ,WAAW,GAKX,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D;;;;GAIG;AACH,MAAM,oBAAoB,GAAG,8BAA8B,CAAC;AAC5D,MAAM,iCAAiC,GAAG,KAAK,CAAC;AAChD,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACrE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAyB,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;AAEhG,SAAS,oBAAoB,CAAC,KAAyB;IACtD,OAAO,CACN,KAAK,CAAC,IAAI,KAAK,SAAS;QACxB,CAAC,OAAO,KAAK,CAAC,IAAI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AI,KAAK,CAAC,oCAAoC,QAAQ,CAAC,EAAE,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;oBACzG,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;oBACzD,IAAI,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,gBAAgB,CAAC;wBAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;gBAC9E,CAAC;YACF,CAAC;YACD,MAAM,YAAY,GAAG,MAAM,WAAW,CAAC,WAAW,CAAC,aAAa,EAAE,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;YACtF,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO;gBAAE,OAAO;YACnC,MAAM,OAAO,CAAC,OAAO,CAAC;gBACrB,OAAO,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE;gBACxD,MAAM,EAAE,GAAG,EAAE;oBACZ,cAAc,GAAG,YAAY,CAAC;gBAC/B,CAAC;aACD,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import {\n\ttype AnyModel,\n\tgetModelType,\n\tisModelType,\n\ttype ModelsStoreEntry,\n\ttype ModelType,\n\ttype Provider,\n\ttype RefreshModelsContext,\n} from \"@draht/ai\";\nimport { VERSION } from \"../config.ts\";\nimport { getDrahtUserAgent } from \"../utils/draht-user-agent.ts\";\nimport { fetchWithRetry } from \"../utils/management-http.ts\";\n\n/**\n * draht has no pi.dev-equivalent model catalog service. The remote overlay is\n * disabled by default; set DRAHT_MODEL_CATALOG_BASE_URL to opt into a\n * self-hosted catalog endpoint that implements the same wire protocol.\n */\nconst CATALOG_BASE_URL_ENV = \"DRAHT_MODEL_CATALOG_BASE_URL\";\nconst REMOTE_CATALOG_ATTEMPT_TIMEOUT_MS = 4_000;\nexport const REMOTE_CATALOG_REFRESH_INTERVAL_MS = 4 * 60 * 60 * 1000;\n/**\n * Model types this client can consume. Sent as `?types=` so the catalog server\n * returns the full-type shard instead of the chat-only one served to clients\n * that predate model types. A server that ignores the parameter still returns\n * the chat-only shard, which this client handles unchanged.\n */\nexport const REMOTE_CATALOG_MODEL_TYPES: readonly ModelType[] = [\"chat\", \"image\", \"classifier\"];\n\nfunction isSupportedModelType(model: { type?: unknown }): boolean {\n\treturn (\n\t\tmodel.type === undefined ||\n\t\t(typeof model.type === \"string\" && REMOTE_CATALOG_MODEL_TYPES.includes(model.type as ModelType))\n\t);\n}\n\nfunction mergeModels<TModel extends AnyModel>(baseline: readonly TModel[], dynamic: readonly TModel[]): TModel[] {\n\tconst merged = new Map<string, TModel>();\n\tfor (const model of [...baseline, ...dynamic]) merged.set(`${getModelType(model)}\\0${model.id}`, model);\n\treturn [...merged.values()];\n}\n\nfunction parseCatalog(providerId: string, value: unknown): AnyModel[] {\n\tconst entries = Array.isArray(value)\n\t\t? value\n\t\t: typeof value === \"object\" && value !== null && \"models\" in value && Array.isArray(value.models)\n\t\t\t? value.models\n\t\t\t: typeof value === \"object\" && value !== null\n\t\t\t\t? Object.values(value)\n\t\t\t\t: undefined;\n\tif (!entries) throw new Error(`Invalid model catalog for provider \"${providerId}\"`);\n\treturn entries\n\t\t.filter((entry): entry is Record<string, unknown> => typeof entry === \"object\" && entry !== null && \"id\" in entry)\n\t\t.filter(isSupportedModelType)\n\t\t.map((model) => ({ ...model, provider: providerId }) as AnyModel);\n}\n\n/** Read a successful remote catalog response. A missing or invalid Last-Modified header is 0. */\nasync function readCatalog(\n\tproviderId: string,\n\tresponse: Response,\n): Promise<{ models: AnyModel[]; lastModified: number; etag: string | undefined }> {\n\tconst lastModified = Date.parse(response.headers.get(\"last-modified\") ?? \"\");\n\treturn {\n\t\tmodels: parseCatalog(providerId, await response.json()),\n\t\tlastModified: Number.isNaN(lastModified) ? 0 : lastModified,\n\t\tetag: response.headers.get(\"etag\") ?? undefined,\n\t};\n}\n\n/** Whether a remote catalog is newer than the model data shipped with draht. */\nfunction isNewer(lastModified: number | undefined, localGeneratedAt: number | undefined): boolean {\n\treturn localGeneratedAt === undefined || (lastModified !== undefined && lastModified > localGeneratedAt);\n}\n\nfunction remoteModels(entry: ModelsStoreEntry | undefined, localGeneratedAt: number | undefined): readonly AnyModel[] {\n\treturn entry && isNewer(entry.lastModified, localGeneratedAt) ? entry.models : [];\n}\n\nfunction requestCatalog(\n\tproviderId: string,\n\tcatalogBaseUrl: string,\n\tsignal: AbortSignal,\n\tvalidator?: string,\n): Promise<Response> {\n\tconst url = new URL(`/api/models/providers/${encodeURIComponent(providerId)}`, catalogBaseUrl);\n\turl.searchParams.set(\"types\", REMOTE_CATALOG_MODEL_TYPES.join(\",\"));\n\treturn fetchWithRetry(\n\t\turl,\n\t\t{\n\t\t\theaders: {\n\t\t\t\taccept: \"application/json\",\n\t\t\t\t\"User-Agent\": getDrahtUserAgent(VERSION),\n\t\t\t\t...(validator ? { \"if-none-match\": validator } : {}),\n\t\t\t},\n\t\t\tsignal,\n\t\t},\n\t\t{ attemptTimeoutMs: REMOTE_CATALOG_ATTEMPT_TIMEOUT_MS },\n\t);\n}\n\n/** Replaces the catalog with a credential-specific model list. */\nexport type PersonalizeCatalog = (\n\tcatalog: readonly AnyModel[],\n\tcontext: RefreshModelsContext,\n) => Promise<readonly AnyModel[]>;\n\n/** Add a persisted remote catalog overlay to a static built-in provider. */\nexport function withRemoteCatalog(\n\tprovider: Provider,\n\tcatalogBaseUrl: string | undefined = process.env[CATALOG_BASE_URL_ENV],\n\tlocalGeneratedAt?: number,\n): Provider {\n\tlet dynamicModels: readonly AnyModel[] = [];\n\n\treturn {\n\t\t...provider,\n\t\tgetModels: () =>\n\t\t\tmergeModels(\n\t\t\t\tprovider.getModels(),\n\t\t\t\tdynamicModels.filter((model) => isModelType(model, \"chat\")),\n\t\t\t),\n\t\tgetAllModels: () => mergeModels(provider.getAllModels?.() ?? provider.getModels(), dynamicModels),\n\t\trefreshModels: async (context) => {\n\t\t\tconst stored = context.stored;\n\t\t\tconst restored = remoteModels(stored, localGeneratedAt).filter((model) => model.provider === provider.id);\n\t\t\tif (\n\t\t\t\t!(await context.publish({\n\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\tdynamicModels = restored;\n\t\t\t\t\t},\n\t\t\t\t}))\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!context.allowNetwork || context.signal.aborted) return;\n\t\t\tif (!catalogBaseUrl) return;\n\t\t\t// Skip the request if the remote catalog was checked less than REMOTE_CATALOG_REFRESH_INTERVAL_MS ago.\n\t\t\t// An entry without lastModified (saved by an older draht, or after a failed first request) is\n\t\t\t// always refetched: remoteModels() ignores it, so waiting would leave the overlay empty.\n\t\t\tif (\n\t\t\t\t!context.force &&\n\t\t\t\tstored?.checkedAt !== undefined &&\n\t\t\t\tstored.lastModified !== undefined &&\n\t\t\t\tDate.now() - stored.checkedAt < REMOTE_CATALOG_REFRESH_INTERVAL_MS\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Only revalidate when a cached body backs the validator, so a 304 can never\n\t\t\t// leave the overlay empty.\n\t\t\tconst validator = stored && stored.models.length > 0 ? stored.etag : undefined;\n\t\t\tconst response = await requestCatalog(provider.id, catalogBaseUrl, context.signal, validator);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst checkedAt = Date.now();\n\t\t\t// Unchanged: dynamicModels already holds the stored overlay, so only the\n\t\t\t// freshness window moves.\n\t\t\tif (response.status === 304 && stored) {\n\t\t\t\tawait context.publish({ persist: { ...stored, checkedAt } });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (response.status === 404 || response.status === 501) {\n\t\t\t\tawait context.publish({\n\t\t\t\t\tpersist: {\n\t\t\t\t\t\t...(stored ?? { models: [] }),\n\t\t\t\t\t\tcheckedAt,\n\t\t\t\t\t\tlastModified: 0,\n\t\t\t\t\t\tetag: undefined,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!response.ok) {\n\t\t\t\t// Transient failure: the cached body and its validator stay valid, so keep the\n\t\t\t\t// etag and let the next refresh revalidate instead of downloading the catalog.\n\t\t\t\tawait context.publish({ persist: { ...(stored ?? { models: [] }), checkedAt } });\n\t\t\t\tthrow new Error(`Model catalog request failed for ${provider.id}: ${response.status}`);\n\t\t\t}\n\t\t\tconst catalog = await readCatalog(provider.id, response);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst entry: ModelsStoreEntry = { ...catalog, checkedAt };\n\t\t\tconst published = remoteModels(entry, localGeneratedAt);\n\t\t\tawait context.publish({\n\t\t\t\tpersist: entry,\n\t\t\t\tupdate: () => {\n\t\t\t\t\tdynamicModels = published;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n}\n\n/**\n * Like `withRemoteCatalog`, but on each network refresh the catalog (built-in models plus a newer\n * remote catalog) is passed through `personalize` and the result is saved. The saved entry holds\n * the personalized list, not the remote catalog, and replaces the catalog, including offline.\n * The refresh interval and etag revalidation are skipped. An empty list (nothing saved yet, or an\n * empty catalog saved by an older draht after a failed or missing remote catalog) falls back to the\n * built-in models.\n */\nexport function withPersonalizedCatalog(\n\tprovider: Provider,\n\tpersonalize: PersonalizeCatalog,\n\tcatalogBaseUrl: string | undefined = process.env[CATALOG_BASE_URL_ENV],\n\tlocalGeneratedAt?: number,\n): Provider {\n\tlet personalModels: readonly AnyModel[] = [];\n\tconst builtinModels = (): readonly AnyModel[] => provider.getAllModels?.() ?? provider.getModels();\n\tconst getAllModels = (): readonly AnyModel[] => (personalModels.length > 0 ? personalModels : builtinModels());\n\n\treturn {\n\t\t...provider,\n\t\tgetModels: () => getAllModels().filter((model) => isModelType(model, \"chat\")),\n\t\tgetAllModels,\n\t\trefreshModels: async (context) => {\n\t\t\tconst restored = (context.stored?.models ?? []).filter((model) => model.provider === provider.id);\n\t\t\tif (\n\t\t\t\t!(await context.publish({\n\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\tpersonalModels = restored;\n\t\t\t\t\t},\n\t\t\t\t}))\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!context.allowNetwork || context.signal.aborted) return;\n\n\t\t\tlet remote: readonly AnyModel[] = [];\n\t\t\tif (catalogBaseUrl) {\n\t\t\t\tconst response = await requestCatalog(provider.id, catalogBaseUrl, context.signal);\n\t\t\t\tif (context.signal.aborted) return;\n\t\t\t\tif (response.status !== 404 && response.status !== 501) {\n\t\t\t\t\tif (!response.ok) throw new Error(`Model catalog request failed for ${provider.id}: ${response.status}`);\n\t\t\t\t\tconst catalog = await readCatalog(provider.id, response);\n\t\t\t\t\tif (isNewer(catalog.lastModified, localGeneratedAt)) remote = catalog.models;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst personalized = await personalize(mergeModels(builtinModels(), remote), context);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tawait context.publish({\n\t\t\t\tpersist: { models: personalized, checkedAt: Date.now() },\n\t\t\t\tupdate: () => {\n\t\t\t\t\tpersonalModels = personalized;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"remote-catalog-provider.js","sourceRoot":"","sources":["../../src/core/remote-catalog-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,YAAY,EACZ,WAAW,GAKX,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D;;;;GAIG;AACH,MAAM,oBAAoB,GAAG,8BAA8B,CAAC;AAC5D,MAAM,iCAAiC,GAAG,KAAK,CAAC;AAChD,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACrE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B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AAC,CAAC;gBACnF,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO;oBAAE,OAAO;gBACnC,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;oBACxD,IAAI,CAAC,QAAQ,CAAC,EAAE;wBAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,QAAQ,CAAC,EAAE,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;oBACzG,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;oBACzD,IAAI,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,gBAAgB,CAAC;wBAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;gBAC9E,CAAC;YACF,CAAC;YACD,MAAM,YAAY,GAAG,MAAM,WAAW,CAAC,WAAW,CAAC,aAAa,EAAE,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;YACtF,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO;gBAAE,OAAO;YACnC,MAAM,OAAO,CAAC,OAAO,CAAC;gBACrB,OAAO,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE;gBACxD,MAAM,EAAE,GAAG,EAAE;oBACZ,cAAc,GAAG,YAAY,CAAC;gBAC/B,CAAC;aACD,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import {\n\ttype AnyModel,\n\tgetModelType,\n\tisModelType,\n\ttype ModelsStoreEntry,\n\ttype ModelType,\n\ttype Provider,\n\ttype RefreshModelsContext,\n} from \"@draht/ai\";\nimport { VERSION } from \"../config.ts\";\nimport { getDrahtUserAgent } from \"../utils/draht-user-agent.ts\";\nimport { fetchWithRetry } from \"../utils/management-http.ts\";\n\n/**\n * draht has no pi.dev-equivalent model catalog service. The remote overlay is\n * disabled by default; set DRAHT_MODEL_CATALOG_BASE_URL to opt into a\n * self-hosted catalog endpoint that implements the same wire protocol.\n */\nconst CATALOG_BASE_URL_ENV = \"DRAHT_MODEL_CATALOG_BASE_URL\";\nconst REMOTE_CATALOG_ATTEMPT_TIMEOUT_MS = 4_000;\nexport const REMOTE_CATALOG_REFRESH_INTERVAL_MS = 4 * 60 * 60 * 1000;\n/**\n * Model types this client can consume. Sent as `?types=` so the catalog server\n * returns the full-type shard instead of the chat-only one served to clients\n * that predate model types. A server that ignores the parameter still returns\n * the chat-only shard, which this client handles unchanged.\n */\nexport const REMOTE_CATALOG_MODEL_TYPES: readonly ModelType[] = [\"chat\", \"image\", \"classifier\"];\n\nfunction isSupportedModelType(model: { type?: unknown }): boolean {\n\treturn (\n\t\tmodel.type === undefined ||\n\t\t(typeof model.type === \"string\" && REMOTE_CATALOG_MODEL_TYPES.includes(model.type as ModelType))\n\t);\n}\n\nfunction mergeModels<TModel extends AnyModel>(baseline: readonly TModel[], dynamic: readonly TModel[]): TModel[] {\n\tconst merged = new Map<string, TModel>();\n\tfor (const model of [...baseline, ...dynamic]) merged.set(`${getModelType(model)}\\0${model.id}`, model);\n\treturn [...merged.values()];\n}\n\nfunction parseCatalog(providerId: string, value: unknown): AnyModel[] {\n\tconst entries = Array.isArray(value)\n\t\t? value\n\t\t: typeof value === \"object\" && value !== null && \"models\" in value && Array.isArray(value.models)\n\t\t\t? value.models\n\t\t\t: typeof value === \"object\" && value !== null\n\t\t\t\t? Object.values(value)\n\t\t\t\t: undefined;\n\tif (!entries) throw new Error(`Invalid model catalog for provider \"${providerId}\"`);\n\treturn entries\n\t\t.filter((entry): entry is Record<string, unknown> => typeof entry === \"object\" && entry !== null && \"id\" in entry)\n\t\t.filter(isSupportedModelType)\n\t\t.map((model) => ({ ...model, provider: providerId }) as AnyModel);\n}\n\n/** Read a successful remote catalog response. A missing or invalid Last-Modified header is 0. */\nasync function readCatalog(\n\tproviderId: string,\n\tresponse: Response,\n): Promise<{ models: AnyModel[]; lastModified: number; etag: string | undefined }> {\n\tconst lastModified = Date.parse(response.headers.get(\"last-modified\") ?? \"\");\n\treturn {\n\t\tmodels: parseCatalog(providerId, await response.json()),\n\t\tlastModified: Number.isNaN(lastModified) ? 0 : lastModified,\n\t\tetag: response.headers.get(\"etag\") ?? undefined,\n\t};\n}\n\n/** Whether a remote catalog is newer than the model data shipped with draht. */\nfunction isNewer(lastModified: number | undefined, localGeneratedAt: number | undefined): boolean {\n\treturn localGeneratedAt === undefined || (lastModified !== undefined && lastModified > localGeneratedAt);\n}\n\nfunction remoteModels(entry: ModelsStoreEntry | undefined, localGeneratedAt: number | undefined): readonly AnyModel[] {\n\treturn entry && isNewer(entry.lastModified, localGeneratedAt) ? entry.models : [];\n}\n\nfunction requestCatalog(\n\tproviderId: string,\n\tcatalogBaseUrl: string,\n\tsignal: AbortSignal,\n\tvalidator?: string,\n): Promise<Response> {\n\tconst url = new URL(`/api/models/providers/${encodeURIComponent(providerId)}`, catalogBaseUrl);\n\turl.searchParams.set(\"types\", REMOTE_CATALOG_MODEL_TYPES.join(\",\"));\n\treturn fetchWithRetry(\n\t\turl,\n\t\t{\n\t\t\theaders: {\n\t\t\t\taccept: \"application/json\",\n\t\t\t\t\"User-Agent\": getDrahtUserAgent(VERSION),\n\t\t\t\t...(validator ? { \"if-none-match\": validator } : {}),\n\t\t\t},\n\t\t\tsignal,\n\t\t},\n\t\t{ attemptTimeoutMs: REMOTE_CATALOG_ATTEMPT_TIMEOUT_MS },\n\t);\n}\n\n/** Replaces the catalog with a credential-specific model list. */\nexport type PersonalizeCatalog = (\n\tcatalog: readonly AnyModel[],\n\tcontext: RefreshModelsContext,\n) => Promise<readonly AnyModel[]>;\n\n/** Add a persisted remote catalog overlay to a static built-in provider. */\nexport function withRemoteCatalog(\n\tprovider: Provider,\n\tcatalogBaseUrl: string | undefined = process.env[CATALOG_BASE_URL_ENV],\n\tlocalGeneratedAt?: number,\n): Provider {\n\tlet dynamicModels: readonly AnyModel[] = [];\n\n\treturn {\n\t\t...provider,\n\t\tgetModels: () =>\n\t\t\tmergeModels(\n\t\t\t\tprovider.getModels(),\n\t\t\t\tdynamicModels.filter((model) => isModelType(model, \"chat\")),\n\t\t\t),\n\t\tgetAllModels: () => mergeModels(provider.getAllModels?.() ?? provider.getModels(), dynamicModels),\n\t\t// A separate remote catalog service serves the catalog, so a stale provider login must not block or fail its refresh.\n\t\trefreshModelsAuth: \"configured\",\n\t\trefreshModels: async (context) => {\n\t\t\tconst stored = context.stored;\n\t\t\tconst restored = remoteModels(stored, localGeneratedAt).filter((model) => model.provider === provider.id);\n\t\t\tif (\n\t\t\t\t!(await context.publish({\n\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\tdynamicModels = restored;\n\t\t\t\t\t},\n\t\t\t\t}))\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!context.allowNetwork || context.signal.aborted) return;\n\t\t\tif (!catalogBaseUrl) return;\n\t\t\t// Skip the request if the remote catalog was checked less than REMOTE_CATALOG_REFRESH_INTERVAL_MS ago.\n\t\t\t// An entry without lastModified (saved by an older draht, or after a failed first request) is\n\t\t\t// always refetched: remoteModels() ignores it, so waiting would leave the overlay empty.\n\t\t\tif (\n\t\t\t\t!context.force &&\n\t\t\t\tstored?.checkedAt !== undefined &&\n\t\t\t\tstored.lastModified !== undefined &&\n\t\t\t\tDate.now() - stored.checkedAt < REMOTE_CATALOG_REFRESH_INTERVAL_MS\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Only revalidate when a cached body backs the validator, so a 304 can never\n\t\t\t// leave the overlay empty.\n\t\t\tconst validator = stored && stored.models.length > 0 ? stored.etag : undefined;\n\t\t\tconst response = await requestCatalog(provider.id, catalogBaseUrl, context.signal, validator);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst checkedAt = Date.now();\n\t\t\t// Unchanged: dynamicModels already holds the stored overlay, so only the\n\t\t\t// freshness window moves.\n\t\t\tif (response.status === 304 && stored) {\n\t\t\t\tawait context.publish({ persist: { ...stored, checkedAt } });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (response.status === 404 || response.status === 501) {\n\t\t\t\tawait context.publish({\n\t\t\t\t\tpersist: {\n\t\t\t\t\t\t...(stored ?? { models: [] }),\n\t\t\t\t\t\tcheckedAt,\n\t\t\t\t\t\tlastModified: 0,\n\t\t\t\t\t\tetag: undefined,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!response.ok) {\n\t\t\t\t// Transient failure: the cached body and its validator stay valid, so keep the\n\t\t\t\t// etag and let the next refresh revalidate instead of downloading the catalog.\n\t\t\t\tawait context.publish({ persist: { ...(stored ?? { models: [] }), checkedAt } });\n\t\t\t\tthrow new Error(`Model catalog request failed for ${provider.id}: ${response.status}`);\n\t\t\t}\n\t\t\tconst catalog = await readCatalog(provider.id, response);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst entry: ModelsStoreEntry = { ...catalog, checkedAt };\n\t\t\tconst published = remoteModels(entry, localGeneratedAt);\n\t\t\tawait context.publish({\n\t\t\t\tpersist: entry,\n\t\t\t\tupdate: () => {\n\t\t\t\t\tdynamicModels = published;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n}\n\n/**\n * Like `withRemoteCatalog`, but on each network refresh the catalog (built-in models plus a newer\n * remote catalog) is passed through `personalize` and the result is saved. The saved entry holds\n * the personalized list, not the remote catalog, and replaces the catalog, including offline.\n * The refresh interval and etag revalidation are skipped. An empty list (nothing saved yet, or an\n * empty catalog saved by an older draht after a failed or missing remote catalog) falls back to the\n * built-in models.\n */\nexport function withPersonalizedCatalog(\n\tprovider: Provider,\n\tpersonalize: PersonalizeCatalog,\n\tcatalogBaseUrl: string | undefined = process.env[CATALOG_BASE_URL_ENV],\n\tlocalGeneratedAt?: number,\n): Provider {\n\tlet personalModels: readonly AnyModel[] = [];\n\tconst builtinModels = (): readonly AnyModel[] => provider.getAllModels?.() ?? provider.getModels();\n\tconst getAllModels = (): readonly AnyModel[] => (personalModels.length > 0 ? personalModels : builtinModels());\n\n\treturn {\n\t\t...provider,\n\t\tgetModels: () => getAllModels().filter((model) => isModelType(model, \"chat\")),\n\t\tgetAllModels,\n\t\trefreshModels: async (context) => {\n\t\t\tconst restored = (context.stored?.models ?? []).filter((model) => model.provider === provider.id);\n\t\t\tif (\n\t\t\t\t!(await context.publish({\n\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\tpersonalModels = restored;\n\t\t\t\t\t},\n\t\t\t\t}))\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!context.allowNetwork || context.signal.aborted) return;\n\n\t\t\tlet remote: readonly AnyModel[] = [];\n\t\t\tif (catalogBaseUrl) {\n\t\t\t\tconst response = await requestCatalog(provider.id, catalogBaseUrl, context.signal);\n\t\t\t\tif (context.signal.aborted) return;\n\t\t\t\tif (response.status !== 404 && response.status !== 501) {\n\t\t\t\t\tif (!response.ok) throw new Error(`Model catalog request failed for ${provider.id}: ${response.status}`);\n\t\t\t\t\tconst catalog = await readCatalog(provider.id, response);\n\t\t\t\t\tif (isNewer(catalog.lastModified, localGeneratedAt)) remote = catalog.models;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst personalized = await personalize(mergeModels(builtinModels(), remote), context);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tawait context.publish({\n\t\t\t\tpersist: { models: personalized, checkedAt: Date.now() },\n\t\t\t\tupdate: () => {\n\t\t\t\t\tpersonalModels = personalized;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n}\n"]}
@@ -3,6 +3,8 @@ import type { AuthOperationOptions, Credential, CredentialInfo, CredentialStore
3
3
  export declare class RuntimeCredentials implements CredentialStore {
4
4
  private readonly store;
5
5
  private readonly overrides;
6
+ /** Modifications not yet written or failed, for example an OAuth refresh. */
7
+ private readonly pendingModifications;
6
8
  constructor(store: CredentialStore);
7
9
  setRuntimeApiKey(providerId: string, apiKey: string): void;
8
10
  removeRuntimeApiKey(providerId: string): void;
@@ -10,6 +12,12 @@ export declare class RuntimeCredentials implements CredentialStore {
10
12
  read(providerId: string, options?: AuthOperationOptions): Promise<Credential | undefined>;
11
13
  list(options?: AuthOperationOptions): Promise<readonly CredentialInfo[]>;
12
14
  modify(providerId: string, fn: (current: Credential | undefined) => Promise<Credential | undefined>, options?: AuthOperationOptions): Promise<Credential | undefined>;
15
+ /**
16
+ * Resolves when every modification started so far is written or failed. An OAuth refresh may
17
+ * already have spent the single-use refresh token, so exiting before its result is written would
18
+ * leave only the spent token in auth.json.
19
+ */
20
+ settled(): Promise<void>;
13
21
  delete(providerId: string, options?: AuthOperationOptions): Promise<void>;
14
22
  }
15
23
  //# sourceMappingURL=runtime-credentials.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-credentials.d.ts","sourceRoot":"","sources":["../../src/core/runtime-credentials.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,UAAU,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEnG,0EAA0E;AAC1E,qBAAa,kBAAmB,YAAW,eAAe;IACzD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkB;IACxC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA6B;IAEvD,YAAY,KAAK,EAAE,eAAe,EAEjC;IAED,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAEzD;IAED,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAE5C;IAED,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAE5C;IAEK,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAI9F;IAEK,IAAI,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,SAAS,cAA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,EAAE,UAAU,GAAG,SAAS,KAAK,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,EACxE,OAAO,CAAC,EAAE,oBAAoB,GAC5B,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CASjC;IAED;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAE7B;IAEK,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAI9E;CACD"}
@@ -2,6 +2,8 @@
2
2
  export class RuntimeCredentials {
3
3
  store;
4
4
  overrides = new Map();
5
+ /** Modifications not yet written or failed, for example an OAuth refresh. */
6
+ pendingModifications = new Set();
5
7
  constructor(store) {
6
8
  this.store = store;
7
9
  }
@@ -28,7 +30,19 @@ export class RuntimeCredentials {
28
30
  return [...entries.values()];
29
31
  }
30
32
  modify(providerId, fn, options) {
31
- return this.store.modify(providerId, fn, options);
33
+ const modification = this.store.modify(providerId, fn, options);
34
+ const pending = modification.then(() => undefined, () => undefined);
35
+ this.pendingModifications.add(pending);
36
+ void pending.finally(() => this.pendingModifications.delete(pending));
37
+ return modification;
38
+ }
39
+ /**
40
+ * Resolves when every modification started so far is written or failed. An OAuth refresh may
41
+ * already have spent the single-use refresh token, so exiting before its result is written would
42
+ * leave only the spent token in auth.json.
43
+ */
44
+ async settled() {
45
+ await Promise.all(this.pendingModifications);
32
46
  }
33
47
  async delete(providerId, options) {
34
48
  options?.signal?.throwIfAborted();
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-credentials.js","sourceRoot":"","sources":["../../src/core/runtime-credentials.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAC1E,MAAM,OAAO,kBAAkB;IACb,KAAK,CAAkB;IACvB,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEvD,YAAY,KAAsB;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,gBAAgB,CAAC,UAAk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AED,MAAM,CACL,UAAkB,EAClB,EAAwE,EACxE,OAA8B;QAE9B,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,UAAkB,EAAE,OAA8B;QAC9D,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;QAClC,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAC7C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;CACD","sourcesContent":["import type { AuthOperationOptions, Credential, CredentialInfo, CredentialStore } from \"@draht/ai\";\n\n/** Async credential store overlay for non-persistent runtime API keys. */\nexport class RuntimeCredentials implements CredentialStore {\n\tprivate readonly store: CredentialStore;\n\tprivate readonly overrides = new Map<string, string>();\n\n\tconstructor(store: CredentialStore) {\n\t\tthis.store = store;\n\t}\n\n\tsetRuntimeApiKey(providerId: string, apiKey: string): void {\n\t\tthis.overrides.set(providerId, apiKey);\n\t}\n\n\tremoveRuntimeApiKey(providerId: string): void {\n\t\tthis.overrides.delete(providerId);\n\t}\n\n\thasRuntimeApiKey(providerId: string): boolean {\n\t\treturn this.overrides.has(providerId);\n\t}\n\n\tasync read(providerId: string, options?: AuthOperationOptions): Promise<Credential | undefined> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tconst override = this.overrides.get(providerId);\n\t\treturn override ? { type: \"api_key\", key: override } : this.store.read(providerId, options);\n\t}\n\n\tasync list(options?: AuthOperationOptions): Promise<readonly CredentialInfo[]> {\n\t\tconst entries = new Map((await this.store.list(options)).map((entry) => [entry.providerId, entry]));\n\t\toptions?.signal?.throwIfAborted();\n\t\tfor (const providerId of this.overrides.keys()) {\n\t\t\tentries.set(providerId, { providerId, type: \"api_key\" });\n\t\t}\n\t\treturn [...entries.values()];\n\t}\n\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\t\treturn this.store.modify(providerId, fn, options);\n\t}\n\n\tasync delete(providerId: string, options?: AuthOperationOptions): Promise<void> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tawait this.store.delete(providerId, options);\n\t\tthis.overrides.delete(providerId);\n\t}\n}\n"]}
1
+ {"version":3,"file":"runtime-credentials.js","sourceRoot":"","sources":["../../src/core/runtime-credentials.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAC1E,MAAM,OAAO,kBAAkB;IACb,KAAK,CAAkB;IACvB,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAC;IACvD,6EAA6E;IAC5D,oBAAoB,GAAG,IAAI,GAAG,EAAiB,CAAC;IAEjE,YAAY,KAAsB;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,gBAAgB,CAAC,UAAkB,EAAE,MAAc;QAClD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;IAED,mBAAmB,CAAC,UAAkB;QACrC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;IAED,gBAAgB,CAAC,UAAkB;QAClC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,UAAkB,EAAE,OAA8B;QAC5D,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;QAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAChD,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CA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C,UAAkB,EAAE,OAA8B;QAC9D,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;QAClC,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAC7C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;CACD","sourcesContent":["import type { AuthOperationOptions, Credential, CredentialInfo, CredentialStore } from \"@draht/ai\";\n\n/** Async credential store overlay for non-persistent runtime API keys. */\nexport class RuntimeCredentials implements CredentialStore {\n\tprivate readonly store: CredentialStore;\n\tprivate readonly overrides = new Map<string, string>();\n\t/** Modifications not yet written or failed, for example an OAuth refresh. */\n\tprivate readonly pendingModifications = new Set<Promise<void>>();\n\n\tconstructor(store: CredentialStore) {\n\t\tthis.store = store;\n\t}\n\n\tsetRuntimeApiKey(providerId: string, apiKey: string): void {\n\t\tthis.overrides.set(providerId, apiKey);\n\t}\n\n\tremoveRuntimeApiKey(providerId: string): void {\n\t\tthis.overrides.delete(providerId);\n\t}\n\n\thasRuntimeApiKey(providerId: string): boolean {\n\t\treturn this.overrides.has(providerId);\n\t}\n\n\tasync read(providerId: string, options?: AuthOperationOptions): Promise<Credential | undefined> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tconst override = this.overrides.get(providerId);\n\t\treturn override ? { type: \"api_key\", key: override } : this.store.read(providerId, options);\n\t}\n\n\tasync list(options?: AuthOperationOptions): Promise<readonly CredentialInfo[]> {\n\t\tconst entries = new Map((await this.store.list(options)).map((entry) => [entry.providerId, entry]));\n\t\toptions?.signal?.throwIfAborted();\n\t\tfor (const providerId of this.overrides.keys()) {\n\t\t\tentries.set(providerId, { providerId, type: \"api_key\" });\n\t\t}\n\t\treturn [...entries.values()];\n\t}\n\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\t\tconst modification = this.store.modify(providerId, fn, options);\n\t\tconst pending = modification.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\tthis.pendingModifications.add(pending);\n\t\tvoid pending.finally(() => this.pendingModifications.delete(pending));\n\t\treturn modification;\n\t}\n\n\t/**\n\t * Resolves when every modification started so far is written or failed. An OAuth refresh may\n\t * already have spent the single-use refresh token, so exiting before its result is written would\n\t * leave only the spent token in auth.json.\n\t */\n\tasync settled(): Promise<void> {\n\t\tawait Promise.all(this.pendingModifications);\n\t}\n\n\tasync delete(providerId: string, options?: AuthOperationOptions): Promise<void> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tawait this.store.delete(providerId, options);\n\t\tthis.overrides.delete(providerId);\n\t}\n}\n"]}
@@ -10,6 +10,13 @@ interface SessionCwdSource {
10
10
  export declare function getMissingSessionCwdIssue(sessionManager: SessionCwdSource, fallbackCwd: string): SessionCwdIssue | undefined;
11
11
  export declare function formatMissingSessionCwdError(issue: SessionCwdIssue): string;
12
12
  export declare function formatMissingSessionCwdPrompt(issue: SessionCwdIssue): string;
13
+ /** How to open a session whose stored cwd is missing: run it in the current cwd once, or fork it there. */
14
+ export type MissingSessionCwdChoice = "continue" | "fork";
15
+ /** Prompt options for a missing session cwd, naming the current cwd; `undefined` cancels. */
16
+ export declare function getMissingSessionCwdOptions(issue: SessionCwdIssue): Array<{
17
+ label: string;
18
+ value: MissingSessionCwdChoice | undefined;
19
+ }>;
13
20
  export declare class MissingSessionCwdError extends Error {
14
21
  readonly issue: SessionCwdIssue;
15
22
  constructor(issue: SessionCwdIssue);
@@ -1 +1 @@
1
- {"version":3,"file":"session-cwd.d.ts","sourceRoot":"","sources":["../../src/core/session-cwd.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,gBAAgB;IACzB,MAAM,IA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C;IAAC,KAAK,EAAE,uBAAuB,GAAG,SAAS,CAAA;CAAE,CAAC,CAMtE;AAED,qBAAa,sBAAuB,SAAQ,KAAK;IAChD,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;IAEhC,YAAY,KAAK,EAAE,eAAe,EAIjC;CACD;AAED,wBAAgB,sBAAsB,CAAC,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAKlG"}
@@ -19,7 +19,15 @@ export function formatMissingSessionCwdError(issue) {
19
19
  return `Stored session working directory does not exist: ${issue.sessionCwd}${sessionFile}\nCurrent working directory: ${issue.fallbackCwd}`;
20
20
  }
21
21
  export function formatMissingSessionCwdPrompt(issue) {
22
- return `cwd from session file does not exist\n${issue.sessionCwd}\n\ncontinue in current cwd\n${issue.fallbackCwd}`;
22
+ return `Session cwd does not exist: ${issue.sessionCwd}`;
23
+ }
24
+ /** Prompt options for a missing session cwd, naming the current cwd; `undefined` cancels. */
25
+ export function getMissingSessionCwdOptions(issue) {
26
+ return [
27
+ { label: `Continue in ${issue.fallbackCwd} (asks again next time)`, value: "continue" },
28
+ { label: `Fork into ${issue.fallbackCwd} (new session ID, original kept)`, value: "fork" },
29
+ { label: "Cancel", value: undefined },
30
+ ];
23
31
  }
24
32
  export class MissingSessionCwdError extends Error {
25
33
  issue;