@noxsoft/anima 2.0.2 → 2.0.4

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 (829) hide show
  1. package/README.md +1260 -28
  2. package/dist/accounts-Bth3PpPD.js +260 -0
  3. package/dist/accounts-D8CPKNkN.js +259 -0
  4. package/dist/acp-cli-ByK6lS6c.js +1081 -0
  5. package/dist/acp-cli-CaQCjIw4.js +1084 -0
  6. package/dist/agent-BgIkqd3F.js +725 -0
  7. package/dist/agent-N5BDcge4.js +725 -0
  8. package/dist/agent-events-COH7NDW2.js +182 -0
  9. package/dist/agent-scope-CPphqq-U.js +452 -0
  10. package/dist/agent-scope-DZgptr9J.js +452 -0
  11. package/dist/agent-scope-cj2QCT6R.js +112 -0
  12. package/dist/agents-NEudYMdg.js +774 -0
  13. package/dist/agents.config-Bujs-NIy.js +182 -0
  14. package/dist/agents.config-jp7OLssr.js +182 -0
  15. package/dist/argv-BMZMiW7v.js +73 -0
  16. package/dist/audit-C-UJhfdv.js +2401 -0
  17. package/dist/audit-CeCO7SK5.js +2401 -0
  18. package/dist/auth-BNZsOHGF.js +648 -0
  19. package/dist/auth-DMPZWzEa.js +639 -0
  20. package/dist/auth-choice-5VnaGMD-.js +2681 -0
  21. package/dist/auth-choice-DA2k4vs8.js +2681 -0
  22. package/dist/auth-health-B7FqA26_.js +149 -0
  23. package/dist/auth-health-VO_MPqVX.js +149 -0
  24. package/dist/auth-profiles-BDrNYX_n.js +1564 -0
  25. package/dist/auth-profiles-CxSHydjn.js +2689 -0
  26. package/dist/banner-BtDZPRzi.js +294 -0
  27. package/dist/browser-cli-8yQMpxb8.js +1679 -0
  28. package/dist/browser-cli-Czg3JtDH.js +1676 -0
  29. package/dist/build-info.json +3 -3
  30. package/dist/bundled/boot-md/handler.js +16 -16
  31. package/dist/bundled/bootstrap-extra-files/handler.js +4 -4
  32. package/dist/bundled/command-logger/handler.js +1 -1
  33. package/dist/bundled/session-memory/handler.js +5 -5
  34. package/dist/call-BIzCaKZb.js +282 -0
  35. package/dist/call-BYDpTVCZ.js +282 -0
  36. package/dist/canvas-host/a2ui/.bundle.hash +1 -1
  37. package/dist/catalog-CqKiUgu6.js +185 -0
  38. package/dist/catalog-DMfEg-oK.js +185 -0
  39. package/dist/channel-options-BrtCtyrT.js +32 -0
  40. package/dist/channel-options-CO21Gl8p.js +33 -0
  41. package/dist/channel-selection-Bbm1lq3P.js +51 -0
  42. package/dist/channel-selection-CqcX7Ocw.js +51 -0
  43. package/dist/channel-web-DrsT6OAE.js +2162 -0
  44. package/dist/channels-cli-Juyh1S6n.js +1304 -0
  45. package/dist/channels-cli-zNvi1m5c.js +1306 -0
  46. package/dist/channels-status-issues-CqzqshW4.js +18 -0
  47. package/dist/channels-status-issues-DdJdO866.js +18 -0
  48. package/dist/chrome-C4dOMO8z.js +1601 -0
  49. package/dist/chrome-DdcDzAtH.js +1629 -0
  50. package/dist/chrome-U3DRzjJD.js +1601 -0
  51. package/dist/chunk-D2nLsrEW.js +348 -0
  52. package/dist/clack-prompter-BI3RDW5w.js +92 -0
  53. package/dist/clack-prompter-Dwr1m_IZ.js +92 -0
  54. package/dist/cli/daemon-cli.js +1 -1
  55. package/dist/cli-C3cpDaz8.js +99 -0
  56. package/dist/cli-CjWUGdGC.js +101 -0
  57. package/dist/cli-session-BVjY_XrW.js +5463 -0
  58. package/dist/cli-session-gtuYN2Iq.js +5408 -0
  59. package/dist/client-Dswwze5_.js +1692 -0
  60. package/dist/client-LRKFjo4A.js +1692 -0
  61. package/dist/clipboard-BZKS9O1u.js +31 -0
  62. package/dist/clipboard-DES8b1AM.js +31 -0
  63. package/dist/command-format-CP1YTNCl.js +52 -0
  64. package/dist/command-format-CVL4K5cj.js +52 -0
  65. package/dist/command-format-G6N2zghg.js +38 -0
  66. package/dist/command-registry-BBvNvysr.js +248 -0
  67. package/dist/commands-AZ3n8Y2c.js +726 -0
  68. package/dist/commands-BMnD_QRY.js +726 -0
  69. package/dist/commands-registry-cFqZ6Ib4.js +766 -0
  70. package/dist/commands-registry-q13H7ng5.js +766 -0
  71. package/dist/common-CX5458fH.js +287 -0
  72. package/dist/common-DJbnT8ws.js +287 -0
  73. package/dist/completion-cli-BADRBcIl.js +432 -0
  74. package/dist/completion-cli-DMQgiObF.js +431 -0
  75. package/dist/config-CU-Axg8P.js +5704 -0
  76. package/dist/config-DaqbUdkI.js +5705 -0
  77. package/dist/config-cli-BPlbwiuA.js +244 -0
  78. package/dist/config-cli-DXgZJkPU.js +247 -0
  79. package/dist/config-guard-Ba49JNds.js +76 -0
  80. package/dist/config-guard-Cu0qMKZJ.js +93 -0
  81. package/dist/config-kVVm5EYV.js +6523 -0
  82. package/dist/config-sync-CzLnLTXt.js +91 -0
  83. package/dist/config-sync-DuydxPWx.js +91 -0
  84. package/dist/configure-CHgacLyi.js +960 -0
  85. package/dist/configure-DfHXDa1L.js +959 -0
  86. package/dist/context-DzgXOckU.js +60 -0
  87. package/dist/control-service-8_wKHwBa.js +72 -0
  88. package/dist/control-service-BtL1Jto_.js +72 -0
  89. package/dist/cron-cli-BCzSR2c0.js +448 -0
  90. package/dist/cron-cli-CCWNkykU.js +451 -0
  91. package/dist/daemon-cli-Bjkbu9Vy.js +565 -0
  92. package/dist/daemon-cli-CmlHcC1J.js +566 -0
  93. package/dist/daemon-cli.js +16 -16
  94. package/dist/daemon-runtime-C0tz7VAC.js +460 -0
  95. package/dist/daemon-runtime-rUTqCVwJ.js +460 -0
  96. package/dist/deliver-BBggsviM.js +1097 -0
  97. package/dist/deliver-CePITOl8.js +1162 -0
  98. package/dist/deliver-DFnVaetP.js +1097 -0
  99. package/dist/delivery-queue-BJQK3oh5.js +220 -0
  100. package/dist/deps-CeEKhrp7.js +42 -0
  101. package/dist/devices-cli-DQrDMrZH.js +198 -0
  102. package/dist/devices-cli-Oe-A1Dv0.js +195 -0
  103. package/dist/diagnostics-DxMFrBLO.js +35 -0
  104. package/dist/diagnostics-m79ZlMmZ.js +35 -0
  105. package/dist/directory-cli-BL6h8cGF.js +246 -0
  106. package/dist/directory-cli-Cjgmi_sj.js +243 -0
  107. package/dist/dispatcher-DAFbQM-c.js +100 -0
  108. package/dist/dispatcher-DNd40gUn.js +100 -0
  109. package/dist/dist-CqDI82ei.js +929 -0
  110. package/dist/dist-DnHRxR5U.js +929 -0
  111. package/dist/dns-cli-CFtV3BXK.js +200 -0
  112. package/dist/dns-cli-NyIHvQ5S.js +197 -0
  113. package/dist/dock-BdXLb5oY.js +753 -0
  114. package/dist/dock-jYICmNcI.js +753 -0
  115. package/dist/docs-cli-CrOaIK_H.js +161 -0
  116. package/dist/docs-cli-D_cmJDSr.js +159 -0
  117. package/dist/doctor-BpGxKrBl.js +1815 -0
  118. package/dist/doctor-D12wNQPU.js +1813 -0
  119. package/dist/doctor-completion-DeOfofek.js +92 -0
  120. package/dist/doctor-completion-DwjqdEcK.js +92 -0
  121. package/dist/doctor-config-flow-BI3mpkbd.js +1232 -0
  122. package/dist/doctor-config-flow-wMHheFkC.js +1232 -0
  123. package/dist/engine-BCtL-AMw.js +563 -0
  124. package/dist/engine-Bk_UT413.js +563 -0
  125. package/dist/entry.js +5 -5
  126. package/dist/env-v6411I8h.js +32 -0
  127. package/dist/exec-B7sUS164.js +1167 -0
  128. package/dist/exec-approvals-CroGJRUg.js +1221 -0
  129. package/dist/exec-approvals-cli-BTxF_RsH.js +371 -0
  130. package/dist/exec-approvals-cli-n1gyGwH2.js +368 -0
  131. package/dist/exec-mhSykkaa.js +255 -0
  132. package/dist/extensionAPI.js +3 -3
  133. package/dist/frontmatter-BmHq0vRD.js +204 -0
  134. package/dist/gateway-cli-DDBadlrS.js +19971 -0
  135. package/dist/gateway-cli-IZNkOMBe.js +19972 -0
  136. package/dist/gateway-rpc-Dtx8HN-n.js +28 -0
  137. package/dist/gateway-rpc-L2PVSqGj.js +28 -0
  138. package/dist/github-copilot-auth-DKyqDaGU.js +1418 -0
  139. package/dist/github-copilot-auth-DXpOMSd3.js +1418 -0
  140. package/dist/gmail-setup-utils-BKNczIJ9.js +428 -0
  141. package/dist/gmail-setup-utils-co0ppccC.js +428 -0
  142. package/dist/health-Bm8ZTvC3.js +1253 -0
  143. package/dist/health-DUf1gt4E.js +1258 -0
  144. package/dist/health-format-BksT6F68.js +208 -0
  145. package/dist/health-format-uzh1xYLD.js +208 -0
  146. package/dist/heartbeat-visibility-1TJb1Zao.js +98 -0
  147. package/dist/heartbeat-visibility-CwodtdcX.js +98 -0
  148. package/dist/help-format-C6cv_aZp.js +17 -0
  149. package/dist/helpers-N-uSFKOn.js +10 -0
  150. package/dist/hooks-cli-1POsXqOl.js +993 -0
  151. package/dist/hooks-cli-BGjILbze.js +991 -0
  152. package/dist/hooks-status-DE07n5RC.js +356 -0
  153. package/dist/hooks-status-Du-d1jde.js +356 -0
  154. package/dist/image-ops-B_AYV3tp.js +541 -0
  155. package/dist/image-ops-Bp0C6Mvr.js +541 -0
  156. package/dist/index.js +82 -82
  157. package/dist/init-9A0s7bWG.js +122 -0
  158. package/dist/init-DoyCHJDC.js +122 -0
  159. package/dist/installs-D1C9wHAq.js +383 -0
  160. package/dist/installs-Dh4dHayM.js +383 -0
  161. package/dist/ipv4-DCItfaJo.js +1964 -0
  162. package/dist/ipv4-DSOUVx0i.js +1964 -0
  163. package/dist/lanes-BvSnHq2h.js +232 -0
  164. package/dist/lifecycle-core-BY4WIf9g.js +388 -0
  165. package/dist/lifecycle-core-TQKyXO-6.js +387 -0
  166. package/dist/links-CNu_8RZl.js +15 -0
  167. package/dist/links-D2tt2ouh.js +15 -0
  168. package/dist/llm-slug-generator.js +4 -4
  169. package/dist/logging-BIeRw0WR.js +15 -0
  170. package/dist/logging-C7lb3Vjc.js +15 -0
  171. package/dist/login-DXWKewA2.js +59 -0
  172. package/dist/login-Fhh4uWmf.js +61 -0
  173. package/dist/login-pPs3UO38.js +61 -0
  174. package/dist/login-qr-CevLD8cV.js +326 -0
  175. package/dist/login-qr-GF2JMIy-.js +323 -0
  176. package/dist/login-qr-ZYYKD6Yt.js +321 -0
  177. package/dist/logs-cli-CzXbX8HZ.js +242 -0
  178. package/dist/logs-cli-D9ngH9PF.js +245 -0
  179. package/dist/manager-BD5rA3w0.js +3244 -0
  180. package/dist/manager-BDPgBQSH.js +3246 -0
  181. package/dist/manager-DRWMWM--.js +3244 -0
  182. package/dist/manifest-registry-DbvPaBXY.js +748 -0
  183. package/dist/manifest-registry-kHX_MFa1.js +748 -0
  184. package/dist/markdown-tables-CqwihY2m.js +347 -0
  185. package/dist/markdown-tables-DJV7eAJZ.js +348 -0
  186. package/dist/media-lUqN-0O9.js +1342 -0
  187. package/dist/memory-cli-BLXSpgnN.js +868 -0
  188. package/dist/memory-cli-BcGVkkRJ.js +869 -0
  189. package/dist/message-channel-D_jIO87f.js +110 -0
  190. package/dist/migrate-BpVOar4L.js +157 -0
  191. package/dist/migrate-CkgGDkWy.js +157 -0
  192. package/dist/model-selection-Cqt6aJ0G.js +2691 -0
  193. package/dist/models-CExsNQPH.js +2510 -0
  194. package/dist/models-cli-Ba3Jmwev.js +2739 -0
  195. package/dist/models-cli-iDAlsbL2.js +258 -0
  196. package/dist/net-0A_zcaQD.js +218 -0
  197. package/dist/node-cli-ATmwCXIk.js +1319 -0
  198. package/dist/node-cli-DYFR_V25.js +1322 -0
  199. package/dist/node-service-CN4LqR1A.js +67 -0
  200. package/dist/node-service-CWt3MdSC.js +67 -0
  201. package/dist/nodes-cli-BeVmhTz3.js +1197 -0
  202. package/dist/nodes-cli-QeJIfa18.js +1200 -0
  203. package/dist/nodes-screen-DHyWAlla.js +234 -0
  204. package/dist/nodes-screen-qs3jRBPk.js +234 -0
  205. package/dist/note-CSlg2BnB.js +73 -0
  206. package/dist/note-Ctvglhp1.js +73 -0
  207. package/dist/npm-registry-spec-DQd4M22q.js +351 -0
  208. package/dist/npm-registry-spec-PxisIMts.js +351 -0
  209. package/dist/onboard-DeruD10m.js +1166 -0
  210. package/dist/onboard-SAcu5N6N.js +1165 -0
  211. package/dist/onboard-channels-C4iSfFXR.js +672 -0
  212. package/dist/onboard-channels-oVTVgoyg.js +672 -0
  213. package/dist/onboard-helpers-B8roRwLP.js +365 -0
  214. package/dist/onboard-helpers-Dgh26hgP.js +365 -0
  215. package/dist/onboarding-Bi-ac8we.js +911 -0
  216. package/dist/onboarding-C2gjB2u8.js +910 -0
  217. package/dist/orchestrator-DlbAYMQP.js +357 -0
  218. package/dist/orchestrator-DlwVRVDA.js +357 -0
  219. package/dist/outbound-CkKgc6iR.js +2062 -0
  220. package/dist/outbound-Vfm5yDh3.js +214 -0
  221. package/dist/outbound-bs_VK51X.js +214 -0
  222. package/dist/outbound-send-deps-DDjiMfEL.js +55 -0
  223. package/dist/pairing-cli-CJYeuEik.js +118 -0
  224. package/dist/pairing-cli-mqopHI8s.js +121 -0
  225. package/dist/pairing-store-BsXzUDPv.js +388 -0
  226. package/dist/pairing-store-DoNj00-X.js +388 -0
  227. package/dist/path-env-C_xpiG8l.js +89 -0
  228. package/dist/path-env-DSSMHu5A.js +89 -0
  229. package/dist/paths-B1vRVCad.js +126 -0
  230. package/dist/paths-BMuHNFxg.js +238 -0
  231. package/dist/paths-BXQQzXGQ.js +129 -0
  232. package/dist/paths-Buw_geoe.js +54 -0
  233. package/dist/paths-DA9WYabg.js +222 -0
  234. package/dist/paths-DfQGx0_k.js +129 -0
  235. package/dist/pi-auth-json-DOPW3e4X.js +78 -0
  236. package/dist/pi-auth-json-MruLmI_X.js +82 -0
  237. package/dist/pi-auth-json-lae_wwwo.js +80 -0
  238. package/dist/pi-model-discovery-7q0GxMrp.js +3 -0
  239. package/dist/pi-tools.policy-Csmla32P.js +200 -0
  240. package/dist/pi-tools.policy-xYdDLEv9.js +200 -0
  241. package/dist/plugin-auto-enable-CViVVWgg.js +282 -0
  242. package/dist/plugin-auto-enable-CjZ238UI.js +282 -0
  243. package/dist/plugin-registry-B4Aw2hzq.js +32 -0
  244. package/dist/plugin-registry-DW81arxW.js +32 -0
  245. package/dist/plugin-sdk/cli/cli-name.d.ts +1 -1
  246. package/dist/plugin-sdk/config/paths.d.ts +2 -2
  247. package/dist/plugin-sdk/index.js +7 -7
  248. package/dist/plugins-DhcGAPDB.js +38 -0
  249. package/dist/plugins-DtghNRtM.js +168 -0
  250. package/dist/plugins-cli-4vWTmOAb.js +736 -0
  251. package/dist/plugins-cli-CdTMbP0X.js +734 -0
  252. package/dist/polls-D6eCdatA.js +1343 -0
  253. package/dist/ports-BtZx-JKD.js +96 -0
  254. package/dist/ports-C8bKN8s0.js +96 -0
  255. package/dist/ports-DHiKnPRX.js +344 -0
  256. package/dist/ports-vd93M_Pt.js +317 -0
  257. package/dist/program-CX3aUVeb.js +176 -0
  258. package/dist/program-context-BPos0ivo.js +496 -0
  259. package/dist/progress-oiAjiiNi.js +133 -0
  260. package/dist/prompt-style-Cm4wOtKm.js +9 -0
  261. package/dist/pw-ai-4QbK5YFe.js +1865 -0
  262. package/dist/pw-ai-BWz3Cxt7.js +1868 -0
  263. package/dist/pw-ai-C83HBue2.js +1867 -0
  264. package/dist/qmd-manager-BcMeZiGD.js +938 -0
  265. package/dist/qmd-manager-CPypGJ0P.js +935 -0
  266. package/dist/qmd-manager-CRrSkfia.js +937 -0
  267. package/dist/register.agent-DDY8KJhn.js +265 -0
  268. package/dist/register.agent-DKawm-9d.js +1003 -0
  269. package/dist/register.anima-CEWUo29k.js +193 -0
  270. package/dist/register.anima-DBWz2rk_.js +193 -0
  271. package/dist/register.configure-BX67qV8k.js +103 -0
  272. package/dist/register.configure-CWsySuiq.js +101 -0
  273. package/dist/register.maintenance-0k-ZNhDg.js +543 -0
  274. package/dist/register.maintenance-BIwx1fzX.js +543 -0
  275. package/dist/register.message-CXPsoakA.js +657 -0
  276. package/dist/register.message-DA3jvfgI.js +660 -0
  277. package/dist/register.onboard-C4HG7Hqv.js +170 -0
  278. package/dist/register.onboard-GOpdif-j.js +170 -0
  279. package/dist/register.setup-B17vZT7C.js +175 -0
  280. package/dist/register.setup-GJyUDCqh.js +175 -0
  281. package/dist/register.status-health-sessions-D5876dGx.js +313 -0
  282. package/dist/register.status-health-sessions-lOewVIZR.js +142 -0
  283. package/dist/register.subclis-Dwnujj5C.js +255 -0
  284. package/dist/reply-CR5T_oQJ.js +32212 -0
  285. package/dist/reply-prefix-BcrS4Umd.js +100 -0
  286. package/dist/reply-prefix-Btb5o2NH.js +100 -0
  287. package/dist/reply-r089HuRA.js +32212 -0
  288. package/dist/routes-B4czFzIb.js +1820 -0
  289. package/dist/routes-ucJWAk5O.js +1820 -0
  290. package/dist/rpc-BnKxnQ0v.js +70 -0
  291. package/dist/rpc-DgE-xnyx.js +70 -0
  292. package/dist/run-main-B74kv84C.js +371 -0
  293. package/dist/runtime-guard-CKFdts2L.js +60 -0
  294. package/dist/sandbox-CJTS3er6.js +858 -0
  295. package/dist/sandbox-DBSiVHt_.js +859 -0
  296. package/dist/sandbox-cli-CrkjyU5M.js +461 -0
  297. package/dist/sandbox-cli-D1r5y6Sz.js +458 -0
  298. package/dist/security-cli-BZUdnkhn.js +462 -0
  299. package/dist/security-cli-DS09ebvA.js +465 -0
  300. package/dist/server-context-C0xZbYhg.js +824 -0
  301. package/dist/server-context-DVh2z7om.js +824 -0
  302. package/dist/server-node-events-bu9lpkMH.js +233 -0
  303. package/dist/server-node-events-i1Rrww31.js +231 -0
  304. package/dist/service-CJJwLEor.js +642 -0
  305. package/dist/service-DxLxBhaU.js +642 -0
  306. package/dist/service-audit-DB4Y3Ekp.js +488 -0
  307. package/dist/service-audit-M8y4TXVb.js +488 -0
  308. package/dist/session-CGxOLFs2.js +179 -0
  309. package/dist/session-DTTbdKb0.js +181 -0
  310. package/dist/session-cost-usage-FcdJl9c3.js +600 -0
  311. package/dist/session-cost-usage-qdfsGU2a.js +600 -0
  312. package/dist/session-yOhWcsD2.js +181 -0
  313. package/dist/sessions-B-Cu7JZq.js +1296 -0
  314. package/dist/sessions-BgLN4KFr.js +180 -0
  315. package/dist/sessions-CnRjwdVr.js +1296 -0
  316. package/dist/sessions-wRKla1Qh.js +2038 -0
  317. package/dist/shared-DS3UaJSP.js +66 -0
  318. package/dist/shared-DxNHzky3.js +77 -0
  319. package/dist/shared-Qpt4hUDi.js +66 -0
  320. package/dist/shared-kzrojZ1B.js +77 -0
  321. package/dist/skill-scanner-DLJji5Ye.js +263 -0
  322. package/dist/skills-BWFIEp4j.js +807 -0
  323. package/dist/skills-DV4zKdCx.js +808 -0
  324. package/dist/skills-cli-BY53ILm2.js +289 -0
  325. package/dist/skills-cli-CO3gxl8A.js +286 -0
  326. package/dist/skills-status-DX5pcqY3.js +166 -0
  327. package/dist/skills-status-zhcKzGkp.js +166 -0
  328. package/dist/sqlite-B6MojU1I.js +321 -0
  329. package/dist/sqlite-CuprTGR7.js +453 -0
  330. package/dist/sqlite-dzD-jMjs.js +368 -0
  331. package/dist/start-Cu3aLoSf.js +297 -0
  332. package/dist/start-Dz7tMAl8.js +296 -0
  333. package/dist/status-CaSxhxfV.js +2132 -0
  334. package/dist/status-D2C0JCX3.js +2137 -0
  335. package/dist/status-DlFMsQzh.js +27 -0
  336. package/dist/status-G0CITnKR.js +27 -0
  337. package/dist/status.update-CHjhVxJY.js +79 -0
  338. package/dist/status.update-DVFelehi.js +79 -0
  339. package/dist/subagent-registry-3Xb4el-8.js +14 -0
  340. package/dist/subagent-registry-CdSjz14I.js +2760 -0
  341. package/dist/subagent-registry-DNDhbHWi.js +2759 -0
  342. package/dist/subsystem-DfKstnEK.js +860 -0
  343. package/dist/system-cli-B5mt0FWa.js +82 -0
  344. package/dist/system-cli-Dg3UQ3Zz.js +79 -0
  345. package/dist/systemd-B43AvOGx.js +452 -0
  346. package/dist/systemd-RpPE0XGg.js +452 -0
  347. package/dist/systemd-hints-DMJT-Bbc.js +36 -0
  348. package/dist/systemd-hints-vRInKcz9.js +36 -0
  349. package/dist/systemd-linger-Dzyxqsod.js +75 -0
  350. package/dist/systemd-linger-EujbmI5A.js +75 -0
  351. package/dist/table-DhXHfRX2.js +279 -0
  352. package/dist/table-bWCLW-3P.js +279 -0
  353. package/dist/timeout-Ddn-5kAO.js +232 -0
  354. package/dist/tokens-3psI_Qk2.js +14 -0
  355. package/dist/tokens-BaM53PEx.js +14 -0
  356. package/dist/trash-Bmxs1Rnm.js +23 -0
  357. package/dist/trash-C39a6hKA.js +23 -0
  358. package/dist/tui-BHgBWhHE.js +3894 -0
  359. package/dist/tui-cli-B9Sq5-cC.js +50 -0
  360. package/dist/tui-cli-Dw7v4JoJ.js +47 -0
  361. package/dist/tui-mUwDwqvd.js +3894 -0
  362. package/dist/update-DF0GHG0j.js +317 -0
  363. package/dist/update-DoZLVjva.js +317 -0
  364. package/dist/update-check-Bt1dVPVN.js +400 -0
  365. package/dist/update-check-D5qAKes7.js +400 -0
  366. package/dist/update-cli-BNu2Oi7H.js +1105 -0
  367. package/dist/update-cli-D36AmALA.js +1105 -0
  368. package/dist/update-runner-CNQQaTwA.js +894 -0
  369. package/dist/update-runner-CvxZmbu-.js +894 -0
  370. package/dist/usage-BGCwNnjk.js +4516 -0
  371. package/dist/utils-DZ8pnOD5.js +243 -0
  372. package/dist/web-B5QG839O.js +46842 -0
  373. package/dist/web-Cmnvk9v0.js +2203 -0
  374. package/dist/web-Cv2KnTnL.js +63 -0
  375. package/dist/webhooks-cli-B6y89Pj_.js +319 -0
  376. package/dist/webhooks-cli-BDzHON4w.js +316 -0
  377. package/dist/whatsapp-actions-C_5MwVxM.js +45 -0
  378. package/dist/whatsapp-actions-hgYA12To.js +53 -0
  379. package/dist/whatsapp-actions-zTiVOoOV.js +49 -0
  380. package/dist/widearea-dns-BeIdnISJ.js +127 -0
  381. package/dist/widearea-dns-CF1gxpJ-.js +127 -0
  382. package/dist/workspace-DLna1IxR.js +649 -0
  383. package/dist/ws-log-Q4wO1Ztb.js +267 -0
  384. package/dist/ws-log-xF0kxDzp.js +267 -0
  385. package/package.json +1 -2
  386. package/dist/accounts-Cc5E4IDO.js +0 -260
  387. package/dist/accounts-CcVrwKqv.js +0 -259
  388. package/dist/acp-cli-DvphOKuh.js +0 -1081
  389. package/dist/acp-cli-p28pQ65a.js +0 -1084
  390. package/dist/agent-Cj7uDJaZ.js +0 -725
  391. package/dist/agent-Cuj9-2sT.js +0 -725
  392. package/dist/agent-events-BEBQsyE5.js +0 -182
  393. package/dist/agent-scope-BVf4aSwY.js +0 -112
  394. package/dist/agent-scope-OZi7lb8S.js +0 -452
  395. package/dist/agent-scope-V1bi9OYL.js +0 -452
  396. package/dist/agents-BUWqn_Ui.js +0 -774
  397. package/dist/agents.config-Dvo2ULxs.js +0 -182
  398. package/dist/agents.config-d6H0_3oj.js +0 -182
  399. package/dist/argv-DqUHKf0o.js +0 -73
  400. package/dist/audit-C6okOOSh.js +0 -2401
  401. package/dist/audit-VWjIdwC7.js +0 -2401
  402. package/dist/auth-91o2YM96.js +0 -648
  403. package/dist/auth-choice-CAmACV13.js +0 -2681
  404. package/dist/auth-choice-p3SeHPj2.js +0 -2681
  405. package/dist/auth-health-B_jXrWe6.js +0 -149
  406. package/dist/auth-health-DCicUKYR.js +0 -149
  407. package/dist/auth-lZ26wsbN.js +0 -639
  408. package/dist/auth-profiles-CCDD56dU.js +0 -1564
  409. package/dist/auth-profiles-DxI8L7bs.js +0 -2689
  410. package/dist/banner-Cohn04J6.js +0 -294
  411. package/dist/browser-cli-DANzjztE.js +0 -1676
  412. package/dist/browser-cli-WjsVH741.js +0 -1679
  413. package/dist/call-BAHvlu2G.js +0 -282
  414. package/dist/call-Ct7EGP_L.js +0 -282
  415. package/dist/catalog-BAayBt1L.js +0 -185
  416. package/dist/catalog-BNsf97BM.js +0 -185
  417. package/dist/channel-options-Dx9nPlX8.js +0 -33
  418. package/dist/channel-options-ZdvXrTGs.js +0 -32
  419. package/dist/channel-selection-CujyiWGM.js +0 -51
  420. package/dist/channel-selection-DfGpCyh2.js +0 -51
  421. package/dist/channel-web-CC0hkgkR.js +0 -2162
  422. package/dist/channels-cli-D7lNBpIb.js +0 -1304
  423. package/dist/channels-cli-DUPG8WDv.js +0 -1306
  424. package/dist/channels-status-issues-DBc1pU_R.js +0 -18
  425. package/dist/channels-status-issues-DjO9MHIG.js +0 -18
  426. package/dist/chrome-Bi6iZ5sG.js +0 -1601
  427. package/dist/chrome-DNSv7Cpy.js +0 -1629
  428. package/dist/chrome-DScZx4Lk.js +0 -1601
  429. package/dist/chunk-mxPVo000.js +0 -348
  430. package/dist/clack-prompter-B0kl7shw.js +0 -92
  431. package/dist/clack-prompter-B1YxZdRy.js +0 -92
  432. package/dist/cli-CfHUkOD0.js +0 -101
  433. package/dist/cli-ClMrIh6l.js +0 -99
  434. package/dist/cli-session-BkPTd9Pk.js +0 -5463
  435. package/dist/cli-session-Dd8DKb5a.js +0 -5408
  436. package/dist/client-C1avc0vD.js +0 -1692
  437. package/dist/client-CC94YZrT.js +0 -1692
  438. package/dist/clipboard-B2fBy8tG.js +0 -31
  439. package/dist/clipboard-BbGnZskJ.js +0 -31
  440. package/dist/command-format-Clp46jkj.js +0 -38
  441. package/dist/command-format-DELazozB.js +0 -52
  442. package/dist/command-format-SkzzRqR1.js +0 -52
  443. package/dist/command-registry-DZ4hkmA0.js +0 -248
  444. package/dist/commands-DtYZJSPn.js +0 -568
  445. package/dist/commands-Dujk1JmY.js +0 -568
  446. package/dist/commands-registry-Bd0xbvwG.js +0 -766
  447. package/dist/commands-registry-DYfRSVF3.js +0 -766
  448. package/dist/common-D6bu0zHC.js +0 -287
  449. package/dist/common-zW9Y2P1B.js +0 -287
  450. package/dist/completion-cli-tSe7Pmqm.js +0 -431
  451. package/dist/completion-cli-vn4IScs5.js +0 -432
  452. package/dist/config-C8rUDJXY.js +0 -5704
  453. package/dist/config-CLZ_XGVw.js +0 -6523
  454. package/dist/config-SY8M0kM_.js +0 -5705
  455. package/dist/config-cli-1V7D2Wsw.js +0 -247
  456. package/dist/config-cli-CjWEC81L.js +0 -244
  457. package/dist/config-guard-BW2gpKj_.js +0 -93
  458. package/dist/config-guard-BvxuzHpo.js +0 -76
  459. package/dist/config-sync-CoIIbEOe.js +0 -91
  460. package/dist/config-sync-DvAttep0.js +0 -91
  461. package/dist/configure-Bf0oupCE.js +0 -959
  462. package/dist/configure-DRM-7zFf.js +0 -960
  463. package/dist/context-D5iEFzv9.js +0 -60
  464. package/dist/control-service-C8m8F9pr.js +0 -72
  465. package/dist/control-service-DKotCWCg.js +0 -72
  466. package/dist/cron-cli-DB_FLYHD.js +0 -448
  467. package/dist/cron-cli-bxm5lrrO.js +0 -451
  468. package/dist/daemon-cli-1LsOnICv.js +0 -566
  469. package/dist/daemon-cli-CC2NrJ7a.js +0 -565
  470. package/dist/daemon-runtime-BXZhtBL9.js +0 -460
  471. package/dist/daemon-runtime-DW4USC7r.js +0 -460
  472. package/dist/deliver-B4HuPwJA.js +0 -1162
  473. package/dist/deliver-LiY5oL52.js +0 -1097
  474. package/dist/deliver-xrmk7xjh.js +0 -1097
  475. package/dist/delivery-queue-TnQykYsg.js +0 -220
  476. package/dist/deps-CMMOiOsF.js +0 -42
  477. package/dist/devices-cli-Be5he2SA.js +0 -195
  478. package/dist/devices-cli-z6ecoFe9.js +0 -198
  479. package/dist/diagnostics-Dj75aEHN.js +0 -35
  480. package/dist/diagnostics-DlIw6fqD.js +0 -35
  481. package/dist/directory-cli-CEy-0nxj.js +0 -243
  482. package/dist/directory-cli-DpzKcigr.js +0 -246
  483. package/dist/dispatcher-10Shiuz3.js +0 -100
  484. package/dist/dispatcher-3Jae6AiW.js +0 -100
  485. package/dist/dns-cli-Bat1pkc-.js +0 -200
  486. package/dist/dns-cli-NohNyEo0.js +0 -197
  487. package/dist/dock-DbxBBv30.js +0 -753
  488. package/dist/dock-cPBY4qGl.js +0 -753
  489. package/dist/docs-cli-BWp6p-Tq.js +0 -161
  490. package/dist/docs-cli-x22FnZfL.js +0 -159
  491. package/dist/doctor-BrT5m_on.js +0 -1815
  492. package/dist/doctor-Pp2HVnjM.js +0 -1813
  493. package/dist/doctor-completion-DNTimX9o.js +0 -92
  494. package/dist/doctor-completion-ylN9QAJ6.js +0 -92
  495. package/dist/doctor-config-flow-D1w3700T.js +0 -1232
  496. package/dist/doctor-config-flow-Dq50iE1R.js +0 -1232
  497. package/dist/engine-B9avUJL5.js +0 -563
  498. package/dist/engine-BiUQ25D4.js +0 -563
  499. package/dist/env-0lJfCPsw.js +0 -32
  500. package/dist/exec-BenD3A5l.js +0 -1167
  501. package/dist/exec-Bv3pyjeM.js +0 -255
  502. package/dist/exec-approvals-CdLmKX2R.js +0 -1221
  503. package/dist/exec-approvals-cli-DXfV6G8H.js +0 -368
  504. package/dist/exec-approvals-cli-J2cZs10o.js +0 -371
  505. package/dist/frontmatter-YijVi0FQ.js +0 -204
  506. package/dist/gateway-cli-DOAbA0pc.js +0 -19972
  507. package/dist/gateway-cli-QpWtBhQy.js +0 -19971
  508. package/dist/gateway-rpc-DJKBil9s.js +0 -28
  509. package/dist/gateway-rpc-DVterpLP.js +0 -28
  510. package/dist/github-copilot-auth-4IUFp669.js +0 -1418
  511. package/dist/github-copilot-auth-C9E0IROs.js +0 -1418
  512. package/dist/gmail-setup-utils-BPo_LkKI.js +0 -428
  513. package/dist/gmail-setup-utils-D3Yqgor7.js +0 -428
  514. package/dist/health-BeZnqp6m.js +0 -1258
  515. package/dist/health-Cn2OoVWZ.js +0 -1253
  516. package/dist/health-format-CdP99j3Y.js +0 -208
  517. package/dist/health-format-JEChH08S.js +0 -208
  518. package/dist/heartbeat-visibility-BL3WAchI.js +0 -98
  519. package/dist/heartbeat-visibility-CQ9QimI7.js +0 -98
  520. package/dist/help-format-Dl4bsrLI.js +0 -17
  521. package/dist/helpers-ZKNRexvX.js +0 -10
  522. package/dist/hooks-cli-D99hXt7K.js +0 -991
  523. package/dist/hooks-cli-DMB8RiEO.js +0 -993
  524. package/dist/hooks-status-B-e96dZj.js +0 -356
  525. package/dist/hooks-status-C_9sE0ox.js +0 -356
  526. package/dist/image-ops-Dlt3T7th.js +0 -541
  527. package/dist/image-ops-omlvdfah.js +0 -541
  528. package/dist/init-Bm04RagW.js +0 -122
  529. package/dist/init-CaJBf4p1.js +0 -122
  530. package/dist/installs-C2iMRBVz.js +0 -383
  531. package/dist/installs-D-cPGdCw.js +0 -383
  532. package/dist/ipv4-Bf7NS3QU.js +0 -1964
  533. package/dist/ipv4-wWNs8IH_.js +0 -1964
  534. package/dist/lanes-CNxj3tit.js +0 -232
  535. package/dist/lifecycle-core-B_7XRcvF.js +0 -388
  536. package/dist/lifecycle-core-By83PVAK.js +0 -387
  537. package/dist/links-BfjHVTB_.js +0 -15
  538. package/dist/links-DPGe0OHw.js +0 -15
  539. package/dist/logging-DB6BQmhi.js +0 -15
  540. package/dist/logging-mcb66J0p.js +0 -15
  541. package/dist/login-BDCg6D0N.js +0 -61
  542. package/dist/login-BDfnbjnZ.js +0 -59
  543. package/dist/login-BqH1itcg.js +0 -61
  544. package/dist/login-qr-CyOw3R4r.js +0 -321
  545. package/dist/login-qr-D8ECtb72.js +0 -323
  546. package/dist/login-qr-RnR7e4Bw.js +0 -326
  547. package/dist/logs-cli--j89L74J.js +0 -245
  548. package/dist/logs-cli-DpEMg_Gq.js +0 -242
  549. package/dist/manager-B4OyvcxT.js +0 -3244
  550. package/dist/manager-Cqc1CeH7.js +0 -3246
  551. package/dist/manager-DUyQPFvj.js +0 -3244
  552. package/dist/manifest-registry-CW1zCyRF.js +0 -748
  553. package/dist/manifest-registry-D4lM2RdV.js +0 -748
  554. package/dist/markdown-tables-BT1X6jqH.js +0 -347
  555. package/dist/markdown-tables-DHgOK2vI.js +0 -348
  556. package/dist/media-THyainiE.js +0 -1342
  557. package/dist/memory-cli-BKocCWXM.js +0 -868
  558. package/dist/memory-cli-Jmma-xI_.js +0 -869
  559. package/dist/message-channel-dSTVVCyX.js +0 -110
  560. package/dist/migrate-BR6iAIjO.js +0 -157
  561. package/dist/migrate-D0EcMs0f.js +0 -157
  562. package/dist/model-selection-YcSr9CgC.js +0 -2691
  563. package/dist/models-1vUQBVfw.js +0 -2510
  564. package/dist/models-cli-BK3BwUhL.js +0 -2739
  565. package/dist/models-cli-DECrM8oA.js +0 -258
  566. package/dist/net-B5lXhYLV.js +0 -218
  567. package/dist/node-cli-cLHUNpPD.js +0 -1319
  568. package/dist/node-cli-fO7Y132S.js +0 -1322
  569. package/dist/node-service-BFxHJsno.js +0 -67
  570. package/dist/node-service-DUnan4uK.js +0 -67
  571. package/dist/nodes-cli-BCq35E6N.js +0 -1200
  572. package/dist/nodes-cli-vD7MwAKP.js +0 -1197
  573. package/dist/nodes-screen-1YiLkqr5.js +0 -234
  574. package/dist/nodes-screen-DZeD8hE5.js +0 -234
  575. package/dist/note-Bi8Wb8DV.js +0 -73
  576. package/dist/note-uiuPxhyX.js +0 -73
  577. package/dist/npm-registry-spec-B-XIShkB.js +0 -351
  578. package/dist/npm-registry-spec-za3itb5Y.js +0 -351
  579. package/dist/onboard-Ds6w_sWo.js +0 -1165
  580. package/dist/onboard-SAVx3bp4.js +0 -1166
  581. package/dist/onboard-channels-Cg_EkBa4.js +0 -672
  582. package/dist/onboard-channels-D7NbA55V.js +0 -672
  583. package/dist/onboard-helpers-DO_hgZb9.js +0 -365
  584. package/dist/onboard-helpers-_XgJgeqh.js +0 -365
  585. package/dist/onboarding-3hLmDd0r.js +0 -911
  586. package/dist/onboarding-B4LKLsbU.js +0 -910
  587. package/dist/orchestrator-BKzmyBWy.js +0 -357
  588. package/dist/orchestrator-BN3QCz2s.js +0 -357
  589. package/dist/outbound-BgA9hNlP.js +0 -2062
  590. package/dist/outbound-CjdvVhUI.js +0 -214
  591. package/dist/outbound-DOGe6qb2.js +0 -214
  592. package/dist/outbound-send-deps-Du5aBpd7.js +0 -55
  593. package/dist/pairing-cli-2vnyg_Nd.js +0 -118
  594. package/dist/pairing-cli-BH1KQtNV.js +0 -121
  595. package/dist/pairing-store-DJz_9Gv0.js +0 -388
  596. package/dist/pairing-store-DmOzxcuk.js +0 -388
  597. package/dist/path-env-Bu6k0jDQ.js +0 -89
  598. package/dist/path-env-C0zQSjw8.js +0 -89
  599. package/dist/paths-BTc4nk-6.js +0 -126
  600. package/dist/paths-BgUi2Z2G.js +0 -54
  601. package/dist/paths-C6VCWKo3.js +0 -238
  602. package/dist/paths-CCxa0o9c.js +0 -222
  603. package/dist/paths-CxRf2rBG.js +0 -129
  604. package/dist/paths-hcX1Gqg5.js +0 -129
  605. package/dist/pi-auth-json-B68R7q7_.js +0 -82
  606. package/dist/pi-auth-json-CR0jXAgq.js +0 -78
  607. package/dist/pi-auth-json-ZYzi3nxs.js +0 -80
  608. package/dist/pi-model-discovery-Cxs4pvC2.js +0 -3
  609. package/dist/pi-tools.policy-D81U5xy0.js +0 -200
  610. package/dist/pi-tools.policy-DSHkkb5b.js +0 -200
  611. package/dist/plugin-auto-enable-CxF4bpDN.js +0 -282
  612. package/dist/plugin-auto-enable-jNaAeyEh.js +0 -282
  613. package/dist/plugin-registry-C7XWotZG.js +0 -32
  614. package/dist/plugin-registry-DcUCbGax.js +0 -32
  615. package/dist/plugins-B362e77G.js +0 -168
  616. package/dist/plugins-CmSUIUNi.js +0 -38
  617. package/dist/plugins-cli-BsCEnoQ7.js +0 -734
  618. package/dist/plugins-cli-QSIsMUG7.js +0 -736
  619. package/dist/polls-CItfB1H8.js +0 -1343
  620. package/dist/ports-BVLMN1Sr.js +0 -96
  621. package/dist/ports-CqLSlU6Z.js +0 -317
  622. package/dist/ports-D94CwCrv.js +0 -344
  623. package/dist/ports-D_NHthOz.js +0 -96
  624. package/dist/program-DkJHjI0R.js +0 -176
  625. package/dist/program-context-DnyGM2SC.js +0 -496
  626. package/dist/progress-Bek_GyWS.js +0 -133
  627. package/dist/prompt-style-lu0clOOE.js +0 -9
  628. package/dist/pw-ai-BLVMuSLv.js +0 -1867
  629. package/dist/pw-ai-DZJWEF_f.js +0 -1865
  630. package/dist/pw-ai-dzf-ptcn.js +0 -1868
  631. package/dist/qmd-manager-Cur_Ekn0.js +0 -937
  632. package/dist/qmd-manager-DNAUuwjK.js +0 -938
  633. package/dist/qmd-manager-DepEoASu.js +0 -935
  634. package/dist/register.agent-CSWvzOkR.js +0 -265
  635. package/dist/register.agent-UeH2NXmH.js +0 -1003
  636. package/dist/register.anima-DOdee0dh.js +0 -193
  637. package/dist/register.anima-HHDWsz6r.js +0 -193
  638. package/dist/register.configure-CSJFxdz9.js +0 -103
  639. package/dist/register.configure-D84Fvcz4.js +0 -101
  640. package/dist/register.maintenance-B3pvNbZb.js +0 -543
  641. package/dist/register.maintenance-BKVOwkw6.js +0 -543
  642. package/dist/register.message-BAO6CPl2.js +0 -657
  643. package/dist/register.message-OXoOKE_6.js +0 -660
  644. package/dist/register.onboard-BK_ixVmD.js +0 -170
  645. package/dist/register.onboard-cfCaPx6j.js +0 -170
  646. package/dist/register.setup-BGfDnzph.js +0 -175
  647. package/dist/register.setup-Y-Q74M-0.js +0 -175
  648. package/dist/register.status-health-sessions-CT14eitH.js +0 -142
  649. package/dist/register.status-health-sessions-TfZMzAUn.js +0 -313
  650. package/dist/register.subclis-BZwdlNHC.js +0 -255
  651. package/dist/reply-mlsExaZm.js +0 -32212
  652. package/dist/reply-prefix-B0CfR4bM.js +0 -100
  653. package/dist/reply-prefix-w4a39ybC.js +0 -100
  654. package/dist/reply-qalRISe_.js +0 -32212
  655. package/dist/routes-CENsHJyg.js +0 -1820
  656. package/dist/routes-DO0HqW2e.js +0 -1820
  657. package/dist/rpc-C0pjNhBi.js +0 -70
  658. package/dist/rpc-DZ44PIXE.js +0 -70
  659. package/dist/run-main-BMpKw8Mp.js +0 -371
  660. package/dist/runtime-guard-BSUFiAQV.js +0 -60
  661. package/dist/sandbox-BIGfMYEI.js +0 -858
  662. package/dist/sandbox-DxP3IpUP.js +0 -859
  663. package/dist/sandbox-cli-DtLGH8sL.js +0 -461
  664. package/dist/sandbox-cli-_Tg7lfJ_.js +0 -458
  665. package/dist/security-cli-BRwgbedo.js +0 -462
  666. package/dist/security-cli-D3bSuyZt.js +0 -465
  667. package/dist/server-context-49XFFxFg.js +0 -824
  668. package/dist/server-context-LrlgrZzS.js +0 -824
  669. package/dist/server-node-events-Dm52i7NW.js +0 -231
  670. package/dist/server-node-events-QX523UyF.js +0 -233
  671. package/dist/service-BNVpYcQe.js +0 -642
  672. package/dist/service-D56aMXUB.js +0 -642
  673. package/dist/service-audit-D0X_XAB2.js +0 -488
  674. package/dist/service-audit-qmf6XMmP.js +0 -488
  675. package/dist/session-CrQQLLhx.js +0 -179
  676. package/dist/session-LocsOOWJ.js +0 -181
  677. package/dist/session-Vlce2BAT.js +0 -181
  678. package/dist/session-cost-usage-BwiTZuKl.js +0 -600
  679. package/dist/session-cost-usage-DT9YNXTJ.js +0 -600
  680. package/dist/sessions-BfV53TbG.js +0 -1296
  681. package/dist/sessions-BimpX_km.js +0 -180
  682. package/dist/sessions-DcXpzig0.js +0 -1296
  683. package/dist/sessions-Wd18dukK.js +0 -2038
  684. package/dist/shared-Bsr69u_7.js +0 -77
  685. package/dist/shared-Cgly1vPb.js +0 -66
  686. package/dist/shared-JOo05hST.js +0 -66
  687. package/dist/shared-f7dvQsi7.js +0 -77
  688. package/dist/skill-scanner-CkaVLABv.js +0 -263
  689. package/dist/skills-B-G7UHOa.js +0 -808
  690. package/dist/skills-B5LQx4lT.js +0 -807
  691. package/dist/skills-cli-DUGe2ZWW.js +0 -286
  692. package/dist/skills-cli-DtOk0bvK.js +0 -289
  693. package/dist/skills-status-Clq9ZnYu.js +0 -166
  694. package/dist/skills-status-JQluhU-P.js +0 -166
  695. package/dist/sqlite-BukcjdJa.js +0 -321
  696. package/dist/sqlite-CGcOZZ0C.js +0 -368
  697. package/dist/sqlite-Ck6f9KWc.js +0 -453
  698. package/dist/start--xmSFepB.js +0 -372
  699. package/dist/start-BdlZbqrr.js +0 -371
  700. package/dist/status-BgoeFm6g.js +0 -2137
  701. package/dist/status-BjjDrUq7.js +0 -27
  702. package/dist/status-Ct0DgOZ-.js +0 -2132
  703. package/dist/status-RA_uNmK0.js +0 -27
  704. package/dist/status.update-BjOH3GlS.js +0 -79
  705. package/dist/status.update-DLU1qBf0.js +0 -79
  706. package/dist/subagent-registry-9RLdKxES.js +0 -2760
  707. package/dist/subagent-registry-Byuex3zp.js +0 -2759
  708. package/dist/subagent-registry-DOBunBYS.js +0 -14
  709. package/dist/subsystem-Dowf8fSU.js +0 -860
  710. package/dist/system-cli-C5oBpzni.js +0 -79
  711. package/dist/system-cli-DXNKD_Id.js +0 -82
  712. package/dist/systemd-BSrHDyeU.js +0 -452
  713. package/dist/systemd-By5xdSB4.js +0 -452
  714. package/dist/systemd-hints-BtjL_5Rh.js +0 -36
  715. package/dist/systemd-hints-sJmr6cjb.js +0 -36
  716. package/dist/systemd-linger-CTmV2Gci.js +0 -75
  717. package/dist/systemd-linger-CmyqQkeC.js +0 -75
  718. package/dist/table-BL0lJzsm.js +0 -279
  719. package/dist/table-DoiRPsn0.js +0 -279
  720. package/dist/timeout-CswI_K-U.js +0 -232
  721. package/dist/tokens-C-X7wDKj.js +0 -14
  722. package/dist/tokens-DkvqA72p.js +0 -14
  723. package/dist/trash-BJLK1vMn.js +0 -23
  724. package/dist/trash-_x5UZ94k.js +0 -23
  725. package/dist/tui-BHjxDFZC.js +0 -3894
  726. package/dist/tui-CgOocwN8.js +0 -3894
  727. package/dist/tui-cli-5ANH8dE5.js +0 -47
  728. package/dist/tui-cli-BQ4P-JW_.js +0 -50
  729. package/dist/update-LFgxHHPd.js +0 -317
  730. package/dist/update-TxptCqk7.js +0 -317
  731. package/dist/update-check-CWc7YXmc.js +0 -400
  732. package/dist/update-check-IhlWaui6.js +0 -400
  733. package/dist/update-cli-PtXU62w7.js +0 -1105
  734. package/dist/update-cli-Va0EtETG.js +0 -1105
  735. package/dist/update-runner-BLeKFkiB.js +0 -894
  736. package/dist/update-runner-Iuzpc-_y.js +0 -894
  737. package/dist/usage-ApGvBLVg.js +0 -4516
  738. package/dist/utils-Bsw__U-F.js +0 -243
  739. package/dist/web-B6_Ky60G.js +0 -63
  740. package/dist/web-EZLQEWXY.js +0 -46842
  741. package/dist/web-pec8YJUX.js +0 -2203
  742. package/dist/webhooks-cli-BYQKTHTp.js +0 -319
  743. package/dist/webhooks-cli-C2_xtsUQ.js +0 -316
  744. package/dist/whatsapp-actions-C72VCq8f.js +0 -49
  745. package/dist/whatsapp-actions-Ck9Uv0Nw.js +0 -45
  746. package/dist/whatsapp-actions-D0reTj2k.js +0 -53
  747. package/dist/widearea-dns-B6ocX23x.js +0 -127
  748. package/dist/widearea-dns-NsEUNYwz.js +0 -127
  749. package/dist/workspace-Dcfoy5JJ.js +0 -649
  750. package/dist/ws-log-N8R5MvGE.js +0 -267
  751. package/dist/ws-log-gwFxPxj5.js +0 -267
  752. /package/dist/{auto-update-CUeF99gI.js → auto-update-CpF0fycd.js} +0 -0
  753. /package/dist/{auto-update-cgkp9ZTJ.js → auto-update-DNWdO7uF.js} +0 -0
  754. /package/dist/{brew-CVZkr0GU.js → brew-nqf_MiE4.js} +0 -0
  755. /package/dist/{budget-DxYQSekw.js → budget-CPedI-qW.js} +0 -0
  756. /package/dist/{budget-BWBp8Res.js → budget-CRpvqDRX.js} +0 -0
  757. /package/dist/{cli-utils-DtAxdCte.js → cli-utils-C1YHVD4o.js} +0 -0
  758. /package/dist/{command-options-CSbuuqHr.js → command-options-BbponVnw.js} +0 -0
  759. /package/dist/{command-options-Cp1tf96a.js → command-options-s0gnvXnS.js} +0 -0
  760. /package/dist/{constants-O8yBqCBv.js → constants-Dhb6zSIV.js} +0 -0
  761. /package/dist/{dangerous-tools-5ObDWy1N.js → dangerous-tools-DGTtJ_JR.js} +0 -0
  762. /package/dist/{dangerous-tools-Jwr7jqNw.js → dangerous-tools-DxrfTOfT.js} +0 -0
  763. /package/dist/{delivery-queue-B6IHz4Ry.js → delivery-queue-Bxm0nzw7.js} +0 -0
  764. /package/dist/{display-BDOsXu8F.js → display-Jy3UdGzA.js} +0 -0
  765. /package/dist/{errors-CHow2wtt.js → errors-CKaCqKga.js} +0 -0
  766. /package/dist/{exec-BizYYQgP.js → exec-DDmuVVNq.js} +0 -0
  767. /package/dist/{format-Mq6iU0_5.js → format-ByEjgyTF.js} +0 -0
  768. /package/dist/{format-duration-DhWzz_5b.js → format-duration-Aaj5tjJd.js} +0 -0
  769. /package/dist/{format-relative-C6kUHuOj.js → format-relative-79_Y1n2Y.js} +0 -0
  770. /package/dist/{help-format-DUBI91Ti.js → help-format-BMKzarov.js} +0 -0
  771. /package/dist/{helpers-eJFa4K6r.js → helpers-DpEB9Mh0.js} +0 -0
  772. /package/dist/{helpers-DLgbkcEn.js → helpers-FMld9sBT.js} +0 -0
  773. /package/dist/{input-provenance-DJBdpeKk.js → input-provenance-Cy_KnBlP.js} +0 -0
  774. /package/dist/{is-main-Dt9DTcH1.js → is-main-yjaVwMtJ.js} +0 -0
  775. /package/dist/{loader-l2OBdJ8x.js → loader-Br7Vr0zn.js} +0 -0
  776. /package/dist/{loader-BoYxRfcW.js → loader-CkmOrXcC.js} +0 -0
  777. /package/dist/{logging-BdnOSVPD.js → logging-CY-Q5cwf.js} +0 -0
  778. /package/dist/{message-channel-w4F2b2F6.js → message-channel-dua8OOGJ.js} +0 -0
  779. /package/dist/{mime-B1ZoR53M.js → mime-CBg4KybI.js} +0 -0
  780. /package/dist/{model-param-b-DPwyNGn8.js → model-param-b-DW9f0NN8.js} +0 -0
  781. /package/dist/{node-match-8XZnaid6.js → node-match-BV8bTBd4.js} +0 -0
  782. /package/dist/{normalize-GDK8JTNW.js → normalize-_lmlBOW9.js} +0 -0
  783. /package/dist/{openclaw-root-C85WMnVV.js → openclaw-root-JPvmPTf7.js} +0 -0
  784. /package/dist/{outbound-send-deps-ANnAhImn.js → outbound-send-deps-BfUvuWGa.js} +0 -0
  785. /package/dist/{parse-6-2MDhdT.js → parse-CZRwKocn.js} +0 -0
  786. /package/dist/{parse-log-line-Bqh1SSzC.js → parse-log-line-CvrZEK6A.js} +0 -0
  787. /package/dist/{parse-log-line-DUZCjXbl.js → parse-log-line-mLdat0AH.js} +0 -0
  788. /package/dist/{parse-port-BKB9Exlg.js → parse-port-BSOOdo7I.js} +0 -0
  789. /package/dist/{parse-port-DrfvwwiL.js → parse-port-Y0NK62x1.js} +0 -0
  790. /package/dist/{parse-timeout-Di_tcEmi.js → parse-timeout-DVPQ3n9j.js} +0 -0
  791. /package/dist/{paths-DcVEkYX5.js → paths-DHjlJ6cn.js} +0 -0
  792. /package/dist/{pi-model-discovery-DsRqYJLy.js → pi-model-discovery-DzEIEgHL.js} +0 -0
  793. /package/dist/{plugins-CDJw924T.js → plugins-D6PBOdkn.js} +0 -0
  794. /package/dist/{program-context-Bvn8046-.js → program-context-Q1hkT73c.js} +0 -0
  795. /package/dist/{progress-CbZ2D53A.js → progress-C9Ha1NJh.js} +0 -0
  796. /package/dist/{prompt-style-DKy6qQxR.js → prompt-style-DQi8j03a.js} +0 -0
  797. /package/dist/{prompts-BI__va99.js → prompts-BEHxUC3w.js} +0 -0
  798. /package/dist/{prompts-_dDWkCAz.js → prompts-CSOhuiqe.js} +0 -0
  799. /package/dist/{queue-D_u34pbL.js → queue-BJGo7kAB.js} +0 -0
  800. /package/dist/{queue-PG591iID.js → queue-DYgUbdoq.js} +0 -0
  801. /package/dist/{redact-ClVwO7Nn.js → redact-CyKvdFrg.js} +0 -0
  802. /package/dist/{registry-Bs_DJK9E.js → registry-C5MAYD4V.js} +0 -0
  803. /package/dist/{registry-D_zlP1U-.js → registry-CRrXXVs0.js} +0 -0
  804. /package/dist/{requirements-BzZxj2Wu.js → requirements-CGkxTCu4.js} +0 -0
  805. /package/dist/{requirements-DIW1svgA.js → requirements-CIDaOcbO.js} +0 -0
  806. /package/dist/{runtime-guard-DeOXA_86.js → runtime-guard-nL3Lp8T-.js} +0 -0
  807. /package/dist/{secret-equal-Dghy3xsA.js → secret-equal-DJpmLXlG.js} +0 -0
  808. /package/dist/{send-BhAfdGII.js → send-CTcxgDDU.js} +0 -0
  809. /package/dist/{send-ga9udK1_.js → send-DPezUR3-.js} +0 -0
  810. /package/dist/{send-C2t9xpXI.js → send-DZQTaG7-.js} +0 -0
  811. /package/dist/{send-DigO-i9j.js → send-VDff2gra.js} +0 -0
  812. /package/dist/{send-Dz2BDHll.js → send-bgQNV8d1.js} +0 -0
  813. /package/dist/{session-key-BGiG_JcT.js → session-key-CQT-NR6w.js} +0 -0
  814. /package/dist/{shell-argv-CAq1mLa2.js → shell-argv-n9IueeJQ.js} +0 -0
  815. /package/dist/{skill-scanner-Coo4QoCd.js → skill-scanner-o6NgVMD9.js} +0 -0
  816. /package/dist/{status-CMnlcBVc.js → status-C53kTIXF.js} +0 -0
  817. /package/dist/{status-tDZPwewW.js → status-CZDDA_Sy.js} +0 -0
  818. /package/dist/{system-run-command-X9lDJIy0.js → system-run-command-BCjUffN9.js} +0 -0
  819. /package/dist/{system-run-command-DGk7dwQP.js → system-run-command-CqAqKL9K.js} +0 -0
  820. /package/dist/{tailnet-CuiNECdL.js → tailnet-Ciwjv243.js} +0 -0
  821. /package/dist/{templates-CeYJjVzw.js → templates-37RKpACb.js} +0 -0
  822. /package/dist/{templates-I3Z0xplD.js → templates-DPalk30o.js} +0 -0
  823. /package/dist/{thinking-BXEswx1X.js → thinking-2hxwmvTl.js} +0 -0
  824. /package/dist/{transcript-events-C1hdue6u.js → transcript-events-Bp7fGnwv.js} +0 -0
  825. /package/dist/{transcript-tools-DuyYOkUq.js → transcript-tools-D4Lbxlka.js} +0 -0
  826. /package/dist/{usage-format-BAirWUSO.js → usage-format-6Uar63S0.js} +0 -0
  827. /package/dist/{utils-C9sj30YY.js → utils-DT8uXjFS.js} +0 -0
  828. /package/dist/{wsl-CqyuRvtM.js → wsl-CrPvx2kZ.js} +0 -0
  829. /package/dist/{wsl-ymJYvc9Q.js → wsl-UvJ5dHah.js} +0 -0
@@ -0,0 +1,2689 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-Cbj13DAv.js";
2
+ import { $ as resolveStateDir, Q as resolveOAuthPath, n as isTruthyEnvValue, o as createSubsystemLogger } from "./entry.js";
3
+ import { t as formatCliCommand } from "./command-format-G6N2zghg.js";
4
+ import { n as DEFAULT_AGENT_ID } from "./session-key-CQT-NR6w.js";
5
+ import { y as resolveUserPath } from "./utils-DT8uXjFS.js";
6
+ import { a as resolveAgentModelPrimary } from "./agent-scope-DZgptr9J.js";
7
+ import { execFileSync, execSync } from "node:child_process";
8
+ import path from "node:path";
9
+ import fs from "node:fs";
10
+ import fs$1 from "node:fs/promises";
11
+ import { getEnvApiKey, getOAuthApiKey, getOAuthProviders } from "@mariozechner/pi-ai";
12
+ import { createHash, randomBytes, randomUUID } from "node:crypto";
13
+
14
+ //#region src/agents/auth-profiles/constants.ts
15
+ const AUTH_STORE_VERSION = 1;
16
+ const AUTH_PROFILE_FILENAME = "auth-profiles.json";
17
+ const LEGACY_AUTH_FILENAME = "auth.json";
18
+ const CLAUDE_CLI_PROFILE_ID = "anthropic:claude-cli";
19
+ const CODEX_CLI_PROFILE_ID = "openai-codex:codex-cli";
20
+ const QWEN_CLI_PROFILE_ID = "qwen-portal:qwen-cli";
21
+ const MINIMAX_CLI_PROFILE_ID = "minimax-portal:minimax-cli";
22
+ const AUTH_STORE_LOCK_OPTIONS = {
23
+ retries: {
24
+ retries: 10,
25
+ factor: 2,
26
+ minTimeout: 100,
27
+ maxTimeout: 1e4,
28
+ randomize: true
29
+ },
30
+ stale: 3e4
31
+ };
32
+ const EXTERNAL_CLI_SYNC_TTL_MS = 900 * 1e3;
33
+ const EXTERNAL_CLI_NEAR_EXPIRY_MS = 600 * 1e3;
34
+ const log$1 = createSubsystemLogger("agents/auth-profiles");
35
+
36
+ //#endregion
37
+ //#region src/agents/auth-profiles/display.ts
38
+ function resolveAuthProfileDisplayLabel(params) {
39
+ const { cfg, store, profileId } = params;
40
+ const profile = store.profiles[profileId];
41
+ const email = cfg?.auth?.profiles?.[profileId]?.email?.trim() || (profile && "email" in profile ? profile.email?.trim() : void 0);
42
+ if (email) return `${profileId} (${email})`;
43
+ return profileId;
44
+ }
45
+
46
+ //#endregion
47
+ //#region src/agents/defaults.ts
48
+ const DEFAULT_PROVIDER = "anthropic";
49
+ const DEFAULT_MODEL = "claude-opus-4-6";
50
+ const DEFAULT_CONTEXT_TOKENS = 2e5;
51
+
52
+ //#endregion
53
+ //#region src/agents/cloudflare-ai-gateway.ts
54
+ const CLOUDFLARE_AI_GATEWAY_PROVIDER_ID = "cloudflare-ai-gateway";
55
+ const CLOUDFLARE_AI_GATEWAY_DEFAULT_MODEL_ID = "claude-sonnet-4-5";
56
+ const CLOUDFLARE_AI_GATEWAY_DEFAULT_MODEL_REF = `${CLOUDFLARE_AI_GATEWAY_PROVIDER_ID}/${CLOUDFLARE_AI_GATEWAY_DEFAULT_MODEL_ID}`;
57
+ const CLOUDFLARE_AI_GATEWAY_DEFAULT_CONTEXT_WINDOW = 2e5;
58
+ const CLOUDFLARE_AI_GATEWAY_DEFAULT_MAX_TOKENS = 64e3;
59
+ const CLOUDFLARE_AI_GATEWAY_DEFAULT_COST = {
60
+ input: 3,
61
+ output: 15,
62
+ cacheRead: .3,
63
+ cacheWrite: 3.75
64
+ };
65
+ function buildCloudflareAiGatewayModelDefinition(params) {
66
+ return {
67
+ id: params?.id?.trim() || CLOUDFLARE_AI_GATEWAY_DEFAULT_MODEL_ID,
68
+ name: params?.name ?? "Claude Sonnet 4.5",
69
+ reasoning: params?.reasoning ?? true,
70
+ input: params?.input ?? ["text", "image"],
71
+ cost: CLOUDFLARE_AI_GATEWAY_DEFAULT_COST,
72
+ contextWindow: CLOUDFLARE_AI_GATEWAY_DEFAULT_CONTEXT_WINDOW,
73
+ maxTokens: CLOUDFLARE_AI_GATEWAY_DEFAULT_MAX_TOKENS
74
+ };
75
+ }
76
+ function resolveCloudflareAiGatewayBaseUrl(params) {
77
+ const accountId = params.accountId.trim();
78
+ const gatewayId = params.gatewayId.trim();
79
+ if (!accountId || !gatewayId) return "";
80
+ return `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/anthropic`;
81
+ }
82
+
83
+ //#endregion
84
+ //#region src/agents/huggingface-models.ts
85
+ /** Hugging Face Inference Providers (router) — OpenAI-compatible chat completions. */
86
+ const HUGGINGFACE_BASE_URL = "https://router.huggingface.co/v1";
87
+ /** Router policy suffixes: router picks backend by cost or speed; no specific provider selection. */
88
+ const HUGGINGFACE_POLICY_SUFFIXES = ["cheapest", "fastest"];
89
+ /**
90
+ * True when the model ref uses :cheapest or :fastest. When true, provider choice is locked
91
+ * (router decides); do not show an interactive "prefer specific backend" option.
92
+ */
93
+ function isHuggingfacePolicyLocked(modelRef) {
94
+ const ref = String(modelRef).trim();
95
+ return HUGGINGFACE_POLICY_SUFFIXES.some((s) => ref.endsWith(`:${s}`) || ref === s);
96
+ }
97
+ /** Default cost when not in static catalog (HF pricing varies by provider). */
98
+ const HUGGINGFACE_DEFAULT_COST = {
99
+ input: 0,
100
+ output: 0,
101
+ cacheRead: 0,
102
+ cacheWrite: 0
103
+ };
104
+ /** Defaults for models discovered from GET /v1/models. */
105
+ const HUGGINGFACE_DEFAULT_CONTEXT_WINDOW = 131072;
106
+ const HUGGINGFACE_DEFAULT_MAX_TOKENS = 8192;
107
+ const HUGGINGFACE_MODEL_CATALOG = [
108
+ {
109
+ id: "deepseek-ai/DeepSeek-R1",
110
+ name: "DeepSeek R1",
111
+ reasoning: true,
112
+ input: ["text"],
113
+ contextWindow: 131072,
114
+ maxTokens: 8192,
115
+ cost: {
116
+ input: 3,
117
+ output: 7,
118
+ cacheRead: 3,
119
+ cacheWrite: 3
120
+ }
121
+ },
122
+ {
123
+ id: "deepseek-ai/DeepSeek-V3.1",
124
+ name: "DeepSeek V3.1",
125
+ reasoning: false,
126
+ input: ["text"],
127
+ contextWindow: 131072,
128
+ maxTokens: 8192,
129
+ cost: {
130
+ input: .6,
131
+ output: 1.25,
132
+ cacheRead: .6,
133
+ cacheWrite: .6
134
+ }
135
+ },
136
+ {
137
+ id: "meta-llama/Llama-3.3-70B-Instruct-Turbo",
138
+ name: "Llama 3.3 70B Instruct Turbo",
139
+ reasoning: false,
140
+ input: ["text"],
141
+ contextWindow: 131072,
142
+ maxTokens: 8192,
143
+ cost: {
144
+ input: .88,
145
+ output: .88,
146
+ cacheRead: .88,
147
+ cacheWrite: .88
148
+ }
149
+ },
150
+ {
151
+ id: "openai/gpt-oss-120b",
152
+ name: "GPT-OSS 120B",
153
+ reasoning: false,
154
+ input: ["text"],
155
+ contextWindow: 131072,
156
+ maxTokens: 8192,
157
+ cost: {
158
+ input: 0,
159
+ output: 0,
160
+ cacheRead: 0,
161
+ cacheWrite: 0
162
+ }
163
+ }
164
+ ];
165
+ function buildHuggingfaceModelDefinition(model) {
166
+ return {
167
+ id: model.id,
168
+ name: model.name,
169
+ reasoning: model.reasoning,
170
+ input: model.input,
171
+ cost: model.cost,
172
+ contextWindow: model.contextWindow,
173
+ maxTokens: model.maxTokens
174
+ };
175
+ }
176
+ /**
177
+ * Infer reasoning and display name from Hub-style model id (e.g. "deepseek-ai/DeepSeek-R1").
178
+ */
179
+ function inferredMetaFromModelId(id) {
180
+ const base = id.split("/").pop() ?? id;
181
+ const reasoning = /r1|reasoning|thinking|reason/i.test(id) || /-\d+[tb]?-thinking/i.test(base);
182
+ return {
183
+ name: base.replace(/-/g, " ").replace(/\b(\w)/g, (c) => c.toUpperCase()),
184
+ reasoning
185
+ };
186
+ }
187
+ /** Prefer API-supplied display name, then owned_by/id, then inferred from id. */
188
+ function displayNameFromApiEntry(entry, inferredName) {
189
+ const fromApi = typeof entry.name === "string" && entry.name.trim() || typeof entry.title === "string" && entry.title.trim() || typeof entry.display_name === "string" && entry.display_name.trim();
190
+ if (fromApi) return fromApi;
191
+ if (typeof entry.owned_by === "string" && entry.owned_by.trim()) {
192
+ const base = entry.id.split("/").pop() ?? entry.id;
193
+ return `${entry.owned_by.trim()}/${base}`;
194
+ }
195
+ return inferredName;
196
+ }
197
+ /**
198
+ * Discover chat-completion models from Hugging Face Inference Providers (GET /v1/models).
199
+ * Requires a valid HF token. Falls back to static catalog on failure or in test env.
200
+ */
201
+ async function discoverHuggingfaceModels(apiKey) {
202
+ if (process.env.VITEST === "true" || false) return HUGGINGFACE_MODEL_CATALOG.map(buildHuggingfaceModelDefinition);
203
+ const trimmedKey = apiKey?.trim();
204
+ if (!trimmedKey) return HUGGINGFACE_MODEL_CATALOG.map(buildHuggingfaceModelDefinition);
205
+ try {
206
+ const response = await fetch(`${HUGGINGFACE_BASE_URL}/models`, {
207
+ signal: AbortSignal.timeout(1e4),
208
+ headers: {
209
+ Authorization: `Bearer ${trimmedKey}`,
210
+ "Content-Type": "application/json"
211
+ }
212
+ });
213
+ if (!response.ok) {
214
+ console.warn(`[huggingface-models] GET /v1/models failed: HTTP ${response.status}, using static catalog`);
215
+ return HUGGINGFACE_MODEL_CATALOG.map(buildHuggingfaceModelDefinition);
216
+ }
217
+ const data = (await response.json())?.data;
218
+ if (!Array.isArray(data) || data.length === 0) {
219
+ console.warn("[huggingface-models] No models in response, using static catalog");
220
+ return HUGGINGFACE_MODEL_CATALOG.map(buildHuggingfaceModelDefinition);
221
+ }
222
+ const catalogById = new Map(HUGGINGFACE_MODEL_CATALOG.map((m) => [m.id, m]));
223
+ const seen = /* @__PURE__ */ new Set();
224
+ const models = [];
225
+ for (const entry of data) {
226
+ const id = typeof entry?.id === "string" ? entry.id.trim() : "";
227
+ if (!id || seen.has(id)) continue;
228
+ seen.add(id);
229
+ const catalogEntry = catalogById.get(id);
230
+ if (catalogEntry) models.push(buildHuggingfaceModelDefinition(catalogEntry));
231
+ else {
232
+ const inferred = inferredMetaFromModelId(id);
233
+ const name = displayNameFromApiEntry(entry, inferred.name);
234
+ const modalities = entry.architecture?.input_modalities;
235
+ const input = Array.isArray(modalities) && modalities.includes("image") ? ["text", "image"] : ["text"];
236
+ const contextLength = (Array.isArray(entry.providers) ? entry.providers : []).find((p) => typeof p?.context_length === "number" && p.context_length > 0)?.context_length ?? HUGGINGFACE_DEFAULT_CONTEXT_WINDOW;
237
+ models.push({
238
+ id,
239
+ name,
240
+ reasoning: inferred.reasoning,
241
+ input,
242
+ cost: HUGGINGFACE_DEFAULT_COST,
243
+ contextWindow: contextLength,
244
+ maxTokens: HUGGINGFACE_DEFAULT_MAX_TOKENS
245
+ });
246
+ }
247
+ }
248
+ return models.length > 0 ? models : HUGGINGFACE_MODEL_CATALOG.map(buildHuggingfaceModelDefinition);
249
+ } catch (error) {
250
+ console.warn(`[huggingface-models] Discovery failed: ${String(error)}, using static catalog`);
251
+ return HUGGINGFACE_MODEL_CATALOG.map(buildHuggingfaceModelDefinition);
252
+ }
253
+ }
254
+
255
+ //#endregion
256
+ //#region src/infra/shell-env.ts
257
+ const DEFAULT_TIMEOUT_MS = 15e3;
258
+ const DEFAULT_MAX_BUFFER_BYTES = 2 * 1024 * 1024;
259
+ let lastAppliedKeys = [];
260
+ let cachedShellPath;
261
+ function resolveShell(env) {
262
+ const shell = env.SHELL?.trim();
263
+ return shell && shell.length > 0 ? shell : "/bin/sh";
264
+ }
265
+ function parseShellEnv(stdout) {
266
+ const shellEnv = /* @__PURE__ */ new Map();
267
+ const parts = stdout.toString("utf8").split("\0");
268
+ for (const part of parts) {
269
+ if (!part) continue;
270
+ const eq = part.indexOf("=");
271
+ if (eq <= 0) continue;
272
+ const key = part.slice(0, eq);
273
+ const value = part.slice(eq + 1);
274
+ if (!key) continue;
275
+ shellEnv.set(key, value);
276
+ }
277
+ return shellEnv;
278
+ }
279
+ function loadShellEnvFallback(opts) {
280
+ const logger = opts.logger ?? console;
281
+ const exec = opts.exec ?? execFileSync;
282
+ if (!opts.enabled) {
283
+ lastAppliedKeys = [];
284
+ return {
285
+ ok: true,
286
+ applied: [],
287
+ skippedReason: "disabled"
288
+ };
289
+ }
290
+ if (opts.expectedKeys.some((key) => Boolean(opts.env[key]?.trim()))) {
291
+ lastAppliedKeys = [];
292
+ return {
293
+ ok: true,
294
+ applied: [],
295
+ skippedReason: "already-has-keys"
296
+ };
297
+ }
298
+ const timeoutMs = typeof opts.timeoutMs === "number" && Number.isFinite(opts.timeoutMs) ? Math.max(0, opts.timeoutMs) : DEFAULT_TIMEOUT_MS;
299
+ const shell = resolveShell(opts.env);
300
+ let stdout;
301
+ try {
302
+ stdout = exec(shell, [
303
+ "-l",
304
+ "-c",
305
+ "env -0"
306
+ ], {
307
+ encoding: "buffer",
308
+ timeout: timeoutMs,
309
+ maxBuffer: DEFAULT_MAX_BUFFER_BYTES,
310
+ env: opts.env,
311
+ stdio: [
312
+ "ignore",
313
+ "pipe",
314
+ "pipe"
315
+ ]
316
+ });
317
+ } catch (err) {
318
+ const msg = err instanceof Error ? err.message : String(err);
319
+ logger.warn(`[anima] shell env fallback failed: ${msg}`);
320
+ lastAppliedKeys = [];
321
+ return {
322
+ ok: false,
323
+ error: msg,
324
+ applied: []
325
+ };
326
+ }
327
+ const shellEnv = parseShellEnv(stdout);
328
+ const applied = [];
329
+ for (const key of opts.expectedKeys) {
330
+ if (opts.env[key]?.trim()) continue;
331
+ const value = shellEnv.get(key);
332
+ if (!value?.trim()) continue;
333
+ opts.env[key] = value;
334
+ applied.push(key);
335
+ }
336
+ lastAppliedKeys = applied;
337
+ return {
338
+ ok: true,
339
+ applied
340
+ };
341
+ }
342
+ function shouldEnableShellEnvFallback(env) {
343
+ return isTruthyEnvValue(env.ANIMA_LOAD_SHELL_ENV);
344
+ }
345
+ function shouldDeferShellEnvFallback(env) {
346
+ return isTruthyEnvValue(env.ANIMA_DEFER_SHELL_ENV_FALLBACK);
347
+ }
348
+ function resolveShellEnvFallbackTimeoutMs(env) {
349
+ const raw = env.ANIMA_SHELL_ENV_TIMEOUT_MS?.trim();
350
+ if (!raw) return DEFAULT_TIMEOUT_MS;
351
+ const parsed = Number.parseInt(raw, 10);
352
+ if (!Number.isFinite(parsed)) return DEFAULT_TIMEOUT_MS;
353
+ return Math.max(0, parsed);
354
+ }
355
+ function getShellPathFromLoginShell(opts) {
356
+ if (cachedShellPath !== void 0) return cachedShellPath;
357
+ if (process.platform === "win32") {
358
+ cachedShellPath = null;
359
+ return cachedShellPath;
360
+ }
361
+ const exec = opts.exec ?? execFileSync;
362
+ const timeoutMs = typeof opts.timeoutMs === "number" && Number.isFinite(opts.timeoutMs) ? Math.max(0, opts.timeoutMs) : DEFAULT_TIMEOUT_MS;
363
+ const shell = resolveShell(opts.env);
364
+ let stdout;
365
+ try {
366
+ stdout = exec(shell, [
367
+ "-l",
368
+ "-c",
369
+ "env -0"
370
+ ], {
371
+ encoding: "buffer",
372
+ timeout: timeoutMs,
373
+ maxBuffer: DEFAULT_MAX_BUFFER_BYTES,
374
+ env: opts.env,
375
+ stdio: [
376
+ "ignore",
377
+ "pipe",
378
+ "pipe"
379
+ ]
380
+ });
381
+ } catch {
382
+ cachedShellPath = null;
383
+ return cachedShellPath;
384
+ }
385
+ const shellPath = parseShellEnv(stdout).get("PATH")?.trim();
386
+ cachedShellPath = shellPath && shellPath.length > 0 ? shellPath : null;
387
+ return cachedShellPath;
388
+ }
389
+ function getShellEnvAppliedKeys() {
390
+ return [...lastAppliedKeys];
391
+ }
392
+
393
+ //#endregion
394
+ //#region src/utils/normalize-secret-input.ts
395
+ /**
396
+ * Secret normalization for copy/pasted credentials.
397
+ *
398
+ * Common footgun: line breaks (especially `\r`) embedded in API keys/tokens.
399
+ * We strip line breaks anywhere, then trim whitespace at the ends.
400
+ *
401
+ * Intentionally does NOT remove ordinary spaces inside the string to avoid
402
+ * silently altering "Bearer <token>" style values.
403
+ */
404
+ function normalizeSecretInput(value) {
405
+ if (typeof value !== "string") return "";
406
+ return value.replace(/[\r\n\u2028\u2029]+/g, "").trim();
407
+ }
408
+ function normalizeOptionalSecretInput(value) {
409
+ const normalized = normalizeSecretInput(value);
410
+ return normalized ? normalized : void 0;
411
+ }
412
+
413
+ //#endregion
414
+ //#region src/agents/model-auth.ts
415
+ const AWS_BEARER_ENV = "AWS_BEARER_TOKEN_BEDROCK";
416
+ const AWS_ACCESS_KEY_ENV = "AWS_ACCESS_KEY_ID";
417
+ const AWS_SECRET_KEY_ENV = "AWS_SECRET_ACCESS_KEY";
418
+ const AWS_PROFILE_ENV = "AWS_PROFILE";
419
+ function resolveProviderConfig(cfg, provider) {
420
+ const providers = cfg?.models?.providers ?? {};
421
+ const direct = providers[provider];
422
+ if (direct) return direct;
423
+ const normalized = normalizeProviderId(provider);
424
+ if (normalized === provider) return Object.entries(providers).find(([key]) => normalizeProviderId(key) === normalized)?.[1];
425
+ return providers[normalized] ?? Object.entries(providers).find(([key]) => normalizeProviderId(key) === normalized)?.[1];
426
+ }
427
+ function getCustomProviderApiKey(cfg, provider) {
428
+ return normalizeOptionalSecretInput(resolveProviderConfig(cfg, provider)?.apiKey);
429
+ }
430
+ function resolveProviderAuthOverride(cfg, provider) {
431
+ const auth = resolveProviderConfig(cfg, provider)?.auth;
432
+ if (auth === "api-key" || auth === "aws-sdk" || auth === "oauth" || auth === "token") return auth;
433
+ }
434
+ function resolveEnvSourceLabel(params) {
435
+ return `${params.envVars.some((envVar) => params.applied.has(envVar)) ? "shell env: " : "env: "}${params.label}`;
436
+ }
437
+ function resolveAwsSdkEnvVarName(env = process.env) {
438
+ if (env[AWS_BEARER_ENV]?.trim()) return AWS_BEARER_ENV;
439
+ if (env[AWS_ACCESS_KEY_ENV]?.trim() && env[AWS_SECRET_KEY_ENV]?.trim()) return AWS_ACCESS_KEY_ENV;
440
+ if (env[AWS_PROFILE_ENV]?.trim()) return AWS_PROFILE_ENV;
441
+ }
442
+ function resolveAwsSdkAuthInfo() {
443
+ const applied = new Set(getShellEnvAppliedKeys());
444
+ if (process.env[AWS_BEARER_ENV]?.trim()) return {
445
+ mode: "aws-sdk",
446
+ source: resolveEnvSourceLabel({
447
+ applied,
448
+ envVars: [AWS_BEARER_ENV],
449
+ label: AWS_BEARER_ENV
450
+ })
451
+ };
452
+ if (process.env[AWS_ACCESS_KEY_ENV]?.trim() && process.env[AWS_SECRET_KEY_ENV]?.trim()) return {
453
+ mode: "aws-sdk",
454
+ source: resolveEnvSourceLabel({
455
+ applied,
456
+ envVars: [AWS_ACCESS_KEY_ENV, AWS_SECRET_KEY_ENV],
457
+ label: `${AWS_ACCESS_KEY_ENV} + ${AWS_SECRET_KEY_ENV}`
458
+ })
459
+ };
460
+ if (process.env[AWS_PROFILE_ENV]?.trim()) return {
461
+ mode: "aws-sdk",
462
+ source: resolveEnvSourceLabel({
463
+ applied,
464
+ envVars: [AWS_PROFILE_ENV],
465
+ label: AWS_PROFILE_ENV
466
+ })
467
+ };
468
+ return {
469
+ mode: "aws-sdk",
470
+ source: "aws-sdk default chain"
471
+ };
472
+ }
473
+ async function resolveApiKeyForProvider(params) {
474
+ const { provider, cfg, profileId, preferredProfile } = params;
475
+ const store = params.store ?? ensureAuthProfileStore(params.agentDir);
476
+ if (profileId) {
477
+ const resolved = await resolveApiKeyForProfile({
478
+ cfg,
479
+ store,
480
+ profileId,
481
+ agentDir: params.agentDir
482
+ });
483
+ if (!resolved) throw new Error(`No credentials found for profile "${profileId}".`);
484
+ const mode = store.profiles[profileId]?.type;
485
+ return {
486
+ apiKey: resolved.apiKey,
487
+ profileId,
488
+ source: `profile:${profileId}`,
489
+ mode: mode === "oauth" ? "oauth" : mode === "token" ? "token" : "api-key"
490
+ };
491
+ }
492
+ const authOverride = resolveProviderAuthOverride(cfg, provider);
493
+ if (authOverride === "aws-sdk") return resolveAwsSdkAuthInfo();
494
+ const order = resolveAuthProfileOrder({
495
+ cfg,
496
+ store,
497
+ provider,
498
+ preferredProfile
499
+ });
500
+ for (const candidate of order) try {
501
+ const resolved = await resolveApiKeyForProfile({
502
+ cfg,
503
+ store,
504
+ profileId: candidate,
505
+ agentDir: params.agentDir
506
+ });
507
+ if (resolved) {
508
+ const mode = store.profiles[candidate]?.type;
509
+ return {
510
+ apiKey: resolved.apiKey,
511
+ profileId: candidate,
512
+ source: `profile:${candidate}`,
513
+ mode: mode === "oauth" ? "oauth" : mode === "token" ? "token" : "api-key"
514
+ };
515
+ }
516
+ } catch {}
517
+ const envResolved = resolveEnvApiKey(provider);
518
+ if (envResolved) return {
519
+ apiKey: envResolved.apiKey,
520
+ source: envResolved.source,
521
+ mode: envResolved.source.includes("OAUTH_TOKEN") ? "oauth" : "api-key"
522
+ };
523
+ const customKey = getCustomProviderApiKey(cfg, provider);
524
+ if (customKey) return {
525
+ apiKey: customKey,
526
+ source: "models.json",
527
+ mode: "api-key"
528
+ };
529
+ const normalized = normalizeProviderId(provider);
530
+ if (authOverride === void 0 && normalized === "amazon-bedrock") return resolveAwsSdkAuthInfo();
531
+ if (provider === "openai") {
532
+ if (listProfilesForProvider(store, "openai-codex").length > 0) throw new Error("No API key found for provider \"openai\". You are authenticated with OpenAI Codex OAuth. Use openai-codex/gpt-5.3-codex (OAuth) or set OPENAI_API_KEY to use openai/gpt-5.1-codex.");
533
+ }
534
+ const authStorePath = resolveAuthStorePathForDisplay(params.agentDir);
535
+ const resolvedAgentDir = path.dirname(authStorePath);
536
+ throw new Error([
537
+ `No API key found for provider "${provider}".`,
538
+ `Auth store: ${authStorePath} (agentDir: ${resolvedAgentDir}).`,
539
+ `Configure auth for this agent (${formatCliCommand("anima agents add <id>")}) or copy auth-profiles.json from the main agentDir.`
540
+ ].join(" "));
541
+ }
542
+ function resolveEnvApiKey(provider) {
543
+ const normalized = normalizeProviderId(provider);
544
+ const applied = new Set(getShellEnvAppliedKeys());
545
+ const pick = (envVar) => {
546
+ const value = normalizeOptionalSecretInput(process.env[envVar]);
547
+ if (!value) return null;
548
+ return {
549
+ apiKey: value,
550
+ source: applied.has(envVar) ? `shell env: ${envVar}` : `env: ${envVar}`
551
+ };
552
+ };
553
+ if (normalized === "github-copilot") return pick("COPILOT_GITHUB_TOKEN") ?? pick("GH_TOKEN") ?? pick("GITHUB_TOKEN");
554
+ if (normalized === "anthropic") return pick("ANTHROPIC_OAUTH_TOKEN") ?? pick("ANTHROPIC_API_KEY");
555
+ if (normalized === "chutes") return pick("CHUTES_OAUTH_TOKEN") ?? pick("CHUTES_API_KEY");
556
+ if (normalized === "zai") return pick("ZAI_API_KEY") ?? pick("Z_AI_API_KEY");
557
+ if (normalized === "google-vertex") {
558
+ const envKey = getEnvApiKey(normalized);
559
+ if (!envKey) return null;
560
+ return {
561
+ apiKey: envKey,
562
+ source: "gcloud adc"
563
+ };
564
+ }
565
+ if (normalized === "opencode") return pick("OPENCODE_API_KEY") ?? pick("OPENCODE_ZEN_API_KEY");
566
+ if (normalized === "qwen-portal") return pick("QWEN_OAUTH_TOKEN") ?? pick("QWEN_PORTAL_API_KEY");
567
+ if (normalized === "minimax-portal") return pick("MINIMAX_OAUTH_TOKEN") ?? pick("MINIMAX_API_KEY");
568
+ if (normalized === "kimi-coding") return pick("KIMI_API_KEY") ?? pick("KIMICODE_API_KEY");
569
+ if (normalized === "huggingface") return pick("HUGGINGFACE_HUB_TOKEN") ?? pick("HF_TOKEN");
570
+ const envVar = {
571
+ openai: "OPENAI_API_KEY",
572
+ google: "GEMINI_API_KEY",
573
+ voyage: "VOYAGE_API_KEY",
574
+ groq: "GROQ_API_KEY",
575
+ deepgram: "DEEPGRAM_API_KEY",
576
+ cerebras: "CEREBRAS_API_KEY",
577
+ xai: "XAI_API_KEY",
578
+ openrouter: "OPENROUTER_API_KEY",
579
+ litellm: "LITELLM_API_KEY",
580
+ "vercel-ai-gateway": "AI_GATEWAY_API_KEY",
581
+ "cloudflare-ai-gateway": "CLOUDFLARE_AI_GATEWAY_API_KEY",
582
+ moonshot: "MOONSHOT_API_KEY",
583
+ minimax: "MINIMAX_API_KEY",
584
+ nvidia: "NVIDIA_API_KEY",
585
+ xiaomi: "XIAOMI_API_KEY",
586
+ synthetic: "SYNTHETIC_API_KEY",
587
+ venice: "VENICE_API_KEY",
588
+ mistral: "MISTRAL_API_KEY",
589
+ opencode: "OPENCODE_API_KEY",
590
+ together: "TOGETHER_API_KEY",
591
+ qianfan: "QIANFAN_API_KEY",
592
+ ollama: "OLLAMA_API_KEY",
593
+ vllm: "VLLM_API_KEY"
594
+ }[normalized];
595
+ if (!envVar) return null;
596
+ return pick(envVar);
597
+ }
598
+ function resolveModelAuthMode(provider, cfg, store) {
599
+ const resolved = provider?.trim();
600
+ if (!resolved) return;
601
+ const authOverride = resolveProviderAuthOverride(cfg, resolved);
602
+ if (authOverride === "aws-sdk") return "aws-sdk";
603
+ const authStore = store ?? ensureAuthProfileStore();
604
+ const profiles = listProfilesForProvider(authStore, resolved);
605
+ if (profiles.length > 0) {
606
+ const modes = new Set(profiles.map((id) => authStore.profiles[id]?.type).filter((mode) => Boolean(mode)));
607
+ if ([
608
+ "oauth",
609
+ "token",
610
+ "api_key"
611
+ ].filter((k) => modes.has(k)).length >= 2) return "mixed";
612
+ if (modes.has("oauth")) return "oauth";
613
+ if (modes.has("token")) return "token";
614
+ if (modes.has("api_key")) return "api-key";
615
+ }
616
+ if (authOverride === void 0 && normalizeProviderId(resolved) === "amazon-bedrock") return "aws-sdk";
617
+ const envKey = resolveEnvApiKey(resolved);
618
+ if (envKey?.apiKey) return envKey.source.includes("OAUTH_TOKEN") ? "oauth" : "api-key";
619
+ if (getCustomProviderApiKey(cfg, resolved)) return "api-key";
620
+ return "unknown";
621
+ }
622
+ async function getApiKeyForModel(params) {
623
+ return resolveApiKeyForProvider({
624
+ provider: params.model.provider,
625
+ cfg: params.cfg,
626
+ profileId: params.profileId,
627
+ preferredProfile: params.preferredProfile,
628
+ store: params.store,
629
+ agentDir: params.agentDir
630
+ });
631
+ }
632
+ function requireApiKey(auth, provider) {
633
+ const key = normalizeSecretInput(auth.apiKey);
634
+ if (key) return key;
635
+ throw new Error(`No API key resolved for provider "${provider}" (auth mode: ${auth.mode}).`);
636
+ }
637
+
638
+ //#endregion
639
+ //#region src/agents/synthetic-models.ts
640
+ const SYNTHETIC_BASE_URL = "https://api.synthetic.new/anthropic";
641
+ const SYNTHETIC_DEFAULT_MODEL_ID = "hf:MiniMaxAI/MiniMax-M2.1";
642
+ const SYNTHETIC_DEFAULT_MODEL_REF = `synthetic/${SYNTHETIC_DEFAULT_MODEL_ID}`;
643
+ const SYNTHETIC_DEFAULT_COST = {
644
+ input: 0,
645
+ output: 0,
646
+ cacheRead: 0,
647
+ cacheWrite: 0
648
+ };
649
+ const SYNTHETIC_MODEL_CATALOG = [
650
+ {
651
+ id: SYNTHETIC_DEFAULT_MODEL_ID,
652
+ name: "MiniMax M2.1",
653
+ reasoning: false,
654
+ input: ["text"],
655
+ contextWindow: 192e3,
656
+ maxTokens: 65536
657
+ },
658
+ {
659
+ id: "hf:moonshotai/Kimi-K2-Thinking",
660
+ name: "Kimi K2 Thinking",
661
+ reasoning: true,
662
+ input: ["text"],
663
+ contextWindow: 256e3,
664
+ maxTokens: 8192
665
+ },
666
+ {
667
+ id: "hf:zai-org/GLM-4.7",
668
+ name: "GLM-4.7",
669
+ reasoning: false,
670
+ input: ["text"],
671
+ contextWindow: 198e3,
672
+ maxTokens: 128e3
673
+ },
674
+ {
675
+ id: "hf:deepseek-ai/DeepSeek-R1-0528",
676
+ name: "DeepSeek R1 0528",
677
+ reasoning: false,
678
+ input: ["text"],
679
+ contextWindow: 128e3,
680
+ maxTokens: 8192
681
+ },
682
+ {
683
+ id: "hf:deepseek-ai/DeepSeek-V3-0324",
684
+ name: "DeepSeek V3 0324",
685
+ reasoning: false,
686
+ input: ["text"],
687
+ contextWindow: 128e3,
688
+ maxTokens: 8192
689
+ },
690
+ {
691
+ id: "hf:deepseek-ai/DeepSeek-V3.1",
692
+ name: "DeepSeek V3.1",
693
+ reasoning: false,
694
+ input: ["text"],
695
+ contextWindow: 128e3,
696
+ maxTokens: 8192
697
+ },
698
+ {
699
+ id: "hf:deepseek-ai/DeepSeek-V3.1-Terminus",
700
+ name: "DeepSeek V3.1 Terminus",
701
+ reasoning: false,
702
+ input: ["text"],
703
+ contextWindow: 128e3,
704
+ maxTokens: 8192
705
+ },
706
+ {
707
+ id: "hf:deepseek-ai/DeepSeek-V3.2",
708
+ name: "DeepSeek V3.2",
709
+ reasoning: false,
710
+ input: ["text"],
711
+ contextWindow: 159e3,
712
+ maxTokens: 8192
713
+ },
714
+ {
715
+ id: "hf:meta-llama/Llama-3.3-70B-Instruct",
716
+ name: "Llama 3.3 70B Instruct",
717
+ reasoning: false,
718
+ input: ["text"],
719
+ contextWindow: 128e3,
720
+ maxTokens: 8192
721
+ },
722
+ {
723
+ id: "hf:meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8",
724
+ name: "Llama 4 Maverick 17B 128E Instruct FP8",
725
+ reasoning: false,
726
+ input: ["text"],
727
+ contextWindow: 524e3,
728
+ maxTokens: 8192
729
+ },
730
+ {
731
+ id: "hf:moonshotai/Kimi-K2-Instruct-0905",
732
+ name: "Kimi K2 Instruct 0905",
733
+ reasoning: false,
734
+ input: ["text"],
735
+ contextWindow: 256e3,
736
+ maxTokens: 8192
737
+ },
738
+ {
739
+ id: "hf:moonshotai/Kimi-K2.5",
740
+ name: "Kimi K2.5",
741
+ reasoning: true,
742
+ input: ["text"],
743
+ contextWindow: 256e3,
744
+ maxTokens: 8192
745
+ },
746
+ {
747
+ id: "hf:openai/gpt-oss-120b",
748
+ name: "GPT OSS 120B",
749
+ reasoning: false,
750
+ input: ["text"],
751
+ contextWindow: 128e3,
752
+ maxTokens: 8192
753
+ },
754
+ {
755
+ id: "hf:Qwen/Qwen3-235B-A22B-Instruct-2507",
756
+ name: "Qwen3 235B A22B Instruct 2507",
757
+ reasoning: false,
758
+ input: ["text"],
759
+ contextWindow: 256e3,
760
+ maxTokens: 8192
761
+ },
762
+ {
763
+ id: "hf:Qwen/Qwen3-Coder-480B-A35B-Instruct",
764
+ name: "Qwen3 Coder 480B A35B Instruct",
765
+ reasoning: false,
766
+ input: ["text"],
767
+ contextWindow: 256e3,
768
+ maxTokens: 8192
769
+ },
770
+ {
771
+ id: "hf:Qwen/Qwen3-VL-235B-A22B-Instruct",
772
+ name: "Qwen3 VL 235B A22B Instruct",
773
+ reasoning: false,
774
+ input: ["text", "image"],
775
+ contextWindow: 25e4,
776
+ maxTokens: 8192
777
+ },
778
+ {
779
+ id: "hf:zai-org/GLM-4.5",
780
+ name: "GLM-4.5",
781
+ reasoning: false,
782
+ input: ["text"],
783
+ contextWindow: 128e3,
784
+ maxTokens: 128e3
785
+ },
786
+ {
787
+ id: "hf:zai-org/GLM-4.6",
788
+ name: "GLM-4.6",
789
+ reasoning: false,
790
+ input: ["text"],
791
+ contextWindow: 198e3,
792
+ maxTokens: 128e3
793
+ },
794
+ {
795
+ id: "hf:zai-org/GLM-5",
796
+ name: "GLM-5",
797
+ reasoning: true,
798
+ input: ["text", "image"],
799
+ contextWindow: 256e3,
800
+ maxTokens: 128e3
801
+ },
802
+ {
803
+ id: "hf:deepseek-ai/DeepSeek-V3",
804
+ name: "DeepSeek V3",
805
+ reasoning: false,
806
+ input: ["text"],
807
+ contextWindow: 128e3,
808
+ maxTokens: 8192
809
+ },
810
+ {
811
+ id: "hf:Qwen/Qwen3-235B-A22B-Thinking-2507",
812
+ name: "Qwen3 235B A22B Thinking 2507",
813
+ reasoning: true,
814
+ input: ["text"],
815
+ contextWindow: 256e3,
816
+ maxTokens: 8192
817
+ }
818
+ ];
819
+ function buildSyntheticModelDefinition(entry) {
820
+ return {
821
+ id: entry.id,
822
+ name: entry.name,
823
+ reasoning: entry.reasoning,
824
+ input: [...entry.input],
825
+ cost: SYNTHETIC_DEFAULT_COST,
826
+ contextWindow: entry.contextWindow,
827
+ maxTokens: entry.maxTokens
828
+ };
829
+ }
830
+
831
+ //#endregion
832
+ //#region src/agents/together-models.ts
833
+ const TOGETHER_BASE_URL = "https://api.together.xyz/v1";
834
+ const TOGETHER_MODEL_CATALOG = [
835
+ {
836
+ id: "zai-org/GLM-4.7",
837
+ name: "GLM 4.7 Fp8",
838
+ reasoning: false,
839
+ input: ["text"],
840
+ contextWindow: 202752,
841
+ maxTokens: 8192,
842
+ cost: {
843
+ input: .45,
844
+ output: 2,
845
+ cacheRead: .45,
846
+ cacheWrite: 2
847
+ }
848
+ },
849
+ {
850
+ id: "moonshotai/Kimi-K2.5",
851
+ name: "Kimi K2.5",
852
+ reasoning: true,
853
+ input: ["text", "image"],
854
+ cost: {
855
+ input: .5,
856
+ output: 2.8,
857
+ cacheRead: .5,
858
+ cacheWrite: 2.8
859
+ },
860
+ contextWindow: 262144,
861
+ maxTokens: 32768
862
+ },
863
+ {
864
+ id: "meta-llama/Llama-3.3-70B-Instruct-Turbo",
865
+ name: "Llama 3.3 70B Instruct Turbo",
866
+ reasoning: false,
867
+ input: ["text"],
868
+ contextWindow: 131072,
869
+ maxTokens: 8192,
870
+ cost: {
871
+ input: .88,
872
+ output: .88,
873
+ cacheRead: .88,
874
+ cacheWrite: .88
875
+ }
876
+ },
877
+ {
878
+ id: "meta-llama/Llama-4-Scout-17B-16E-Instruct",
879
+ name: "Llama 4 Scout 17B 16E Instruct",
880
+ reasoning: false,
881
+ input: ["text", "image"],
882
+ contextWindow: 1e7,
883
+ maxTokens: 32768,
884
+ cost: {
885
+ input: .18,
886
+ output: .59,
887
+ cacheRead: .18,
888
+ cacheWrite: .18
889
+ }
890
+ },
891
+ {
892
+ id: "meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8",
893
+ name: "Llama 4 Maverick 17B 128E Instruct FP8",
894
+ reasoning: false,
895
+ input: ["text", "image"],
896
+ contextWindow: 2e7,
897
+ maxTokens: 32768,
898
+ cost: {
899
+ input: .27,
900
+ output: .85,
901
+ cacheRead: .27,
902
+ cacheWrite: .27
903
+ }
904
+ },
905
+ {
906
+ id: "deepseek-ai/DeepSeek-V3.1",
907
+ name: "DeepSeek V3.1",
908
+ reasoning: false,
909
+ input: ["text"],
910
+ contextWindow: 131072,
911
+ maxTokens: 8192,
912
+ cost: {
913
+ input: .6,
914
+ output: 1.25,
915
+ cacheRead: .6,
916
+ cacheWrite: .6
917
+ }
918
+ },
919
+ {
920
+ id: "deepseek-ai/DeepSeek-R1",
921
+ name: "DeepSeek R1",
922
+ reasoning: true,
923
+ input: ["text"],
924
+ contextWindow: 131072,
925
+ maxTokens: 8192,
926
+ cost: {
927
+ input: 3,
928
+ output: 7,
929
+ cacheRead: 3,
930
+ cacheWrite: 3
931
+ }
932
+ },
933
+ {
934
+ id: "moonshotai/Kimi-K2-Instruct-0905",
935
+ name: "Kimi K2-Instruct 0905",
936
+ reasoning: false,
937
+ input: ["text"],
938
+ contextWindow: 262144,
939
+ maxTokens: 8192,
940
+ cost: {
941
+ input: 1,
942
+ output: 3,
943
+ cacheRead: 1,
944
+ cacheWrite: 3
945
+ }
946
+ }
947
+ ];
948
+ function buildTogetherModelDefinition(model) {
949
+ return {
950
+ id: model.id,
951
+ name: model.name,
952
+ api: "openai-completions",
953
+ reasoning: model.reasoning,
954
+ input: model.input,
955
+ cost: model.cost,
956
+ contextWindow: model.contextWindow,
957
+ maxTokens: model.maxTokens
958
+ };
959
+ }
960
+
961
+ //#endregion
962
+ //#region src/agents/venice-models.ts
963
+ const VENICE_BASE_URL = "https://api.venice.ai/api/v1";
964
+ const VENICE_DEFAULT_MODEL_ID = "llama-3.3-70b";
965
+ const VENICE_DEFAULT_MODEL_REF = `venice/${VENICE_DEFAULT_MODEL_ID}`;
966
+ const VENICE_DEFAULT_COST = {
967
+ input: 0,
968
+ output: 0,
969
+ cacheRead: 0,
970
+ cacheWrite: 0
971
+ };
972
+ /**
973
+ * Complete catalog of Venice AI models.
974
+ *
975
+ * Venice provides two privacy modes:
976
+ * - "private": Fully private inference, no logging, ephemeral
977
+ * - "anonymized": Proxied through Venice with metadata stripped (for proprietary models)
978
+ *
979
+ * Note: The `privacy` field is included for documentation purposes but is not
980
+ * propagated to ModelDefinitionConfig as it's not part of the core model schema.
981
+ * Privacy mode is determined by the model itself, not configurable at runtime.
982
+ *
983
+ * This catalog serves as a fallback when the Venice API is unreachable.
984
+ */
985
+ const VENICE_MODEL_CATALOG = [
986
+ {
987
+ id: "llama-3.3-70b",
988
+ name: "Llama 3.3 70B",
989
+ reasoning: false,
990
+ input: ["text"],
991
+ contextWindow: 131072,
992
+ maxTokens: 8192,
993
+ privacy: "private"
994
+ },
995
+ {
996
+ id: "llama-3.2-3b",
997
+ name: "Llama 3.2 3B",
998
+ reasoning: false,
999
+ input: ["text"],
1000
+ contextWindow: 131072,
1001
+ maxTokens: 8192,
1002
+ privacy: "private"
1003
+ },
1004
+ {
1005
+ id: "hermes-3-llama-3.1-405b",
1006
+ name: "Hermes 3 Llama 3.1 405B",
1007
+ reasoning: false,
1008
+ input: ["text"],
1009
+ contextWindow: 131072,
1010
+ maxTokens: 8192,
1011
+ privacy: "private"
1012
+ },
1013
+ {
1014
+ id: "qwen3-235b-a22b-thinking-2507",
1015
+ name: "Qwen3 235B Thinking",
1016
+ reasoning: true,
1017
+ input: ["text"],
1018
+ contextWindow: 131072,
1019
+ maxTokens: 8192,
1020
+ privacy: "private"
1021
+ },
1022
+ {
1023
+ id: "qwen3-235b-a22b-instruct-2507",
1024
+ name: "Qwen3 235B Instruct",
1025
+ reasoning: false,
1026
+ input: ["text"],
1027
+ contextWindow: 131072,
1028
+ maxTokens: 8192,
1029
+ privacy: "private"
1030
+ },
1031
+ {
1032
+ id: "qwen3-coder-480b-a35b-instruct",
1033
+ name: "Qwen3 Coder 480B",
1034
+ reasoning: false,
1035
+ input: ["text"],
1036
+ contextWindow: 262144,
1037
+ maxTokens: 8192,
1038
+ privacy: "private"
1039
+ },
1040
+ {
1041
+ id: "qwen3-next-80b",
1042
+ name: "Qwen3 Next 80B",
1043
+ reasoning: false,
1044
+ input: ["text"],
1045
+ contextWindow: 262144,
1046
+ maxTokens: 8192,
1047
+ privacy: "private"
1048
+ },
1049
+ {
1050
+ id: "qwen3-vl-235b-a22b",
1051
+ name: "Qwen3 VL 235B (Vision)",
1052
+ reasoning: false,
1053
+ input: ["text", "image"],
1054
+ contextWindow: 262144,
1055
+ maxTokens: 8192,
1056
+ privacy: "private"
1057
+ },
1058
+ {
1059
+ id: "qwen3-4b",
1060
+ name: "Venice Small (Qwen3 4B)",
1061
+ reasoning: true,
1062
+ input: ["text"],
1063
+ contextWindow: 32768,
1064
+ maxTokens: 8192,
1065
+ privacy: "private"
1066
+ },
1067
+ {
1068
+ id: "deepseek-v3.2",
1069
+ name: "DeepSeek V3.2",
1070
+ reasoning: true,
1071
+ input: ["text"],
1072
+ contextWindow: 163840,
1073
+ maxTokens: 8192,
1074
+ privacy: "private"
1075
+ },
1076
+ {
1077
+ id: "venice-uncensored",
1078
+ name: "Venice Uncensored (Dolphin-Mistral)",
1079
+ reasoning: false,
1080
+ input: ["text"],
1081
+ contextWindow: 32768,
1082
+ maxTokens: 8192,
1083
+ privacy: "private"
1084
+ },
1085
+ {
1086
+ id: "mistral-31-24b",
1087
+ name: "Venice Medium (Mistral)",
1088
+ reasoning: false,
1089
+ input: ["text", "image"],
1090
+ contextWindow: 131072,
1091
+ maxTokens: 8192,
1092
+ privacy: "private"
1093
+ },
1094
+ {
1095
+ id: "google-gemma-3-27b-it",
1096
+ name: "Google Gemma 3 27B Instruct",
1097
+ reasoning: false,
1098
+ input: ["text", "image"],
1099
+ contextWindow: 202752,
1100
+ maxTokens: 8192,
1101
+ privacy: "private"
1102
+ },
1103
+ {
1104
+ id: "openai-gpt-oss-120b",
1105
+ name: "OpenAI GPT OSS 120B",
1106
+ reasoning: false,
1107
+ input: ["text"],
1108
+ contextWindow: 131072,
1109
+ maxTokens: 8192,
1110
+ privacy: "private"
1111
+ },
1112
+ {
1113
+ id: "zai-org-glm-4.7",
1114
+ name: "GLM 4.7",
1115
+ reasoning: true,
1116
+ input: ["text"],
1117
+ contextWindow: 202752,
1118
+ maxTokens: 8192,
1119
+ privacy: "private"
1120
+ },
1121
+ {
1122
+ id: "claude-opus-45",
1123
+ name: "Claude Opus 4.5 (via Venice)",
1124
+ reasoning: true,
1125
+ input: ["text", "image"],
1126
+ contextWindow: 202752,
1127
+ maxTokens: 8192,
1128
+ privacy: "anonymized"
1129
+ },
1130
+ {
1131
+ id: "claude-sonnet-45",
1132
+ name: "Claude Sonnet 4.5 (via Venice)",
1133
+ reasoning: true,
1134
+ input: ["text", "image"],
1135
+ contextWindow: 202752,
1136
+ maxTokens: 8192,
1137
+ privacy: "anonymized"
1138
+ },
1139
+ {
1140
+ id: "openai-gpt-52",
1141
+ name: "GPT-5.2 (via Venice)",
1142
+ reasoning: true,
1143
+ input: ["text"],
1144
+ contextWindow: 262144,
1145
+ maxTokens: 8192,
1146
+ privacy: "anonymized"
1147
+ },
1148
+ {
1149
+ id: "openai-gpt-52-codex",
1150
+ name: "GPT-5.2 Codex (via Venice)",
1151
+ reasoning: true,
1152
+ input: ["text", "image"],
1153
+ contextWindow: 262144,
1154
+ maxTokens: 8192,
1155
+ privacy: "anonymized"
1156
+ },
1157
+ {
1158
+ id: "gemini-3-pro-preview",
1159
+ name: "Gemini 3 Pro (via Venice)",
1160
+ reasoning: true,
1161
+ input: ["text", "image"],
1162
+ contextWindow: 202752,
1163
+ maxTokens: 8192,
1164
+ privacy: "anonymized"
1165
+ },
1166
+ {
1167
+ id: "gemini-3-flash-preview",
1168
+ name: "Gemini 3 Flash (via Venice)",
1169
+ reasoning: true,
1170
+ input: ["text", "image"],
1171
+ contextWindow: 262144,
1172
+ maxTokens: 8192,
1173
+ privacy: "anonymized"
1174
+ },
1175
+ {
1176
+ id: "grok-41-fast",
1177
+ name: "Grok 4.1 Fast (via Venice)",
1178
+ reasoning: true,
1179
+ input: ["text", "image"],
1180
+ contextWindow: 262144,
1181
+ maxTokens: 8192,
1182
+ privacy: "anonymized"
1183
+ },
1184
+ {
1185
+ id: "grok-code-fast-1",
1186
+ name: "Grok Code Fast 1 (via Venice)",
1187
+ reasoning: true,
1188
+ input: ["text"],
1189
+ contextWindow: 262144,
1190
+ maxTokens: 8192,
1191
+ privacy: "anonymized"
1192
+ },
1193
+ {
1194
+ id: "kimi-k2-thinking",
1195
+ name: "Kimi K2 Thinking (via Venice)",
1196
+ reasoning: true,
1197
+ input: ["text"],
1198
+ contextWindow: 262144,
1199
+ maxTokens: 8192,
1200
+ privacy: "anonymized"
1201
+ },
1202
+ {
1203
+ id: "minimax-m21",
1204
+ name: "MiniMax M2.1 (via Venice)",
1205
+ reasoning: true,
1206
+ input: ["text"],
1207
+ contextWindow: 202752,
1208
+ maxTokens: 8192,
1209
+ privacy: "anonymized"
1210
+ }
1211
+ ];
1212
+ /**
1213
+ * Build a ModelDefinitionConfig from a Venice catalog entry.
1214
+ *
1215
+ * Note: The `privacy` field from the catalog is not included in the output
1216
+ * as ModelDefinitionConfig doesn't support custom metadata fields. Privacy
1217
+ * mode is inherent to each model and documented in the catalog/docs.
1218
+ */
1219
+ function buildVeniceModelDefinition(entry) {
1220
+ return {
1221
+ id: entry.id,
1222
+ name: entry.name,
1223
+ reasoning: entry.reasoning,
1224
+ input: [...entry.input],
1225
+ cost: VENICE_DEFAULT_COST,
1226
+ contextWindow: entry.contextWindow,
1227
+ maxTokens: entry.maxTokens,
1228
+ compat: { supportsUsageInStreaming: false }
1229
+ };
1230
+ }
1231
+
1232
+ //#endregion
1233
+ //#region src/agents/models-config.providers.ts
1234
+ const XIAOMI_BASE_URL = "https://api.xiaomimimo.com/anthropic";
1235
+ const XIAOMI_DEFAULT_MODEL_ID = "mimo-v2-flash";
1236
+ const XIAOMI_DEFAULT_CONTEXT_WINDOW = 262144;
1237
+ const XIAOMI_DEFAULT_MAX_TOKENS = 8192;
1238
+ const XIAOMI_DEFAULT_COST = {
1239
+ input: 0,
1240
+ output: 0,
1241
+ cacheRead: 0,
1242
+ cacheWrite: 0
1243
+ };
1244
+ const QIANFAN_BASE_URL = "https://qianfan.baidubce.com/v2";
1245
+ const QIANFAN_DEFAULT_MODEL_ID = "deepseek-v3.2";
1246
+ const QIANFAN_DEFAULT_CONTEXT_WINDOW = 98304;
1247
+ const QIANFAN_DEFAULT_MAX_TOKENS = 32768;
1248
+ const QIANFAN_DEFAULT_COST = {
1249
+ input: 0,
1250
+ output: 0,
1251
+ cacheRead: 0,
1252
+ cacheWrite: 0
1253
+ };
1254
+ function normalizeGoogleModelId(id) {
1255
+ if (id === "gemini-3-pro") return "gemini-3-pro-preview";
1256
+ if (id === "gemini-3-flash") return "gemini-3-flash-preview";
1257
+ return id;
1258
+ }
1259
+ function buildXiaomiProvider() {
1260
+ return {
1261
+ baseUrl: XIAOMI_BASE_URL,
1262
+ api: "anthropic-messages",
1263
+ models: [{
1264
+ id: XIAOMI_DEFAULT_MODEL_ID,
1265
+ name: "Xiaomi MiMo V2 Flash",
1266
+ reasoning: false,
1267
+ input: ["text"],
1268
+ cost: XIAOMI_DEFAULT_COST,
1269
+ contextWindow: XIAOMI_DEFAULT_CONTEXT_WINDOW,
1270
+ maxTokens: XIAOMI_DEFAULT_MAX_TOKENS
1271
+ }]
1272
+ };
1273
+ }
1274
+ function buildQianfanProvider() {
1275
+ return {
1276
+ baseUrl: QIANFAN_BASE_URL,
1277
+ api: "openai-completions",
1278
+ models: [{
1279
+ id: QIANFAN_DEFAULT_MODEL_ID,
1280
+ name: "DEEPSEEK V3.2",
1281
+ reasoning: true,
1282
+ input: ["text"],
1283
+ cost: QIANFAN_DEFAULT_COST,
1284
+ contextWindow: QIANFAN_DEFAULT_CONTEXT_WINDOW,
1285
+ maxTokens: QIANFAN_DEFAULT_MAX_TOKENS
1286
+ }, {
1287
+ id: "ernie-5.0-thinking-preview",
1288
+ name: "ERNIE-5.0-Thinking-Preview",
1289
+ reasoning: true,
1290
+ input: ["text", "image"],
1291
+ cost: QIANFAN_DEFAULT_COST,
1292
+ contextWindow: 119e3,
1293
+ maxTokens: 64e3
1294
+ }]
1295
+ };
1296
+ }
1297
+
1298
+ //#endregion
1299
+ //#region src/agents/model-selection.ts
1300
+ const ANTHROPIC_MODEL_ALIASES = {
1301
+ "opus-4.6": "claude-opus-4-6",
1302
+ "opus-4.5": "claude-opus-4-5",
1303
+ "sonnet-4.5": "claude-sonnet-4-5"
1304
+ };
1305
+ const OPENAI_CODEX_OAUTH_MODEL_PREFIXES = ["gpt-5.3-codex"];
1306
+ function normalizeAliasKey(value) {
1307
+ return value.trim().toLowerCase();
1308
+ }
1309
+ function modelKey(provider, model) {
1310
+ return `${provider}/${model}`;
1311
+ }
1312
+ function normalizeProviderId(provider) {
1313
+ const normalized = provider.trim().toLowerCase();
1314
+ if (normalized === "z.ai" || normalized === "z-ai") return "zai";
1315
+ if (normalized === "opencode-zen") return "opencode";
1316
+ if (normalized === "qwen") return "qwen-portal";
1317
+ if (normalized === "kimi-code") return "kimi-coding";
1318
+ return normalized;
1319
+ }
1320
+ function isCliProvider(provider, cfg) {
1321
+ const normalized = normalizeProviderId(provider);
1322
+ if (normalized === "claude-cli") return true;
1323
+ if (normalized === "codex-cli") return true;
1324
+ const backends = cfg?.agents?.defaults?.cliBackends ?? {};
1325
+ return Object.keys(backends).some((key) => normalizeProviderId(key) === normalized);
1326
+ }
1327
+ function normalizeAnthropicModelId(model) {
1328
+ const trimmed = model.trim();
1329
+ if (!trimmed) return trimmed;
1330
+ return ANTHROPIC_MODEL_ALIASES[trimmed.toLowerCase()] ?? trimmed;
1331
+ }
1332
+ function normalizeProviderModelId(provider, model) {
1333
+ if (provider === "anthropic") return normalizeAnthropicModelId(model);
1334
+ if (provider === "google") return normalizeGoogleModelId(model);
1335
+ return model;
1336
+ }
1337
+ function shouldUseOpenAICodexProvider(provider, model) {
1338
+ if (provider !== "openai") return false;
1339
+ const normalized = model.trim().toLowerCase();
1340
+ if (!normalized) return false;
1341
+ return OPENAI_CODEX_OAUTH_MODEL_PREFIXES.some((prefix) => normalized === prefix || normalized.startsWith(`${prefix}-`));
1342
+ }
1343
+ function normalizeModelRef(provider, model) {
1344
+ const normalizedProvider = normalizeProviderId(provider);
1345
+ const normalizedModel = normalizeProviderModelId(normalizedProvider, model.trim());
1346
+ if (shouldUseOpenAICodexProvider(normalizedProvider, normalizedModel)) return {
1347
+ provider: "openai-codex",
1348
+ model: normalizedModel
1349
+ };
1350
+ return {
1351
+ provider: normalizedProvider,
1352
+ model: normalizedModel
1353
+ };
1354
+ }
1355
+ function parseModelRef(raw, defaultProvider) {
1356
+ const trimmed = raw.trim();
1357
+ if (!trimmed) return null;
1358
+ const slash = trimmed.indexOf("/");
1359
+ if (slash === -1) return normalizeModelRef(defaultProvider, trimmed);
1360
+ const providerRaw = trimmed.slice(0, slash).trim();
1361
+ const model = trimmed.slice(slash + 1).trim();
1362
+ if (!providerRaw || !model) return null;
1363
+ return normalizeModelRef(providerRaw, model);
1364
+ }
1365
+ function resolveAllowlistModelKey(raw, defaultProvider) {
1366
+ const parsed = parseModelRef(raw, defaultProvider);
1367
+ if (!parsed) return null;
1368
+ return modelKey(parsed.provider, parsed.model);
1369
+ }
1370
+ function buildConfiguredAllowlistKeys(params) {
1371
+ const rawAllowlist = Object.keys(params.cfg?.agents?.defaults?.models ?? {});
1372
+ if (rawAllowlist.length === 0) return null;
1373
+ const keys = /* @__PURE__ */ new Set();
1374
+ for (const raw of rawAllowlist) {
1375
+ const key = resolveAllowlistModelKey(String(raw ?? ""), params.defaultProvider);
1376
+ if (key) keys.add(key);
1377
+ }
1378
+ return keys.size > 0 ? keys : null;
1379
+ }
1380
+ function buildModelAliasIndex(params) {
1381
+ const byAlias = /* @__PURE__ */ new Map();
1382
+ const byKey = /* @__PURE__ */ new Map();
1383
+ const rawModels = params.cfg.agents?.defaults?.models ?? {};
1384
+ for (const [keyRaw, entryRaw] of Object.entries(rawModels)) {
1385
+ const parsed = parseModelRef(String(keyRaw ?? ""), params.defaultProvider);
1386
+ if (!parsed) continue;
1387
+ const alias = String(entryRaw?.alias ?? "").trim();
1388
+ if (!alias) continue;
1389
+ const aliasKey = normalizeAliasKey(alias);
1390
+ byAlias.set(aliasKey, {
1391
+ alias,
1392
+ ref: parsed
1393
+ });
1394
+ const key = modelKey(parsed.provider, parsed.model);
1395
+ const existing = byKey.get(key) ?? [];
1396
+ existing.push(alias);
1397
+ byKey.set(key, existing);
1398
+ }
1399
+ return {
1400
+ byAlias,
1401
+ byKey
1402
+ };
1403
+ }
1404
+ function resolveModelRefFromString(params) {
1405
+ const trimmed = params.raw.trim();
1406
+ if (!trimmed) return null;
1407
+ if (!trimmed.includes("/")) {
1408
+ const aliasKey = normalizeAliasKey(trimmed);
1409
+ const aliasMatch = params.aliasIndex?.byAlias.get(aliasKey);
1410
+ if (aliasMatch) return {
1411
+ ref: aliasMatch.ref,
1412
+ alias: aliasMatch.alias
1413
+ };
1414
+ }
1415
+ const parsed = parseModelRef(trimmed, params.defaultProvider);
1416
+ if (!parsed) return null;
1417
+ return { ref: parsed };
1418
+ }
1419
+ function resolveConfiguredModelRef(params) {
1420
+ const rawModel = (() => {
1421
+ const raw = params.cfg.agents?.defaults?.model;
1422
+ if (typeof raw === "string") return raw.trim();
1423
+ return raw?.primary?.trim() ?? "";
1424
+ })();
1425
+ if (rawModel) {
1426
+ const trimmed = rawModel.trim();
1427
+ const aliasIndex = buildModelAliasIndex({
1428
+ cfg: params.cfg,
1429
+ defaultProvider: params.defaultProvider
1430
+ });
1431
+ if (!trimmed.includes("/")) {
1432
+ const aliasKey = normalizeAliasKey(trimmed);
1433
+ const aliasMatch = aliasIndex.byAlias.get(aliasKey);
1434
+ if (aliasMatch) return aliasMatch.ref;
1435
+ console.warn(`[anima] Model "${trimmed}" specified without provider. Falling back to "anthropic/${trimmed}". Please use "anthropic/${trimmed}" in your config.`);
1436
+ return {
1437
+ provider: "anthropic",
1438
+ model: trimmed
1439
+ };
1440
+ }
1441
+ const resolved = resolveModelRefFromString({
1442
+ raw: trimmed,
1443
+ defaultProvider: params.defaultProvider,
1444
+ aliasIndex
1445
+ });
1446
+ if (resolved) return resolved.ref;
1447
+ }
1448
+ return {
1449
+ provider: params.defaultProvider,
1450
+ model: params.defaultModel
1451
+ };
1452
+ }
1453
+ function resolveDefaultModelForAgent(params) {
1454
+ const agentModelOverride = params.agentId ? resolveAgentModelPrimary(params.cfg, params.agentId) : void 0;
1455
+ return resolveConfiguredModelRef({
1456
+ cfg: agentModelOverride && agentModelOverride.length > 0 ? {
1457
+ ...params.cfg,
1458
+ agents: {
1459
+ ...params.cfg.agents,
1460
+ defaults: {
1461
+ ...params.cfg.agents?.defaults,
1462
+ model: {
1463
+ ...typeof params.cfg.agents?.defaults?.model === "object" ? params.cfg.agents.defaults.model : void 0,
1464
+ primary: agentModelOverride
1465
+ }
1466
+ }
1467
+ }
1468
+ } : params.cfg,
1469
+ defaultProvider: DEFAULT_PROVIDER,
1470
+ defaultModel: DEFAULT_MODEL
1471
+ });
1472
+ }
1473
+ function buildAllowedModelSet(params) {
1474
+ const rawAllowlist = (() => {
1475
+ const modelMap = params.cfg.agents?.defaults?.models ?? {};
1476
+ return Object.keys(modelMap);
1477
+ })();
1478
+ const allowAny = rawAllowlist.length === 0;
1479
+ const defaultModel = params.defaultModel?.trim();
1480
+ const defaultKey = defaultModel && params.defaultProvider ? modelKey(params.defaultProvider, defaultModel) : void 0;
1481
+ const catalogKeys = new Set(params.catalog.map((entry) => modelKey(entry.provider, entry.id)));
1482
+ if (allowAny) {
1483
+ if (defaultKey) catalogKeys.add(defaultKey);
1484
+ return {
1485
+ allowAny: true,
1486
+ allowedCatalog: params.catalog,
1487
+ allowedKeys: catalogKeys
1488
+ };
1489
+ }
1490
+ const allowedKeys = /* @__PURE__ */ new Set();
1491
+ const configuredProviders = params.cfg.models?.providers ?? {};
1492
+ for (const raw of rawAllowlist) {
1493
+ const parsed = parseModelRef(String(raw), params.defaultProvider);
1494
+ if (!parsed) continue;
1495
+ const key = modelKey(parsed.provider, parsed.model);
1496
+ const providerKey = normalizeProviderId(parsed.provider);
1497
+ if (isCliProvider(parsed.provider, params.cfg)) allowedKeys.add(key);
1498
+ else if (catalogKeys.has(key)) allowedKeys.add(key);
1499
+ else if (configuredProviders[providerKey] != null) allowedKeys.add(key);
1500
+ }
1501
+ if (defaultKey) allowedKeys.add(defaultKey);
1502
+ const allowedCatalog = params.catalog.filter((entry) => allowedKeys.has(modelKey(entry.provider, entry.id)));
1503
+ if (allowedCatalog.length === 0 && allowedKeys.size === 0) {
1504
+ if (defaultKey) catalogKeys.add(defaultKey);
1505
+ return {
1506
+ allowAny: true,
1507
+ allowedCatalog: params.catalog,
1508
+ allowedKeys: catalogKeys
1509
+ };
1510
+ }
1511
+ return {
1512
+ allowAny: false,
1513
+ allowedCatalog,
1514
+ allowedKeys
1515
+ };
1516
+ }
1517
+ function getModelRefStatus(params) {
1518
+ const allowed = buildAllowedModelSet({
1519
+ cfg: params.cfg,
1520
+ catalog: params.catalog,
1521
+ defaultProvider: params.defaultProvider,
1522
+ defaultModel: params.defaultModel
1523
+ });
1524
+ const key = modelKey(params.ref.provider, params.ref.model);
1525
+ return {
1526
+ key,
1527
+ inCatalog: params.catalog.some((entry) => modelKey(entry.provider, entry.id) === key),
1528
+ allowAny: allowed.allowAny,
1529
+ allowed: allowed.allowAny || allowed.allowedKeys.has(key)
1530
+ };
1531
+ }
1532
+ function resolveAllowedModelRef(params) {
1533
+ const trimmed = params.raw.trim();
1534
+ if (!trimmed) return { error: "invalid model: empty" };
1535
+ const aliasIndex = buildModelAliasIndex({
1536
+ cfg: params.cfg,
1537
+ defaultProvider: params.defaultProvider
1538
+ });
1539
+ const resolved = resolveModelRefFromString({
1540
+ raw: trimmed,
1541
+ defaultProvider: params.defaultProvider,
1542
+ aliasIndex
1543
+ });
1544
+ if (!resolved) return { error: `invalid model: ${trimmed}` };
1545
+ const status = getModelRefStatus({
1546
+ cfg: params.cfg,
1547
+ catalog: params.catalog,
1548
+ ref: resolved.ref,
1549
+ defaultProvider: params.defaultProvider,
1550
+ defaultModel: params.defaultModel
1551
+ });
1552
+ if (!status.allowed) return { error: `model not allowed: ${status.key}` };
1553
+ return {
1554
+ ref: resolved.ref,
1555
+ key: status.key
1556
+ };
1557
+ }
1558
+ function resolveThinkingDefault(params) {
1559
+ const configured = params.cfg.agents?.defaults?.thinkingDefault;
1560
+ if (configured) return configured;
1561
+ if ((params.catalog?.find((entry) => entry.provider === params.provider && entry.id === params.model))?.reasoning) return "low";
1562
+ return "off";
1563
+ }
1564
+ /**
1565
+ * Resolve the model configured for Gmail hook processing.
1566
+ * Returns null if hooks.gmail.model is not set.
1567
+ */
1568
+ function resolveHooksGmailModel(params) {
1569
+ const hooksModel = params.cfg.hooks?.gmail?.model;
1570
+ if (!hooksModel?.trim()) return null;
1571
+ const aliasIndex = buildModelAliasIndex({
1572
+ cfg: params.cfg,
1573
+ defaultProvider: params.defaultProvider
1574
+ });
1575
+ return resolveModelRefFromString({
1576
+ raw: hooksModel,
1577
+ defaultProvider: params.defaultProvider,
1578
+ aliasIndex
1579
+ })?.ref ?? null;
1580
+ }
1581
+
1582
+ //#endregion
1583
+ //#region src/plugin-sdk/file-lock.ts
1584
+ const HELD_LOCKS_KEY = Symbol.for("anima.fileLockHeldLocks");
1585
+ function resolveHeldLocks() {
1586
+ const proc = process;
1587
+ if (!proc[HELD_LOCKS_KEY]) proc[HELD_LOCKS_KEY] = /* @__PURE__ */ new Map();
1588
+ return proc[HELD_LOCKS_KEY];
1589
+ }
1590
+ const HELD_LOCKS = resolveHeldLocks();
1591
+ function isAlive(pid) {
1592
+ if (!Number.isFinite(pid) || pid <= 0) return false;
1593
+ try {
1594
+ process.kill(pid, 0);
1595
+ return true;
1596
+ } catch {
1597
+ return false;
1598
+ }
1599
+ }
1600
+ function computeDelayMs(retries, attempt) {
1601
+ const base = Math.min(retries.maxTimeout, Math.max(retries.minTimeout, retries.minTimeout * retries.factor ** attempt));
1602
+ const jitter = retries.randomize ? 1 + Math.random() : 1;
1603
+ return Math.min(retries.maxTimeout, Math.round(base * jitter));
1604
+ }
1605
+ async function readLockPayload(lockPath) {
1606
+ try {
1607
+ const raw = await fs$1.readFile(lockPath, "utf8");
1608
+ const parsed = JSON.parse(raw);
1609
+ if (typeof parsed.pid !== "number" || typeof parsed.createdAt !== "string") return null;
1610
+ return {
1611
+ pid: parsed.pid,
1612
+ createdAt: parsed.createdAt
1613
+ };
1614
+ } catch {
1615
+ return null;
1616
+ }
1617
+ }
1618
+ async function resolveNormalizedFilePath(filePath) {
1619
+ const resolved = path.resolve(filePath);
1620
+ const dir = path.dirname(resolved);
1621
+ await fs$1.mkdir(dir, { recursive: true });
1622
+ try {
1623
+ const realDir = await fs$1.realpath(dir);
1624
+ return path.join(realDir, path.basename(resolved));
1625
+ } catch {
1626
+ return resolved;
1627
+ }
1628
+ }
1629
+ async function isStaleLock(lockPath, staleMs) {
1630
+ const payload = await readLockPayload(lockPath);
1631
+ if (payload?.pid && !isAlive(payload.pid)) return true;
1632
+ if (payload?.createdAt) {
1633
+ const createdAt = Date.parse(payload.createdAt);
1634
+ if (!Number.isFinite(createdAt) || Date.now() - createdAt > staleMs) return true;
1635
+ }
1636
+ try {
1637
+ const stat = await fs$1.stat(lockPath);
1638
+ return Date.now() - stat.mtimeMs > staleMs;
1639
+ } catch {
1640
+ return true;
1641
+ }
1642
+ }
1643
+ async function acquireFileLock(filePath, options) {
1644
+ const normalizedFile = await resolveNormalizedFilePath(filePath);
1645
+ const lockPath = `${normalizedFile}.lock`;
1646
+ const held = HELD_LOCKS.get(normalizedFile);
1647
+ if (held) {
1648
+ held.count += 1;
1649
+ return {
1650
+ lockPath,
1651
+ release: async () => {
1652
+ const current = HELD_LOCKS.get(normalizedFile);
1653
+ if (!current) return;
1654
+ current.count -= 1;
1655
+ if (current.count > 0) return;
1656
+ HELD_LOCKS.delete(normalizedFile);
1657
+ await current.handle.close().catch(() => void 0);
1658
+ await fs$1.rm(current.lockPath, { force: true }).catch(() => void 0);
1659
+ }
1660
+ };
1661
+ }
1662
+ const attempts = Math.max(1, options.retries.retries + 1);
1663
+ for (let attempt = 0; attempt < attempts; attempt += 1) try {
1664
+ const handle = await fs$1.open(lockPath, "wx");
1665
+ await handle.writeFile(JSON.stringify({
1666
+ pid: process.pid,
1667
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
1668
+ }, null, 2), "utf8");
1669
+ HELD_LOCKS.set(normalizedFile, {
1670
+ count: 1,
1671
+ handle,
1672
+ lockPath
1673
+ });
1674
+ return {
1675
+ lockPath,
1676
+ release: async () => {
1677
+ const current = HELD_LOCKS.get(normalizedFile);
1678
+ if (!current) return;
1679
+ current.count -= 1;
1680
+ if (current.count > 0) return;
1681
+ HELD_LOCKS.delete(normalizedFile);
1682
+ await current.handle.close().catch(() => void 0);
1683
+ await fs$1.rm(current.lockPath, { force: true }).catch(() => void 0);
1684
+ }
1685
+ };
1686
+ } catch (err) {
1687
+ if (err.code !== "EEXIST") throw err;
1688
+ if (await isStaleLock(lockPath, options.stale)) {
1689
+ await fs$1.rm(lockPath, { force: true }).catch(() => void 0);
1690
+ continue;
1691
+ }
1692
+ if (attempt >= attempts - 1) break;
1693
+ await new Promise((resolve) => setTimeout(resolve, computeDelayMs(options.retries, attempt)));
1694
+ }
1695
+ throw new Error(`file lock timeout for ${normalizedFile}`);
1696
+ }
1697
+ async function withFileLock(filePath, options, fn) {
1698
+ const lock = await acquireFileLock(filePath, options);
1699
+ try {
1700
+ return await fn();
1701
+ } finally {
1702
+ await lock.release();
1703
+ }
1704
+ }
1705
+
1706
+ //#endregion
1707
+ //#region src/infra/json-file.ts
1708
+ function loadJsonFile(pathname) {
1709
+ try {
1710
+ if (!fs.existsSync(pathname)) return;
1711
+ const raw = fs.readFileSync(pathname, "utf8");
1712
+ return JSON.parse(raw);
1713
+ } catch {
1714
+ return;
1715
+ }
1716
+ }
1717
+ function saveJsonFile(pathname, data) {
1718
+ const dir = path.dirname(pathname);
1719
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, {
1720
+ recursive: true,
1721
+ mode: 448
1722
+ });
1723
+ fs.writeFileSync(pathname, `${JSON.stringify(data, null, 2)}\n`, "utf8");
1724
+ fs.chmodSync(pathname, 384);
1725
+ }
1726
+
1727
+ //#endregion
1728
+ //#region src/agents/cli-credentials.ts
1729
+ const log = createSubsystemLogger("agents/auth-profiles");
1730
+ const QWEN_CLI_CREDENTIALS_RELATIVE_PATH = ".qwen/oauth_creds.json";
1731
+ const MINIMAX_CLI_CREDENTIALS_RELATIVE_PATH = ".minimax/oauth_creds.json";
1732
+ let qwenCliCache = null;
1733
+ let minimaxCliCache = null;
1734
+ function resolveQwenCliCredentialsPath(homeDir) {
1735
+ const baseDir = homeDir ?? resolveUserPath("~");
1736
+ return path.join(baseDir, QWEN_CLI_CREDENTIALS_RELATIVE_PATH);
1737
+ }
1738
+ function resolveMiniMaxCliCredentialsPath(homeDir) {
1739
+ const baseDir = homeDir ?? resolveUserPath("~");
1740
+ return path.join(baseDir, MINIMAX_CLI_CREDENTIALS_RELATIVE_PATH);
1741
+ }
1742
+ function readQwenCliCredentials(options) {
1743
+ return readPortalCliOauthCredentials(resolveQwenCliCredentialsPath(options?.homeDir), "qwen-portal");
1744
+ }
1745
+ function readPortalCliOauthCredentials(credPath, provider) {
1746
+ const raw = loadJsonFile(credPath);
1747
+ if (!raw || typeof raw !== "object") return null;
1748
+ const data = raw;
1749
+ const accessToken = data.access_token;
1750
+ const refreshToken = data.refresh_token;
1751
+ const expiresAt = data.expiry_date;
1752
+ if (typeof accessToken !== "string" || !accessToken) return null;
1753
+ if (typeof refreshToken !== "string" || !refreshToken) return null;
1754
+ if (typeof expiresAt !== "number" || !Number.isFinite(expiresAt)) return null;
1755
+ return {
1756
+ type: "oauth",
1757
+ provider,
1758
+ access: accessToken,
1759
+ refresh: refreshToken,
1760
+ expires: expiresAt
1761
+ };
1762
+ }
1763
+ function readMiniMaxCliCredentials(options) {
1764
+ return readPortalCliOauthCredentials(resolveMiniMaxCliCredentialsPath(options?.homeDir), "minimax-portal");
1765
+ }
1766
+ function readQwenCliCredentialsCached(options) {
1767
+ const ttlMs = options?.ttlMs ?? 0;
1768
+ const now = Date.now();
1769
+ const cacheKey = resolveQwenCliCredentialsPath(options?.homeDir);
1770
+ if (ttlMs > 0 && qwenCliCache && qwenCliCache.cacheKey === cacheKey && now - qwenCliCache.readAt < ttlMs) return qwenCliCache.value;
1771
+ const value = readQwenCliCredentials({ homeDir: options?.homeDir });
1772
+ if (ttlMs > 0) qwenCliCache = {
1773
+ value,
1774
+ readAt: now,
1775
+ cacheKey
1776
+ };
1777
+ return value;
1778
+ }
1779
+ function readMiniMaxCliCredentialsCached(options) {
1780
+ const ttlMs = options?.ttlMs ?? 0;
1781
+ const now = Date.now();
1782
+ const cacheKey = resolveMiniMaxCliCredentialsPath(options?.homeDir);
1783
+ if (ttlMs > 0 && minimaxCliCache && minimaxCliCache.cacheKey === cacheKey && now - minimaxCliCache.readAt < ttlMs) return minimaxCliCache.value;
1784
+ const value = readMiniMaxCliCredentials({ homeDir: options?.homeDir });
1785
+ if (ttlMs > 0) minimaxCliCache = {
1786
+ value,
1787
+ readAt: now,
1788
+ cacheKey
1789
+ };
1790
+ return value;
1791
+ }
1792
+
1793
+ //#endregion
1794
+ //#region src/agents/auth-profiles/external-cli-sync.ts
1795
+ function shallowEqualOAuthCredentials(a, b) {
1796
+ if (!a) return false;
1797
+ if (a.type !== "oauth") return false;
1798
+ return a.provider === b.provider && a.access === b.access && a.refresh === b.refresh && a.expires === b.expires && a.email === b.email && a.enterpriseUrl === b.enterpriseUrl && a.projectId === b.projectId && a.accountId === b.accountId;
1799
+ }
1800
+ function isExternalProfileFresh(cred, now) {
1801
+ if (!cred) return false;
1802
+ if (cred.type !== "oauth" && cred.type !== "token") return false;
1803
+ if (cred.provider !== "qwen-portal" && cred.provider !== "minimax-portal") return false;
1804
+ if (typeof cred.expires !== "number") return true;
1805
+ return cred.expires > now + EXTERNAL_CLI_NEAR_EXPIRY_MS;
1806
+ }
1807
+ /** Sync external CLI credentials into the store for a given provider. */
1808
+ function syncExternalCliCredentialsForProvider(store, profileId, provider, readCredentials, now) {
1809
+ const existing = store.profiles[profileId];
1810
+ const creds = !existing || existing.provider !== provider || !isExternalProfileFresh(existing, now) ? readCredentials() : null;
1811
+ if (!creds) return false;
1812
+ const existingOAuth = existing?.type === "oauth" ? existing : void 0;
1813
+ if ((!existingOAuth || existingOAuth.provider !== provider || existingOAuth.expires <= now || creds.expires > existingOAuth.expires) && !shallowEqualOAuthCredentials(existingOAuth, creds)) {
1814
+ store.profiles[profileId] = creds;
1815
+ log$1.info(`synced ${provider} credentials from external cli`, {
1816
+ profileId,
1817
+ expires: new Date(creds.expires).toISOString()
1818
+ });
1819
+ return true;
1820
+ }
1821
+ return false;
1822
+ }
1823
+ /**
1824
+ * Sync OAuth credentials from external CLI tools (Qwen Code CLI, MiniMax CLI) into the store.
1825
+ *
1826
+ * Returns true if any credentials were updated.
1827
+ */
1828
+ function syncExternalCliCredentials(store) {
1829
+ let mutated = false;
1830
+ const now = Date.now();
1831
+ const existingQwen = store.profiles[QWEN_CLI_PROFILE_ID];
1832
+ const qwenCreds = !existingQwen || existingQwen.provider !== "qwen-portal" || !isExternalProfileFresh(existingQwen, now) ? readQwenCliCredentialsCached({ ttlMs: EXTERNAL_CLI_SYNC_TTL_MS }) : null;
1833
+ if (qwenCreds) {
1834
+ const existing = store.profiles[QWEN_CLI_PROFILE_ID];
1835
+ const existingOAuth = existing?.type === "oauth" ? existing : void 0;
1836
+ if ((!existingOAuth || existingOAuth.provider !== "qwen-portal" || existingOAuth.expires <= now || qwenCreds.expires > existingOAuth.expires) && !shallowEqualOAuthCredentials(existingOAuth, qwenCreds)) {
1837
+ store.profiles[QWEN_CLI_PROFILE_ID] = qwenCreds;
1838
+ mutated = true;
1839
+ log$1.info("synced qwen credentials from qwen cli", {
1840
+ profileId: QWEN_CLI_PROFILE_ID,
1841
+ expires: new Date(qwenCreds.expires).toISOString()
1842
+ });
1843
+ }
1844
+ }
1845
+ if (syncExternalCliCredentialsForProvider(store, MINIMAX_CLI_PROFILE_ID, "minimax-portal", () => readMiniMaxCliCredentialsCached({ ttlMs: EXTERNAL_CLI_SYNC_TTL_MS }), now)) mutated = true;
1846
+ return mutated;
1847
+ }
1848
+
1849
+ //#endregion
1850
+ //#region src/agents/agent-paths.ts
1851
+ function resolveAnimaAgentDir() {
1852
+ const override = process.env.ANIMA_AGENT_DIR?.trim() || process.env.OPENCLAW_AGENT_DIR?.trim() || process.env.PI_CODING_AGENT_DIR?.trim();
1853
+ if (override) return resolveUserPath(override);
1854
+ return resolveUserPath(path.join(resolveStateDir(), "agents", DEFAULT_AGENT_ID, "agent"));
1855
+ }
1856
+
1857
+ //#endregion
1858
+ //#region src/agents/auth-profiles/paths.ts
1859
+ function resolveAuthStorePath(agentDir) {
1860
+ const resolved = resolveUserPath(agentDir ?? resolveAnimaAgentDir());
1861
+ return path.join(resolved, AUTH_PROFILE_FILENAME);
1862
+ }
1863
+ function resolveLegacyAuthStorePath(agentDir) {
1864
+ const resolved = resolveUserPath(agentDir ?? resolveAnimaAgentDir());
1865
+ return path.join(resolved, LEGACY_AUTH_FILENAME);
1866
+ }
1867
+ function resolveAuthStorePathForDisplay(agentDir) {
1868
+ const pathname = resolveAuthStorePath(agentDir);
1869
+ return pathname.startsWith("~") ? pathname : resolveUserPath(pathname);
1870
+ }
1871
+ function ensureAuthStoreFile(pathname) {
1872
+ if (fs.existsSync(pathname)) return;
1873
+ saveJsonFile(pathname, {
1874
+ version: AUTH_STORE_VERSION,
1875
+ profiles: {}
1876
+ });
1877
+ }
1878
+
1879
+ //#endregion
1880
+ //#region src/agents/auth-profiles/store.ts
1881
+ async function updateAuthProfileStoreWithLock(params) {
1882
+ const authPath = resolveAuthStorePath(params.agentDir);
1883
+ ensureAuthStoreFile(authPath);
1884
+ try {
1885
+ return await withFileLock(authPath, AUTH_STORE_LOCK_OPTIONS, async () => {
1886
+ const store = ensureAuthProfileStore(params.agentDir);
1887
+ if (params.updater(store)) saveAuthProfileStore(store, params.agentDir);
1888
+ return store;
1889
+ });
1890
+ } catch {
1891
+ return null;
1892
+ }
1893
+ }
1894
+ function coerceLegacyStore(raw) {
1895
+ if (!raw || typeof raw !== "object") return null;
1896
+ const record = raw;
1897
+ if ("profiles" in record) return null;
1898
+ const entries = {};
1899
+ for (const [key, value] of Object.entries(record)) {
1900
+ if (!value || typeof value !== "object") continue;
1901
+ const typed = value;
1902
+ if (typed.type !== "api_key" && typed.type !== "oauth" && typed.type !== "token") continue;
1903
+ entries[key] = {
1904
+ ...typed,
1905
+ provider: String(typed.provider ?? key)
1906
+ };
1907
+ }
1908
+ return Object.keys(entries).length > 0 ? entries : null;
1909
+ }
1910
+ function coerceAuthStore(raw) {
1911
+ if (!raw || typeof raw !== "object") return null;
1912
+ const record = raw;
1913
+ if (!record.profiles || typeof record.profiles !== "object") return null;
1914
+ const profiles = record.profiles;
1915
+ const normalized = {};
1916
+ for (const [key, value] of Object.entries(profiles)) {
1917
+ if (!value || typeof value !== "object") continue;
1918
+ const typed = value;
1919
+ if (typed.type !== "api_key" && typed.type !== "oauth" && typed.type !== "token") continue;
1920
+ if (!typed.provider) continue;
1921
+ normalized[key] = typed;
1922
+ }
1923
+ const order = record.order && typeof record.order === "object" ? Object.entries(record.order).reduce((acc, [provider, value]) => {
1924
+ if (!Array.isArray(value)) return acc;
1925
+ const list = value.map((entry) => typeof entry === "string" ? entry.trim() : "").filter(Boolean);
1926
+ if (list.length === 0) return acc;
1927
+ acc[provider] = list;
1928
+ return acc;
1929
+ }, {}) : void 0;
1930
+ return {
1931
+ version: Number(record.version ?? AUTH_STORE_VERSION),
1932
+ profiles: normalized,
1933
+ order,
1934
+ lastGood: record.lastGood && typeof record.lastGood === "object" ? record.lastGood : void 0,
1935
+ usageStats: record.usageStats && typeof record.usageStats === "object" ? record.usageStats : void 0
1936
+ };
1937
+ }
1938
+ function mergeRecord(base, override) {
1939
+ if (!base && !override) return;
1940
+ if (!base) return { ...override };
1941
+ if (!override) return { ...base };
1942
+ return {
1943
+ ...base,
1944
+ ...override
1945
+ };
1946
+ }
1947
+ function mergeAuthProfileStores(base, override) {
1948
+ if (Object.keys(override.profiles).length === 0 && !override.order && !override.lastGood && !override.usageStats) return base;
1949
+ return {
1950
+ version: Math.max(base.version, override.version ?? base.version),
1951
+ profiles: {
1952
+ ...base.profiles,
1953
+ ...override.profiles
1954
+ },
1955
+ order: mergeRecord(base.order, override.order),
1956
+ lastGood: mergeRecord(base.lastGood, override.lastGood),
1957
+ usageStats: mergeRecord(base.usageStats, override.usageStats)
1958
+ };
1959
+ }
1960
+ function mergeOAuthFileIntoStore(store) {
1961
+ const oauthRaw = loadJsonFile(resolveOAuthPath());
1962
+ if (!oauthRaw || typeof oauthRaw !== "object") return false;
1963
+ const oauthEntries = oauthRaw;
1964
+ let mutated = false;
1965
+ for (const [provider, creds] of Object.entries(oauthEntries)) {
1966
+ if (!creds || typeof creds !== "object") continue;
1967
+ const profileId = `${provider}:default`;
1968
+ if (store.profiles[profileId]) continue;
1969
+ store.profiles[profileId] = {
1970
+ type: "oauth",
1971
+ provider,
1972
+ ...creds
1973
+ };
1974
+ mutated = true;
1975
+ }
1976
+ return mutated;
1977
+ }
1978
+ function applyLegacyStore(store, legacy) {
1979
+ for (const [provider, cred] of Object.entries(legacy)) {
1980
+ const profileId = `${provider}:default`;
1981
+ if (cred.type === "api_key") {
1982
+ store.profiles[profileId] = {
1983
+ type: "api_key",
1984
+ provider: String(cred.provider ?? provider),
1985
+ key: cred.key,
1986
+ ...cred.email ? { email: cred.email } : {}
1987
+ };
1988
+ continue;
1989
+ }
1990
+ if (cred.type === "token") {
1991
+ store.profiles[profileId] = {
1992
+ type: "token",
1993
+ provider: String(cred.provider ?? provider),
1994
+ token: cred.token,
1995
+ ...typeof cred.expires === "number" ? { expires: cred.expires } : {},
1996
+ ...cred.email ? { email: cred.email } : {}
1997
+ };
1998
+ continue;
1999
+ }
2000
+ store.profiles[profileId] = {
2001
+ type: "oauth",
2002
+ provider: String(cred.provider ?? provider),
2003
+ access: cred.access,
2004
+ refresh: cred.refresh,
2005
+ expires: cred.expires,
2006
+ ...cred.enterpriseUrl ? { enterpriseUrl: cred.enterpriseUrl } : {},
2007
+ ...cred.projectId ? { projectId: cred.projectId } : {},
2008
+ ...cred.accountId ? { accountId: cred.accountId } : {},
2009
+ ...cred.email ? { email: cred.email } : {}
2010
+ };
2011
+ }
2012
+ }
2013
+ function loadAuthProfileStore() {
2014
+ const authPath = resolveAuthStorePath();
2015
+ const asStore = coerceAuthStore(loadJsonFile(authPath));
2016
+ if (asStore) {
2017
+ if (syncExternalCliCredentials(asStore)) saveJsonFile(authPath, asStore);
2018
+ return asStore;
2019
+ }
2020
+ const legacy = coerceLegacyStore(loadJsonFile(resolveLegacyAuthStorePath()));
2021
+ if (legacy) {
2022
+ const store = {
2023
+ version: AUTH_STORE_VERSION,
2024
+ profiles: {}
2025
+ };
2026
+ applyLegacyStore(store, legacy);
2027
+ syncExternalCliCredentials(store);
2028
+ return store;
2029
+ }
2030
+ const store = {
2031
+ version: AUTH_STORE_VERSION,
2032
+ profiles: {}
2033
+ };
2034
+ syncExternalCliCredentials(store);
2035
+ return store;
2036
+ }
2037
+ function loadAuthProfileStoreForAgent(agentDir, _options) {
2038
+ const authPath = resolveAuthStorePath(agentDir);
2039
+ const asStore = coerceAuthStore(loadJsonFile(authPath));
2040
+ if (asStore) {
2041
+ if (syncExternalCliCredentials(asStore)) saveJsonFile(authPath, asStore);
2042
+ return asStore;
2043
+ }
2044
+ if (agentDir) {
2045
+ const mainStore = coerceAuthStore(loadJsonFile(resolveAuthStorePath()));
2046
+ if (mainStore && Object.keys(mainStore.profiles).length > 0) {
2047
+ saveJsonFile(authPath, mainStore);
2048
+ log$1.info("inherited auth-profiles from main agent", { agentDir });
2049
+ return mainStore;
2050
+ }
2051
+ }
2052
+ const legacy = coerceLegacyStore(loadJsonFile(resolveLegacyAuthStorePath(agentDir)));
2053
+ const store = {
2054
+ version: AUTH_STORE_VERSION,
2055
+ profiles: {}
2056
+ };
2057
+ if (legacy) applyLegacyStore(store, legacy);
2058
+ const mergedOAuth = mergeOAuthFileIntoStore(store);
2059
+ const syncedCli = syncExternalCliCredentials(store);
2060
+ const shouldWrite = legacy !== null || mergedOAuth || syncedCli;
2061
+ if (shouldWrite) saveJsonFile(authPath, store);
2062
+ if (shouldWrite && legacy !== null) {
2063
+ const legacyPath = resolveLegacyAuthStorePath(agentDir);
2064
+ try {
2065
+ fs.unlinkSync(legacyPath);
2066
+ } catch (err) {
2067
+ if (err?.code !== "ENOENT") log$1.warn("failed to delete legacy auth.json after migration", {
2068
+ err,
2069
+ legacyPath
2070
+ });
2071
+ }
2072
+ }
2073
+ return store;
2074
+ }
2075
+ function ensureAuthProfileStore(agentDir, options) {
2076
+ const store = loadAuthProfileStoreForAgent(agentDir, options);
2077
+ const authPath = resolveAuthStorePath(agentDir);
2078
+ const mainAuthPath = resolveAuthStorePath();
2079
+ if (!agentDir || authPath === mainAuthPath) return store;
2080
+ return mergeAuthProfileStores(loadAuthProfileStoreForAgent(void 0, options), store);
2081
+ }
2082
+ function saveAuthProfileStore(store, agentDir) {
2083
+ saveJsonFile(resolveAuthStorePath(agentDir), {
2084
+ version: AUTH_STORE_VERSION,
2085
+ profiles: store.profiles,
2086
+ order: store.order ?? void 0,
2087
+ lastGood: store.lastGood ?? void 0,
2088
+ usageStats: store.usageStats ?? void 0
2089
+ });
2090
+ }
2091
+
2092
+ //#endregion
2093
+ //#region src/agents/auth-profiles/profiles.ts
2094
+ async function setAuthProfileOrder(params) {
2095
+ const providerKey = normalizeProviderId(params.provider);
2096
+ const sanitized = params.order && Array.isArray(params.order) ? params.order.map((entry) => String(entry).trim()).filter(Boolean) : [];
2097
+ const deduped = [];
2098
+ for (const entry of sanitized) if (!deduped.includes(entry)) deduped.push(entry);
2099
+ return await updateAuthProfileStoreWithLock({
2100
+ agentDir: params.agentDir,
2101
+ updater: (store) => {
2102
+ store.order = store.order ?? {};
2103
+ if (deduped.length === 0) {
2104
+ if (!store.order[providerKey]) return false;
2105
+ delete store.order[providerKey];
2106
+ if (Object.keys(store.order).length === 0) store.order = void 0;
2107
+ return true;
2108
+ }
2109
+ store.order[providerKey] = deduped;
2110
+ return true;
2111
+ }
2112
+ });
2113
+ }
2114
+ function upsertAuthProfile(params) {
2115
+ const credential = params.credential.type === "api_key" ? {
2116
+ ...params.credential,
2117
+ ...typeof params.credential.key === "string" ? { key: normalizeSecretInput(params.credential.key) } : {}
2118
+ } : params.credential.type === "token" ? {
2119
+ ...params.credential,
2120
+ token: normalizeSecretInput(params.credential.token)
2121
+ } : params.credential;
2122
+ const store = ensureAuthProfileStore(params.agentDir);
2123
+ store.profiles[params.profileId] = credential;
2124
+ saveAuthProfileStore(store, params.agentDir);
2125
+ }
2126
+ async function upsertAuthProfileWithLock(params) {
2127
+ return await updateAuthProfileStoreWithLock({
2128
+ agentDir: params.agentDir,
2129
+ updater: (store) => {
2130
+ store.profiles[params.profileId] = params.credential;
2131
+ return true;
2132
+ }
2133
+ });
2134
+ }
2135
+ function listProfilesForProvider(store, provider) {
2136
+ const providerKey = normalizeProviderId(provider);
2137
+ return Object.entries(store.profiles).filter(([, cred]) => normalizeProviderId(cred.provider) === providerKey).map(([id]) => id);
2138
+ }
2139
+
2140
+ //#endregion
2141
+ //#region src/agents/auth-profiles/repair.ts
2142
+ function getProfileSuffix(profileId) {
2143
+ const idx = profileId.indexOf(":");
2144
+ if (idx < 0) return "";
2145
+ return profileId.slice(idx + 1);
2146
+ }
2147
+ function isEmailLike(value) {
2148
+ const trimmed = value.trim();
2149
+ if (!trimmed) return false;
2150
+ return trimmed.includes("@") && trimmed.includes(".");
2151
+ }
2152
+ function suggestOAuthProfileIdForLegacyDefault(params) {
2153
+ const providerKey = normalizeProviderId(params.provider);
2154
+ if (getProfileSuffix(params.legacyProfileId) !== "default") return null;
2155
+ const legacyCfg = params.cfg?.auth?.profiles?.[params.legacyProfileId];
2156
+ if (legacyCfg && normalizeProviderId(legacyCfg.provider) === providerKey && legacyCfg.mode !== "oauth") return null;
2157
+ const oauthProfiles = listProfilesForProvider(params.store, providerKey).filter((id) => params.store.profiles[id]?.type === "oauth");
2158
+ if (oauthProfiles.length === 0) return null;
2159
+ const configuredEmail = legacyCfg?.email?.trim();
2160
+ if (configuredEmail) {
2161
+ const byEmail = oauthProfiles.find((id) => {
2162
+ const cred = params.store.profiles[id];
2163
+ if (!cred || cred.type !== "oauth") return false;
2164
+ return cred.email?.trim() === configuredEmail || id === `${providerKey}:${configuredEmail}`;
2165
+ });
2166
+ if (byEmail) return byEmail;
2167
+ }
2168
+ const lastGood = params.store.lastGood?.[providerKey] ?? params.store.lastGood?.[params.provider];
2169
+ if (lastGood && oauthProfiles.includes(lastGood)) return lastGood;
2170
+ const nonLegacy = oauthProfiles.filter((id) => id !== params.legacyProfileId);
2171
+ if (nonLegacy.length === 1) return nonLegacy[0] ?? null;
2172
+ const emailLike = nonLegacy.filter((id) => isEmailLike(getProfileSuffix(id)));
2173
+ if (emailLike.length === 1) return emailLike[0] ?? null;
2174
+ return null;
2175
+ }
2176
+ function repairOAuthProfileIdMismatch(params) {
2177
+ const legacyProfileId = params.legacyProfileId ?? `${normalizeProviderId(params.provider)}:default`;
2178
+ const legacyCfg = params.cfg.auth?.profiles?.[legacyProfileId];
2179
+ if (!legacyCfg) return {
2180
+ config: params.cfg,
2181
+ changes: [],
2182
+ migrated: false
2183
+ };
2184
+ if (legacyCfg.mode !== "oauth") return {
2185
+ config: params.cfg,
2186
+ changes: [],
2187
+ migrated: false
2188
+ };
2189
+ if (normalizeProviderId(legacyCfg.provider) !== normalizeProviderId(params.provider)) return {
2190
+ config: params.cfg,
2191
+ changes: [],
2192
+ migrated: false
2193
+ };
2194
+ const toProfileId = suggestOAuthProfileIdForLegacyDefault({
2195
+ cfg: params.cfg,
2196
+ store: params.store,
2197
+ provider: params.provider,
2198
+ legacyProfileId
2199
+ });
2200
+ if (!toProfileId || toProfileId === legacyProfileId) return {
2201
+ config: params.cfg,
2202
+ changes: [],
2203
+ migrated: false
2204
+ };
2205
+ const toCred = params.store.profiles[toProfileId];
2206
+ const toEmail = toCred?.type === "oauth" ? toCred.email?.trim() : void 0;
2207
+ const nextProfiles = { ...params.cfg.auth?.profiles };
2208
+ delete nextProfiles[legacyProfileId];
2209
+ nextProfiles[toProfileId] = {
2210
+ ...legacyCfg,
2211
+ ...toEmail ? { email: toEmail } : {}
2212
+ };
2213
+ const providerKey = normalizeProviderId(params.provider);
2214
+ const nextOrder = (() => {
2215
+ const order = params.cfg.auth?.order;
2216
+ if (!order) return;
2217
+ const resolvedKey = Object.keys(order).find((key) => normalizeProviderId(key) === providerKey);
2218
+ if (!resolvedKey) return order;
2219
+ const existing = order[resolvedKey];
2220
+ if (!Array.isArray(existing)) return order;
2221
+ const replaced = existing.map((id) => id === legacyProfileId ? toProfileId : id).filter((id) => typeof id === "string" && id.trim().length > 0);
2222
+ const deduped = [];
2223
+ for (const entry of replaced) if (!deduped.includes(entry)) deduped.push(entry);
2224
+ return {
2225
+ ...order,
2226
+ [resolvedKey]: deduped
2227
+ };
2228
+ })();
2229
+ return {
2230
+ config: {
2231
+ ...params.cfg,
2232
+ auth: {
2233
+ ...params.cfg.auth,
2234
+ profiles: nextProfiles,
2235
+ ...nextOrder ? { order: nextOrder } : {}
2236
+ }
2237
+ },
2238
+ changes: [`Auth: migrate ${legacyProfileId} → ${toProfileId} (OAuth profile id)`],
2239
+ migrated: true,
2240
+ fromProfileId: legacyProfileId,
2241
+ toProfileId
2242
+ };
2243
+ }
2244
+
2245
+ //#endregion
2246
+ //#region src/agents/auth-profiles/doctor.ts
2247
+ function formatAuthDoctorHint(params) {
2248
+ const providerKey = normalizeProviderId(params.provider);
2249
+ if (providerKey !== "anthropic") return "";
2250
+ const legacyProfileId = params.profileId ?? "anthropic:default";
2251
+ const suggested = suggestOAuthProfileIdForLegacyDefault({
2252
+ cfg: params.cfg,
2253
+ store: params.store,
2254
+ provider: providerKey,
2255
+ legacyProfileId
2256
+ });
2257
+ if (!suggested || suggested === legacyProfileId) return "";
2258
+ const storeOauthProfiles = listProfilesForProvider(params.store, providerKey).filter((id) => params.store.profiles[id]?.type === "oauth").join(", ");
2259
+ const cfgMode = params.cfg?.auth?.profiles?.[legacyProfileId]?.mode;
2260
+ const cfgProvider = params.cfg?.auth?.profiles?.[legacyProfileId]?.provider;
2261
+ return [
2262
+ "Doctor hint (for GitHub issue):",
2263
+ `- provider: ${providerKey}`,
2264
+ `- config: ${legacyProfileId}${cfgProvider || cfgMode ? ` (provider=${cfgProvider ?? "?"}, mode=${cfgMode ?? "?"})` : ""}`,
2265
+ `- auth store oauth profiles: ${storeOauthProfiles || "(none)"}`,
2266
+ `- suggested profile: ${suggested}`,
2267
+ `Fix: run "${formatCliCommand("anima doctor --yes")}"`
2268
+ ].join("\n");
2269
+ }
2270
+
2271
+ //#endregion
2272
+ //#region src/providers/qwen-portal-oauth.ts
2273
+ async function refreshQwenPortalCredentials(_opts) {
2274
+ return null;
2275
+ }
2276
+
2277
+ //#endregion
2278
+ //#region src/agents/chutes-oauth.ts
2279
+ const CHUTES_OAUTH_ISSUER = "https://api.chutes.ai";
2280
+ const CHUTES_AUTHORIZE_ENDPOINT = `${CHUTES_OAUTH_ISSUER}/idp/authorize`;
2281
+ const CHUTES_TOKEN_ENDPOINT = `${CHUTES_OAUTH_ISSUER}/idp/token`;
2282
+ const CHUTES_USERINFO_ENDPOINT = `${CHUTES_OAUTH_ISSUER}/idp/userinfo`;
2283
+ const DEFAULT_EXPIRES_BUFFER_MS = 300 * 1e3;
2284
+ function generateChutesPkce() {
2285
+ const verifier = randomBytes(32).toString("hex");
2286
+ return {
2287
+ verifier,
2288
+ challenge: createHash("sha256").update(verifier).digest("base64url")
2289
+ };
2290
+ }
2291
+ function parseOAuthCallbackInput(input, expectedState) {
2292
+ const trimmed = input.trim();
2293
+ if (!trimmed) return { error: "No input provided" };
2294
+ let url;
2295
+ try {
2296
+ url = new URL(trimmed);
2297
+ } catch {
2298
+ if (!/\s/.test(trimmed) && !trimmed.includes("://") && !trimmed.includes("?") && !trimmed.includes("=")) return { error: "Paste the full redirect URL (must include code + state)." };
2299
+ const qs = trimmed.startsWith("?") ? trimmed : `?${trimmed}`;
2300
+ try {
2301
+ url = new URL(`http://localhost/${qs}`);
2302
+ } catch {
2303
+ return { error: "Paste the full redirect URL (must include code + state)." };
2304
+ }
2305
+ }
2306
+ const code = url.searchParams.get("code")?.trim();
2307
+ const state = url.searchParams.get("state")?.trim();
2308
+ if (!code) return { error: "Missing 'code' parameter in URL" };
2309
+ if (!state) return { error: "Missing 'state' parameter. Paste the full redirect URL." };
2310
+ if (state !== expectedState) return { error: "OAuth state mismatch - possible CSRF attack. Please retry login." };
2311
+ return {
2312
+ code,
2313
+ state
2314
+ };
2315
+ }
2316
+ function coerceExpiresAt(expiresInSeconds, now) {
2317
+ const value = now + Math.max(0, Math.floor(expiresInSeconds)) * 1e3 - DEFAULT_EXPIRES_BUFFER_MS;
2318
+ return Math.max(value, now + 3e4);
2319
+ }
2320
+ async function fetchChutesUserInfo(params) {
2321
+ const response = await (params.fetchFn ?? fetch)(CHUTES_USERINFO_ENDPOINT, { headers: { Authorization: `Bearer ${params.accessToken}` } });
2322
+ if (!response.ok) return null;
2323
+ const data = await response.json();
2324
+ if (!data || typeof data !== "object") return null;
2325
+ return data;
2326
+ }
2327
+ async function exchangeChutesCodeForTokens(params) {
2328
+ const fetchFn = params.fetchFn ?? fetch;
2329
+ const now = params.now ?? Date.now();
2330
+ const body = new URLSearchParams({
2331
+ grant_type: "authorization_code",
2332
+ client_id: params.app.clientId,
2333
+ code: params.code,
2334
+ redirect_uri: params.app.redirectUri,
2335
+ code_verifier: params.codeVerifier
2336
+ });
2337
+ if (params.app.clientSecret) body.set("client_secret", params.app.clientSecret);
2338
+ const response = await fetchFn(CHUTES_TOKEN_ENDPOINT, {
2339
+ method: "POST",
2340
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
2341
+ body
2342
+ });
2343
+ if (!response.ok) {
2344
+ const text = await response.text();
2345
+ throw new Error(`Chutes token exchange failed: ${text}`);
2346
+ }
2347
+ const data = await response.json();
2348
+ const access = data.access_token?.trim();
2349
+ const refresh = data.refresh_token?.trim();
2350
+ const expiresIn = data.expires_in ?? 0;
2351
+ if (!access) throw new Error("Chutes token exchange returned no access_token");
2352
+ if (!refresh) throw new Error("Chutes token exchange returned no refresh_token");
2353
+ const info = await fetchChutesUserInfo({
2354
+ accessToken: access,
2355
+ fetchFn
2356
+ });
2357
+ return {
2358
+ access,
2359
+ refresh,
2360
+ expires: coerceExpiresAt(expiresIn, now),
2361
+ email: info?.username,
2362
+ accountId: info?.sub,
2363
+ clientId: params.app.clientId
2364
+ };
2365
+ }
2366
+ async function refreshChutesTokens(params) {
2367
+ const fetchFn = params.fetchFn ?? fetch;
2368
+ const now = params.now ?? Date.now();
2369
+ const refreshToken = params.credential.refresh?.trim();
2370
+ if (!refreshToken) throw new Error("Chutes OAuth credential is missing refresh token");
2371
+ const clientId = params.credential.clientId?.trim() ?? process.env.CHUTES_CLIENT_ID?.trim();
2372
+ if (!clientId) throw new Error("Missing CHUTES_CLIENT_ID for Chutes OAuth refresh (set env var or re-auth).");
2373
+ const clientSecret = process.env.CHUTES_CLIENT_SECRET?.trim() || void 0;
2374
+ const body = new URLSearchParams({
2375
+ grant_type: "refresh_token",
2376
+ client_id: clientId,
2377
+ refresh_token: refreshToken
2378
+ });
2379
+ if (clientSecret) body.set("client_secret", clientSecret);
2380
+ const response = await fetchFn(CHUTES_TOKEN_ENDPOINT, {
2381
+ method: "POST",
2382
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
2383
+ body
2384
+ });
2385
+ if (!response.ok) {
2386
+ const text = await response.text();
2387
+ throw new Error(`Chutes token refresh failed: ${text}`);
2388
+ }
2389
+ const data = await response.json();
2390
+ const access = data.access_token?.trim();
2391
+ const newRefresh = data.refresh_token?.trim();
2392
+ const expiresIn = data.expires_in ?? 0;
2393
+ if (!access) throw new Error("Chutes token refresh returned no access_token");
2394
+ return {
2395
+ ...params.credential,
2396
+ access,
2397
+ refresh: newRefresh || refreshToken,
2398
+ expires: coerceExpiresAt(expiresIn, now),
2399
+ clientId
2400
+ };
2401
+ }
2402
+
2403
+ //#endregion
2404
+ //#region src/agents/auth-profiles/oauth.ts
2405
+ const OAUTH_PROVIDER_IDS = new Set(getOAuthProviders().map((provider) => provider.id));
2406
+ const isOAuthProvider = (provider) => OAUTH_PROVIDER_IDS.has(provider);
2407
+ const resolveOAuthProvider = (provider) => isOAuthProvider(provider) ? provider : null;
2408
+ function buildOAuthApiKey(provider, credentials) {
2409
+ return provider === "google-gemini-cli" || provider === "google-antigravity" ? JSON.stringify({
2410
+ token: credentials.access,
2411
+ projectId: credentials.projectId
2412
+ }) : credentials.access;
2413
+ }
2414
+ async function refreshOAuthTokenWithLock(params) {
2415
+ const authPath = resolveAuthStorePath(params.agentDir);
2416
+ ensureAuthStoreFile(authPath);
2417
+ return await withFileLock(authPath, AUTH_STORE_LOCK_OPTIONS, async () => {
2418
+ const store = ensureAuthProfileStore(params.agentDir);
2419
+ const cred = store.profiles[params.profileId];
2420
+ if (!cred || cred.type !== "oauth") return null;
2421
+ if (Date.now() < cred.expires) return {
2422
+ apiKey: buildOAuthApiKey(cred.provider, cred),
2423
+ newCredentials: cred
2424
+ };
2425
+ const oauthCreds = { [cred.provider]: cred };
2426
+ const result = String(cred.provider) === "chutes" ? await (async () => {
2427
+ const newCredentials = await refreshChutesTokens({ credential: cred });
2428
+ return {
2429
+ apiKey: newCredentials.access,
2430
+ newCredentials
2431
+ };
2432
+ })() : String(cred.provider) === "qwen-portal" ? await (async () => {
2433
+ const newCredentials = await refreshQwenPortalCredentials(cred);
2434
+ return {
2435
+ apiKey: newCredentials.access,
2436
+ newCredentials
2437
+ };
2438
+ })() : await (async () => {
2439
+ const oauthProvider = resolveOAuthProvider(cred.provider);
2440
+ if (!oauthProvider) return null;
2441
+ return await getOAuthApiKey(oauthProvider, oauthCreds);
2442
+ })();
2443
+ if (!result) return null;
2444
+ store.profiles[params.profileId] = {
2445
+ ...cred,
2446
+ ...result.newCredentials,
2447
+ type: "oauth"
2448
+ };
2449
+ saveAuthProfileStore(store, params.agentDir);
2450
+ return result;
2451
+ });
2452
+ }
2453
+ async function tryResolveOAuthProfile(params) {
2454
+ const { cfg, store, profileId } = params;
2455
+ const cred = store.profiles[profileId];
2456
+ if (!cred || cred.type !== "oauth") return null;
2457
+ const profileConfig = cfg?.auth?.profiles?.[profileId];
2458
+ if (profileConfig && profileConfig.provider !== cred.provider) return null;
2459
+ if (profileConfig && profileConfig.mode !== cred.type) return null;
2460
+ if (Date.now() < cred.expires) return {
2461
+ apiKey: buildOAuthApiKey(cred.provider, cred),
2462
+ provider: cred.provider,
2463
+ email: cred.email
2464
+ };
2465
+ const refreshed = await refreshOAuthTokenWithLock({
2466
+ profileId,
2467
+ agentDir: params.agentDir
2468
+ });
2469
+ if (!refreshed) return null;
2470
+ return {
2471
+ apiKey: refreshed.apiKey,
2472
+ provider: cred.provider,
2473
+ email: cred.email
2474
+ };
2475
+ }
2476
+ async function resolveApiKeyForProfile(params) {
2477
+ const { cfg, store, profileId } = params;
2478
+ const cred = store.profiles[profileId];
2479
+ if (!cred) return null;
2480
+ const profileConfig = cfg?.auth?.profiles?.[profileId];
2481
+ if (profileConfig && profileConfig.provider !== cred.provider) return null;
2482
+ if (profileConfig && profileConfig.mode !== cred.type) {
2483
+ if (!(profileConfig.mode === "oauth" && cred.type === "token")) return null;
2484
+ }
2485
+ if (cred.type === "api_key") {
2486
+ const key = cred.key?.trim();
2487
+ if (!key) return null;
2488
+ return {
2489
+ apiKey: key,
2490
+ provider: cred.provider,
2491
+ email: cred.email
2492
+ };
2493
+ }
2494
+ if (cred.type === "token") {
2495
+ const token = cred.token?.trim();
2496
+ if (!token) return null;
2497
+ if (typeof cred.expires === "number" && Number.isFinite(cred.expires) && cred.expires > 0 && Date.now() >= cred.expires) return null;
2498
+ return {
2499
+ apiKey: token,
2500
+ provider: cred.provider,
2501
+ email: cred.email
2502
+ };
2503
+ }
2504
+ if (Date.now() < cred.expires) return {
2505
+ apiKey: buildOAuthApiKey(cred.provider, cred),
2506
+ provider: cred.provider,
2507
+ email: cred.email
2508
+ };
2509
+ try {
2510
+ const result = await refreshOAuthTokenWithLock({
2511
+ profileId,
2512
+ agentDir: params.agentDir
2513
+ });
2514
+ if (!result) return null;
2515
+ return {
2516
+ apiKey: result.apiKey,
2517
+ provider: cred.provider,
2518
+ email: cred.email
2519
+ };
2520
+ } catch (error) {
2521
+ const refreshedStore = ensureAuthProfileStore(params.agentDir);
2522
+ const refreshed = refreshedStore.profiles[profileId];
2523
+ if (refreshed?.type === "oauth" && Date.now() < refreshed.expires) return {
2524
+ apiKey: buildOAuthApiKey(refreshed.provider, refreshed),
2525
+ provider: refreshed.provider,
2526
+ email: refreshed.email ?? cred.email
2527
+ };
2528
+ const fallbackProfileId = suggestOAuthProfileIdForLegacyDefault({
2529
+ cfg,
2530
+ store: refreshedStore,
2531
+ provider: cred.provider,
2532
+ legacyProfileId: profileId
2533
+ });
2534
+ if (fallbackProfileId && fallbackProfileId !== profileId) try {
2535
+ const fallbackResolved = await tryResolveOAuthProfile({
2536
+ cfg,
2537
+ store: refreshedStore,
2538
+ profileId: fallbackProfileId,
2539
+ agentDir: params.agentDir
2540
+ });
2541
+ if (fallbackResolved) return fallbackResolved;
2542
+ } catch {}
2543
+ if (params.agentDir) try {
2544
+ const mainCred = ensureAuthProfileStore(void 0).profiles[profileId];
2545
+ if (mainCred?.type === "oauth" && Date.now() < mainCred.expires) {
2546
+ refreshedStore.profiles[profileId] = { ...mainCred };
2547
+ saveAuthProfileStore(refreshedStore, params.agentDir);
2548
+ log$1.info("inherited fresh OAuth credentials from main agent", {
2549
+ profileId,
2550
+ agentDir: params.agentDir,
2551
+ expires: new Date(mainCred.expires).toISOString()
2552
+ });
2553
+ return {
2554
+ apiKey: buildOAuthApiKey(mainCred.provider, mainCred),
2555
+ provider: mainCred.provider,
2556
+ email: mainCred.email
2557
+ };
2558
+ }
2559
+ } catch {}
2560
+ const message = error instanceof Error ? error.message : String(error);
2561
+ const hint = formatAuthDoctorHint({
2562
+ cfg,
2563
+ store: refreshedStore,
2564
+ provider: cred.provider,
2565
+ profileId
2566
+ });
2567
+ throw new Error(`OAuth token refresh failed for ${cred.provider}: ${message}. Please try again or re-authenticate.` + (hint ? `\n\n${hint}` : ""), { cause: error });
2568
+ }
2569
+ }
2570
+
2571
+ //#endregion
2572
+ //#region src/agents/auth-profiles/usage.ts
2573
+ function resolveProfileUnusableUntil$1(stats) {
2574
+ const values = [stats.cooldownUntil, stats.disabledUntil].filter((value) => typeof value === "number").filter((value) => Number.isFinite(value) && value > 0);
2575
+ if (values.length === 0) return null;
2576
+ return Math.max(...values);
2577
+ }
2578
+ /**
2579
+ * Check if a profile is currently in cooldown (due to rate limiting or errors).
2580
+ */
2581
+ function isProfileInCooldown(store, profileId) {
2582
+ const stats = store.usageStats?.[profileId];
2583
+ if (!stats) return false;
2584
+ const unusableUntil = resolveProfileUnusableUntil$1(stats);
2585
+ return unusableUntil ? Date.now() < unusableUntil : false;
2586
+ }
2587
+ function resolveProfileUnusableUntilForDisplay(store, profileId) {
2588
+ const stats = store.usageStats?.[profileId];
2589
+ if (!stats) return null;
2590
+ return resolveProfileUnusableUntil$1(stats);
2591
+ }
2592
+
2593
+ //#endregion
2594
+ //#region src/agents/auth-profiles/order.ts
2595
+ function resolveProfileUnusableUntil(stats) {
2596
+ const values = [stats.cooldownUntil, stats.disabledUntil].filter((value) => typeof value === "number").filter((value) => Number.isFinite(value) && value > 0);
2597
+ if (values.length === 0) return null;
2598
+ return Math.max(...values);
2599
+ }
2600
+ function resolveAuthProfileOrder(params) {
2601
+ const { cfg, store, provider, preferredProfile } = params;
2602
+ const providerKey = normalizeProviderId(provider);
2603
+ const now = Date.now();
2604
+ const storedOrder = (() => {
2605
+ const order = store.order;
2606
+ if (!order) return;
2607
+ for (const [key, value] of Object.entries(order)) if (normalizeProviderId(key) === providerKey) return value;
2608
+ })();
2609
+ const configuredOrder = (() => {
2610
+ const order = cfg?.auth?.order;
2611
+ if (!order) return;
2612
+ for (const [key, value] of Object.entries(order)) if (normalizeProviderId(key) === providerKey) return value;
2613
+ })();
2614
+ const explicitOrder = storedOrder ?? configuredOrder;
2615
+ const explicitProfiles = cfg?.auth?.profiles ? Object.entries(cfg.auth.profiles).filter(([, profile]) => normalizeProviderId(profile.provider) === providerKey).map(([profileId]) => profileId) : [];
2616
+ const baseOrder = explicitOrder ?? (explicitProfiles.length > 0 ? explicitProfiles : listProfilesForProvider(store, providerKey));
2617
+ if (baseOrder.length === 0) return [];
2618
+ const filtered = baseOrder.filter((profileId) => {
2619
+ const cred = store.profiles[profileId];
2620
+ if (!cred) return false;
2621
+ if (normalizeProviderId(cred.provider) !== providerKey) return false;
2622
+ const profileConfig = cfg?.auth?.profiles?.[profileId];
2623
+ if (profileConfig) {
2624
+ if (normalizeProviderId(profileConfig.provider) !== providerKey) return false;
2625
+ if (profileConfig.mode !== cred.type) {
2626
+ if (!(profileConfig.mode === "oauth" && cred.type === "token")) return false;
2627
+ }
2628
+ }
2629
+ if (cred.type === "api_key") return Boolean(cred.key?.trim());
2630
+ if (cred.type === "token") {
2631
+ if (!cred.token?.trim()) return false;
2632
+ if (typeof cred.expires === "number" && Number.isFinite(cred.expires) && cred.expires > 0 && now >= cred.expires) return false;
2633
+ return true;
2634
+ }
2635
+ if (cred.type === "oauth") return Boolean(cred.access?.trim() || cred.refresh?.trim());
2636
+ return false;
2637
+ });
2638
+ const deduped = [];
2639
+ for (const entry of filtered) if (!deduped.includes(entry)) deduped.push(entry);
2640
+ if (explicitOrder && explicitOrder.length > 0) {
2641
+ const available = [];
2642
+ const inCooldown = [];
2643
+ for (const profileId of deduped) {
2644
+ const cooldownUntil = resolveProfileUnusableUntil(store.usageStats?.[profileId] ?? {}) ?? 0;
2645
+ if (typeof cooldownUntil === "number" && Number.isFinite(cooldownUntil) && cooldownUntil > 0 && now < cooldownUntil) inCooldown.push({
2646
+ profileId,
2647
+ cooldownUntil
2648
+ });
2649
+ else available.push(profileId);
2650
+ }
2651
+ const cooldownSorted = inCooldown.toSorted((a, b) => a.cooldownUntil - b.cooldownUntil).map((entry) => entry.profileId);
2652
+ const ordered = [...available, ...cooldownSorted];
2653
+ if (preferredProfile && ordered.includes(preferredProfile)) return [preferredProfile, ...ordered.filter((e) => e !== preferredProfile)];
2654
+ return ordered;
2655
+ }
2656
+ const sorted = orderProfilesByMode(deduped, store);
2657
+ if (preferredProfile && sorted.includes(preferredProfile)) return [preferredProfile, ...sorted.filter((e) => e !== preferredProfile)];
2658
+ return sorted;
2659
+ }
2660
+ function orderProfilesByMode(order, store) {
2661
+ const now = Date.now();
2662
+ const available = [];
2663
+ const inCooldown = [];
2664
+ for (const profileId of order) if (isProfileInCooldown(store, profileId)) inCooldown.push(profileId);
2665
+ else available.push(profileId);
2666
+ const sorted = available.map((profileId) => {
2667
+ const type = store.profiles[profileId]?.type;
2668
+ return {
2669
+ profileId,
2670
+ typeScore: type === "oauth" ? 0 : type === "token" ? 1 : type === "api_key" ? 2 : 3,
2671
+ lastUsed: store.usageStats?.[profileId]?.lastUsed ?? 0
2672
+ };
2673
+ }).toSorted((a, b) => {
2674
+ if (a.typeScore !== b.typeScore) return a.typeScore - b.typeScore;
2675
+ return a.lastUsed - b.lastUsed;
2676
+ }).map((entry) => entry.profileId);
2677
+ const cooldownSorted = inCooldown.map((profileId) => ({
2678
+ profileId,
2679
+ cooldownUntil: resolveProfileUnusableUntil(store.usageStats?.[profileId] ?? {}) ?? now
2680
+ })).toSorted((a, b) => a.cooldownUntil - b.cooldownUntil).map((entry) => entry.profileId);
2681
+ return [...sorted, ...cooldownSorted];
2682
+ }
2683
+
2684
+ //#endregion
2685
+ //#region src/agents/auth-profiles.ts
2686
+ var auth_profiles_exports = /* @__PURE__ */ __exportAll({ ensureAuthProfileStore: () => ensureAuthProfileStore });
2687
+
2688
+ //#endregion
2689
+ export { SYNTHETIC_DEFAULT_MODEL_REF as $, normalizeModelRef as A, CODEX_CLI_PROFILE_ID as At, QIANFAN_BASE_URL as B, withFileLock as C, buildCloudflareAiGatewayModelDefinition as Ct, getModelRefStatus as D, DEFAULT_PROVIDER as Dt, buildModelAliasIndex as E, DEFAULT_MODEL as Et, resolveConfiguredModelRef as F, VENICE_BASE_URL as G, XIAOMI_DEFAULT_MODEL_ID as H, resolveDefaultModelForAgent as I, buildVeniceModelDefinition as J, VENICE_DEFAULT_MODEL_REF as K, resolveHooksGmailModel as L, parseModelRef as M, resolveAllowedModelRef as N, isCliProvider as O, resolveAuthProfileDisplayLabel as Ot, resolveAllowlistModelKey as P, SYNTHETIC_BASE_URL as Q, resolveModelRefFromString as R, saveJsonFile as S, CLOUDFLARE_AI_GATEWAY_DEFAULT_MODEL_REF as St, buildConfiguredAllowlistKeys as T, DEFAULT_CONTEXT_TOKENS as Tt, buildQianfanProvider as U, QIANFAN_DEFAULT_MODEL_ID as V, buildXiaomiProvider as W, TOGETHER_MODEL_CATALOG as X, TOGETHER_BASE_URL as Y, buildTogetherModelDefinition as Z, updateAuthProfileStoreWithLock as _, HUGGINGFACE_BASE_URL as _t, resolveApiKeyForProfile as a, resolveApiKeyForProvider as at, resolveAnimaAgentDir as b, discoverHuggingfaceModels as bt, generateChutesPkce as c, resolveModelAuthMode as ct, listProfilesForProvider as d, getShellEnvAppliedKeys as dt, SYNTHETIC_MODEL_CATALOG as et, setAuthProfileOrder as f, getShellPathFromLoginShell as ft, loadAuthProfileStore as g, shouldEnableShellEnvFallback as gt, ensureAuthProfileStore as h, shouldDeferShellEnvFallback as ht, resolveProfileUnusableUntilForDisplay as i, requireApiKey as it, normalizeProviderId as j, modelKey as k, CLAUDE_CLI_PROFILE_ID as kt, parseOAuthCallbackInput as l, normalizeOptionalSecretInput as lt, upsertAuthProfileWithLock as m, resolveShellEnvFallbackTimeoutMs as mt, resolveAuthProfileOrder as n, getApiKeyForModel as nt, CHUTES_AUTHORIZE_ENDPOINT as o, resolveAwsSdkEnvVarName as ot, upsertAuthProfile as p, loadShellEnvFallback as pt, VENICE_MODEL_CATALOG as q, isProfileInCooldown as r, getCustomProviderApiKey as rt, exchangeChutesCodeForTokens as s, resolveEnvApiKey as st, auth_profiles_exports as t, buildSyntheticModelDefinition as tt, repairOAuthProfileIdMismatch as u, normalizeSecretInput as ut, resolveAuthStorePath as v, HUGGINGFACE_MODEL_CATALOG as vt, buildAllowedModelSet as w, resolveCloudflareAiGatewayBaseUrl as wt, loadJsonFile as x, isHuggingfacePolicyLocked as xt, resolveAuthStorePathForDisplay as y, buildHuggingfaceModelDefinition as yt, resolveThinkingDefault as z };