@cortex-agent/server 2026.10.28 → 2026.12.5

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 (401) hide show
  1. package/LICENSE +255 -21
  2. package/README.md +36 -7
  3. package/THIRD_PARTY_NOTICES.txt +1990 -593
  4. package/defaults/hooks/cortex-hook-api.mjs +2 -1
  5. package/defaults/hooks/quota-stop.mjs +37 -0
  6. package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +23 -15
  7. package/defaults/prompts/clean-workspace.md +5 -0
  8. package/dist/agent-adapter/claude/remote-mcp-proxy.js +1 -1
  9. package/dist/chunks/agent-runner-LVZVKBZX.js +4 -0
  10. package/dist/chunks/anthropic-messages-TT6454AA.js +8 -0
  11. package/dist/chunks/azure-openai-responses-52LR2XZD.js +4 -0
  12. package/dist/chunks/bedrock-converse-stream-EOZGYUNY.js +60 -0
  13. package/dist/chunks/bowser-MLGGLXTZ.js +20 -0
  14. package/dist/chunks/child-runner-SMG2VOU5.js +4 -0
  15. package/dist/chunks/chunk-24DH4IR5.js +4 -0
  16. package/dist/chunks/chunk-25XKBRDT.js +70 -0
  17. package/dist/chunks/chunk-2ABET62E.js +23 -0
  18. package/dist/chunks/chunk-2BVUA256.js +4 -0
  19. package/dist/chunks/{chunk-LEUENXI2.js → chunk-2WFL62UO.js} +1 -1
  20. package/dist/chunks/{chunk-OZGBWAT2.js → chunk-2YTYYG4K.js} +1 -1
  21. package/dist/chunks/chunk-335SSANX.js +4 -0
  22. package/dist/chunks/chunk-377OPTXX.js +17 -0
  23. package/dist/chunks/chunk-3EZNVLBF.js +129 -0
  24. package/dist/chunks/chunk-3O6ZG5HA.js +7 -0
  25. package/dist/chunks/{chunk-6AKUD3CF.js → chunk-3XLHL5YT.js} +1 -1
  26. package/dist/chunks/chunk-4HRI75GU.js +4 -0
  27. package/dist/chunks/chunk-4JBYLRPM.js +57 -0
  28. package/dist/chunks/chunk-4KKV7VKE.js +4 -0
  29. package/dist/chunks/chunk-4KQHDDC5.js +4 -0
  30. package/dist/chunks/chunk-4SWD4JMP.js +33 -0
  31. package/dist/chunks/chunk-52VCLZS5.js +4 -0
  32. package/dist/chunks/chunk-54P7TSY3.js +10 -0
  33. package/dist/chunks/chunk-5DVSAXOI.js +7 -0
  34. package/dist/chunks/chunk-5F3A62YS.js +4 -0
  35. package/dist/chunks/{chunk-XNSSUVT6.js → chunk-5FHETFZM.js} +1 -1
  36. package/dist/chunks/{chunk-A34TDMIC.js → chunk-5LBLRAHS.js} +1 -1
  37. package/dist/chunks/chunk-5UYVNA3W.js +4 -0
  38. package/dist/chunks/chunk-6G3OYMCV.js +21 -0
  39. package/dist/chunks/chunk-7GGPYU5E.js +30 -0
  40. package/dist/chunks/chunk-7TYSMLUV.js +4 -0
  41. package/dist/chunks/chunk-7W7VYUTK.js +5 -0
  42. package/dist/chunks/chunk-AXYAZTTN.js +6 -0
  43. package/dist/chunks/{chunk-BGVHA2D4.js → chunk-B3NB243Z.js} +1 -1
  44. package/dist/chunks/chunk-BKYP6AGM.js +8 -0
  45. package/dist/chunks/chunk-BVEDNESB.js +4 -0
  46. package/dist/chunks/chunk-BWDJS6A4.js +12 -0
  47. package/dist/chunks/chunk-C6YVF7EI.js +4 -0
  48. package/dist/chunks/chunk-CEJIYYVE.js +15 -0
  49. package/dist/chunks/chunk-CI2RHH74.js +50 -0
  50. package/dist/chunks/chunk-CMSOOLJB.js +4 -0
  51. package/dist/chunks/chunk-CSVTYYLP.js +4 -0
  52. package/dist/chunks/chunk-DE5EGVKG.js +6 -0
  53. package/dist/chunks/{chunk-E6BYRULL.js → chunk-DK3RPZOQ.js} +1 -1
  54. package/dist/chunks/{chunk-YPK2CAIZ.js → chunk-DK4UCK7L.js} +1 -1
  55. package/dist/chunks/chunk-DYLBVUAU.js +4 -0
  56. package/dist/chunks/chunk-FDC2GRBK.js +27 -0
  57. package/dist/chunks/chunk-FE7HH5JS.js +18 -0
  58. package/dist/chunks/chunk-FYD57YRO.js +436 -0
  59. package/dist/chunks/chunk-G264APQN.js +5 -0
  60. package/dist/chunks/chunk-G4JYZFEO.js +11 -0
  61. package/dist/chunks/chunk-GFFM56U2.js +4 -0
  62. package/dist/chunks/chunk-GOS3P7KS.js +132 -0
  63. package/dist/chunks/chunk-HVN37UXD.js +4 -0
  64. package/dist/chunks/chunk-IA6IODY3.js +4 -0
  65. package/dist/chunks/{chunk-HU6UIDEJ.js → chunk-IGZWZP7Z.js} +1 -1
  66. package/dist/chunks/{chunk-NR6U3WIZ.js → chunk-IJ7XFQMI.js} +1 -1
  67. package/dist/chunks/chunk-IMMGYDAB.js +6 -0
  68. package/dist/chunks/chunk-IOWBF7UK.js +10 -0
  69. package/dist/chunks/{chunk-HALUQ7ZF.js → chunk-ITGCWQFK.js} +1 -1
  70. package/dist/chunks/chunk-IVZ7QUEG.js +4 -0
  71. package/dist/chunks/{chunk-YAEVYJAR.js → chunk-IWY2HIFK.js} +1 -1
  72. package/dist/chunks/{chunk-KGJZAYQD.js → chunk-J7OBATRN.js} +1 -1
  73. package/dist/chunks/{chunk-QWAQHHRS.js → chunk-JGUEIW2W.js} +1 -1
  74. package/dist/chunks/chunk-JKL3AK5D.js +106 -0
  75. package/dist/chunks/chunk-JZ7U7RUK.js +351 -0
  76. package/dist/chunks/chunk-KJUQCCB5.js +4 -0
  77. package/dist/chunks/chunk-KST6OY76.js +10 -0
  78. package/dist/chunks/chunk-KZSAFVSY.js +129 -0
  79. package/dist/chunks/chunk-LD2ZSH3M.js +903 -0
  80. package/dist/chunks/chunk-LE6QPXN6.js +7 -0
  81. package/dist/chunks/chunk-LEAV3FFG.js +4 -0
  82. package/dist/chunks/chunk-LIIZI3HY.js +5 -0
  83. package/dist/chunks/chunk-LP72AF56.js +45 -0
  84. package/dist/chunks/{chunk-FXDIR3SQ.js → chunk-MJQ2D2OP.js} +1 -1
  85. package/dist/chunks/{chunk-6LZK4DDH.js → chunk-NHHR4DCF.js} +1 -1
  86. package/dist/chunks/chunk-NW4GW47L.js +4 -0
  87. package/dist/chunks/chunk-OALEJ6FG.js +60 -0
  88. package/dist/chunks/chunk-OIV4DIMB.js +4 -0
  89. package/dist/chunks/chunk-OJ37ZWBG.js +4 -0
  90. package/dist/chunks/chunk-OZXMPBUX.js +4 -0
  91. package/dist/chunks/{chunk-3THJYAEF.js → chunk-PG7452XE.js} +1 -1
  92. package/dist/chunks/chunk-PJCUB7YJ.js +4 -0
  93. package/dist/chunks/chunk-PTS3J4DQ.js +6 -0
  94. package/dist/chunks/{chunk-PXS5SHOV.js → chunk-PVVEEBUU.js} +1 -1
  95. package/dist/chunks/chunk-Q7BZLPBU.js +8 -0
  96. package/dist/chunks/{chunk-FOJQXLL2.js → chunk-QC66ZXPP.js} +1 -1
  97. package/dist/chunks/chunk-QXFWIL4C.js +4 -0
  98. package/dist/chunks/{chunk-PFMEUFJ7.js → chunk-R2CCD4OF.js} +1 -1
  99. package/dist/chunks/chunk-R6CGBSTC.js +22 -0
  100. package/dist/chunks/chunk-RG5GP4RB.js +5 -0
  101. package/dist/chunks/{chunk-D3NXKK2L.js → chunk-RW2F2QNP.js} +1 -1
  102. package/dist/chunks/{models-L5VF4I5O-XXNJYQMQ.js → chunk-RWPO3NZ3.js} +1 -1
  103. package/dist/chunks/chunk-SAJD4EKE.js +10 -0
  104. package/dist/chunks/chunk-SDUS2H3E.js +4 -0
  105. package/dist/chunks/chunk-SIHGKM4E.js +4 -0
  106. package/dist/chunks/chunk-SKHFU5DI.js +4 -0
  107. package/dist/chunks/{chunk-STUHNKQS.js → chunk-SM45TH22.js} +1 -1
  108. package/dist/chunks/chunk-T54CZKNJ.js +6 -0
  109. package/dist/chunks/chunk-TKFFQNAP.js +19 -0
  110. package/dist/chunks/chunk-TMV2ZDOI.js +18 -0
  111. package/dist/chunks/chunk-TRXLIL7V.js +4 -0
  112. package/dist/chunks/{chunk-SUFW24P4.js → chunk-UEEW2R4E.js} +1 -1
  113. package/dist/chunks/chunk-UHXPRU6G.js +10 -0
  114. package/dist/chunks/chunk-UPQVWHZ3.js +4 -0
  115. package/dist/chunks/{chunk-JERCOLY3.js → chunk-V35MFAUQ.js} +4 -6
  116. package/dist/chunks/chunk-V7K3KNDM.js +4 -0
  117. package/dist/chunks/chunk-VHX2GHBF.js +4 -0
  118. package/dist/chunks/chunk-VOAKRJ4R.js +4 -0
  119. package/dist/chunks/{chunk-X2GYYRVM.js → chunk-VW7TLY3P.js} +1 -1
  120. package/dist/chunks/chunk-W34AK4SK.js +65 -0
  121. package/dist/chunks/{chunk-REBNWCKI.js → chunk-WU7RNAZD.js} +1 -1
  122. package/dist/chunks/chunk-WZC4TDDM.js +6 -0
  123. package/dist/chunks/chunk-WZYS2HAK.js +4 -0
  124. package/dist/chunks/chunk-X2TKJ7KR.js +11 -0
  125. package/dist/chunks/{chunk-H2FP6DG4.js → chunk-X5ND4H4P.js} +1 -1
  126. package/dist/chunks/{chunk-4U7XXM4W.js → chunk-Y3AOGNDT.js} +1 -1
  127. package/dist/chunks/chunk-Y6DGVTKM.js +6 -0
  128. package/dist/chunks/{chunk-KENCMLRE.js → chunk-YAEHSSR4.js} +1 -1
  129. package/dist/chunks/chunk-YWPBE5LP.js +4 -0
  130. package/dist/chunks/chunk-ZAVX7G2M.js +15 -0
  131. package/dist/chunks/chunk-ZD2M73XA.js +19 -0
  132. package/dist/chunks/chunk-ZD4O6NPV.js +4 -0
  133. package/dist/chunks/chunk-ZNAMETPQ.js +4 -0
  134. package/dist/chunks/chunk-ZY6N5LVQ.js +4 -0
  135. package/dist/chunks/chunk-ZYQ4TDTT.js +81 -0
  136. package/dist/chunks/cli-VB2N7HEK.js +55 -0
  137. package/dist/chunks/cloudflare-workers-ai-system-one-YKU742EC.js +4 -0
  138. package/dist/chunks/context-CI2FKEQE.js +4 -0
  139. package/dist/chunks/cost-CZRRSIUF.js +5 -0
  140. package/dist/chunks/dist-QCNQN6DY.js +4 -0
  141. package/dist/chunks/easter-egg-3d-XR5S2O3T.js +4 -0
  142. package/dist/chunks/{event-streams-3JSFPOTZ.js → event-streams-AVE4MSS6.js} +1 -1
  143. package/dist/chunks/{execution-repo-ZLJTBWFC.js → execution-repo-5TLV2NM4.js} +1 -1
  144. package/dist/chunks/{executions-6ARGR3IO.js → executions-I3UUIGSL.js} +1 -1
  145. package/dist/chunks/file-Y5G56IUT.js +4 -0
  146. package/dist/chunks/github-copilot-BRU2SRRZ.js +4 -0
  147. package/dist/chunks/google-generative-ai-ZF5QEUZV.js +4 -0
  148. package/dist/chunks/google-vertex-4PJZZI3Y.js +4 -0
  149. package/dist/chunks/init-A6GY656J.js +4 -0
  150. package/dist/chunks/{install-cli-4IZCSDFZ.js → install-cli-FALWKQYO.js} +1 -1
  151. package/dist/chunks/{interaction-ask-G5T3H3CG.js → interaction-ask-O5HGF6CH.js} +1 -1
  152. package/dist/chunks/{interaction-plan-E5V42MUP.js → interaction-plan-JTVDN3BC.js} +1 -1
  153. package/dist/chunks/kimi-coding-ZCIBMDZ6.js +4 -0
  154. package/dist/chunks/{llama-cpp-classify-OTXZWCMW.js → llama-cpp-classify-NRUXAIGQ.js} +3 -3
  155. package/dist/chunks/local-client-stop-RS4AHNF4.js +4 -0
  156. package/dist/chunks/{memory-cli-PYOILNN5.js → memory-cli-DIT4DQF3.js} +1 -1
  157. package/dist/chunks/meta-JQH66YU7.js +4 -0
  158. package/dist/chunks/mistral-conversations-CXHOECUV.js +7 -0
  159. package/dist/chunks/model-resolver-GIBPYRKP.js +4 -0
  160. package/dist/chunks/monitor-Z2HKNY5E.js +4 -0
  161. package/dist/chunks/{node-PTK2HCDV.js → node-DAO3SX7O.js} +1 -1
  162. package/dist/chunks/{openai-codex-2REL6UQU.js → openai-codex-JULCKICT.js} +1 -1
  163. package/dist/chunks/openai-codex-responses-U6DGMGDK.js +12 -0
  164. package/dist/chunks/openai-completions-PP4XLLOM.js +9 -0
  165. package/dist/chunks/{openai-decisions-2N6ZRPZC.js → openai-decisions-JU6QQKEM.js} +1 -1
  166. package/dist/chunks/openai-responses-2SG757TL.js +6 -0
  167. package/dist/chunks/openrouter-images-32M7YZWC.js +4 -0
  168. package/dist/chunks/pi-messages-VSINMXN4.js +10 -0
  169. package/dist/chunks/radius-THYKWV4E.js +4 -0
  170. package/dist/chunks/remote-ops-2WBEFQ3E.js +14 -0
  171. package/dist/chunks/runner-5MKMRTIN.js +4 -0
  172. package/dist/chunks/runtime-DST3H5JP.js +4 -0
  173. package/dist/chunks/schedule-cli-V7Y2BBVY.js +4 -0
  174. package/dist/chunks/slack-R7SEJYMY.js +4 -0
  175. package/dist/chunks/start-ui-http-7K5JOLPU.js +43 -0
  176. package/dist/chunks/subagent-Z5IQ4L54.js +4 -0
  177. package/dist/chunks/{time-KEHDQT6K.js → time-P6PE52WL.js} +1 -1
  178. package/dist/chunks/tool-shims-YCXZWTST.js +4 -0
  179. package/dist/chunks/typesafe-system-one-M2DABJSZ.js +4 -0
  180. package/dist/chunks/ui-board-HQIE4RZG.js +5 -0
  181. package/dist/chunks/ui-decision-YBZDS4YW.js +4 -0
  182. package/dist/chunks/{ui-file-GVH53O3X.js → ui-file-SRD4ILBS.js} +1 -1
  183. package/dist/chunks/ui-view-Z25MTZT7.js +4 -0
  184. package/dist/chunks/virtual-modules-H4DXPJZB.js +4 -0
  185. package/dist/chunks/waitpoint-M6JZBSLT.js +5 -0
  186. package/dist/chunks/workers-SQ2R32TK.js +4 -0
  187. package/dist/client-bundle/client.mjs +273 -93
  188. package/dist/client-bundle/manifest.json +2 -2
  189. package/dist/core/pi-sdk.js +1 -1
  190. package/dist/domain/auth/cc-auth-cli.js +1 -1
  191. package/dist/domain/mcp/bundled-server.js +1 -1
  192. package/dist/domain/mcp/feishu/client.js +4 -0
  193. package/dist/entry/app.js +151 -559
  194. package/dist/entry/browser-cli.js +10 -10
  195. package/dist/entry/cli.js +1 -1
  196. package/dist/entry/cortex-cli.js +1 -1
  197. package/dist/entry/daemon.js +4 -4
  198. package/dist/entry/hook-cli.js +2 -2
  199. package/dist/entry/production-app-bootstrap.js +1 -1
  200. package/dist/entry/production-evidence-export-cli.js +1 -1
  201. package/dist/entry/signal-cli.js +2 -2
  202. package/dist/tui/index.js +41 -41
  203. package/package.json +3 -3
  204. package/vendor/pi/CHANGELOG.md +330 -0
  205. package/vendor/pi/dist/codemode-worker.js +2 -0
  206. package/vendor/pi/dist/core/export-html/ansi-to-html.js +57 -20
  207. package/vendor/pi/dist/core/export-html/template.css +9 -0
  208. package/vendor/pi/dist/core/export-html/template.js +166 -46
  209. package/vendor/pi/dist/core/export-html/tool-renderer.js +5 -3
  210. package/vendor/pi/dist/core/extensions/loader.js +1 -1
  211. package/vendor/pi/dist/extensions/codemode/execute.js +15 -13
  212. package/vendor/pi/dist/modes/interactive/theme/theme.js +36 -23
  213. package/vendor/pi/dist/utils/image-resize-worker.js +1 -1
  214. package/vendor/pi/dist/utils/image-resize.js +1 -1
  215. package/vendor/pi/docs/cli.md +35 -12
  216. package/vendor/pi/docs/custom-provider.md +2 -0
  217. package/vendor/pi/docs/environment-variables.md +2 -0
  218. package/vendor/pi/docs/extensions.md +3192 -225
  219. package/vendor/pi/docs/keybindings.md +2 -2
  220. package/vendor/pi/docs/llama-cpp.md +27 -19
  221. package/vendor/pi/docs/mcp.md +6 -4
  222. package/vendor/pi/docs/message-types.md +1 -1
  223. package/vendor/pi/docs/models-configuration.md +9 -3
  224. package/vendor/pi/docs/models.md +2 -1
  225. package/vendor/pi/docs/nvidia-rtx-llama-cpp.md +5 -5
  226. package/vendor/pi/docs/packages.md +24 -0
  227. package/vendor/pi/docs/prompt-templates.md +1 -1
  228. package/vendor/pi/docs/providers.md +4 -2
  229. package/vendor/pi/docs/quickstart.md +7 -3
  230. package/vendor/pi/docs/rpc-commands.md +1 -1
  231. package/vendor/pi/docs/rpc.md +4 -2
  232. package/vendor/pi/docs/sessions.md +17 -3
  233. package/vendor/pi/docs/settings.md +6 -5
  234. package/vendor/pi/docs/slash-commands.md +3 -2
  235. package/vendor/pi/docs/terminal-setup.md +3 -1
  236. package/vendor/pi/docs/tmux.md +6 -0
  237. package/vendor/pi/docs/tui.md +4 -0
  238. package/vendor/pi/docs/windows.md +27 -0
  239. package/vendor/pi/examples/extensions/README.md +2 -1
  240. package/vendor/pi/examples/extensions/custom-provider-anthropic/index.ts +27 -31
  241. package/vendor/pi/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  242. package/vendor/pi/examples/extensions/custom-provider-anthropic/package.json +1 -1
  243. package/vendor/pi/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  244. package/vendor/pi/examples/extensions/debug-provider.ts +2 -2
  245. package/vendor/pi/examples/extensions/gondolin/index.ts +4 -7
  246. package/vendor/pi/examples/extensions/gondolin/package-lock.json +19 -29
  247. package/vendor/pi/examples/extensions/gondolin/package.json +2 -2
  248. package/vendor/pi/examples/extensions/plan-mode/index.ts +23 -13
  249. package/vendor/pi/examples/extensions/plan-mode/utils.ts +42 -16
  250. package/vendor/pi/examples/extensions/preset.ts +2 -0
  251. package/vendor/pi/examples/extensions/reload-runtime.ts +17 -5
  252. package/vendor/pi/examples/extensions/subagent/README.md +14 -11
  253. package/vendor/pi/examples/extensions/subagent/index.ts +392 -171
  254. package/vendor/pi/examples/extensions/todo.ts +7 -0
  255. package/vendor/pi/examples/extensions/tools.ts +2 -0
  256. package/vendor/pi/examples/extensions/with-deps/package-lock.json +2 -2
  257. package/vendor/pi/examples/extensions/with-deps/package.json +1 -1
  258. package/vendor/pi/examples/tsconfig.json +208 -0
  259. package/vendor/pi/package.json +15 -16
  260. package/vendor/pi/schemas/models.schema.json +66 -37
  261. package/vendor/pi/schemas/settings.schema.json +18 -1
  262. package/vendor/pi-ai/bedrock.js +1 -1
  263. package/vendor/pi-ai/oauth-load.js +1 -1
  264. package/web/dist/assets/{board-math-css-BPXakv_3.js → board-math-css-DKX6FcUS.js} +1 -1
  265. package/web/dist/assets/index-D11wi0uG.js +540 -0
  266. package/web/dist/assets/index-JedYumhY.css +1 -0
  267. package/web/dist/assets/{index-WCm6wwmM.js → index-jl30Gy8P.js} +1 -1
  268. package/web/dist/assets/pdf-worker-DdZgk2mV.js +57 -0
  269. package/web/dist/assets/pdf.worker.min-Bz_KHX45.js +55 -0
  270. package/web/dist/index.html +2 -2
  271. package/web/dist/theme.css +22 -0
  272. package/dist/chunks/anthropic-messages-M3SMXACA.js +0 -8
  273. package/dist/chunks/api-GM53PHIL-GFHEXXE6.js +0 -4
  274. package/dist/chunks/azure-openai-responses-76YWXHSB.js +0 -4
  275. package/dist/chunks/bedrock-converse-stream-5UPX4NTQ.js +0 -58
  276. package/dist/chunks/child-runner-3GHOWGZP.js +0 -4
  277. package/dist/chunks/chunk-2ZNLUY2U.js +0 -128
  278. package/dist/chunks/chunk-3F6WW7HR.js +0 -13
  279. package/dist/chunks/chunk-3OKHUVEM.js +0 -7
  280. package/dist/chunks/chunk-3YHOCPQU.js +0 -10
  281. package/dist/chunks/chunk-4EX2JJWB.js +0 -4
  282. package/dist/chunks/chunk-4LLH5OWM.js +0 -10
  283. package/dist/chunks/chunk-52T37Y47.js +0 -8
  284. package/dist/chunks/chunk-7MU2AKNM.js +0 -4
  285. package/dist/chunks/chunk-AAA3UBIS.js +0 -4
  286. package/dist/chunks/chunk-ASYQHJVQ.js +0 -9
  287. package/dist/chunks/chunk-BKHDWCRT.js +0 -79
  288. package/dist/chunks/chunk-CQLH4UVX.js +0 -4
  289. package/dist/chunks/chunk-CVC66CFV.js +0 -33
  290. package/dist/chunks/chunk-D6UA4BZC.js +0 -19
  291. package/dist/chunks/chunk-DGMNI4AO.js +0 -4
  292. package/dist/chunks/chunk-DHSA5ACV.js +0 -125
  293. package/dist/chunks/chunk-DPQPXBTP.js +0 -68
  294. package/dist/chunks/chunk-DXBSQXJL.js +0 -18
  295. package/dist/chunks/chunk-E7ZMYIY6.js +0 -30
  296. package/dist/chunks/chunk-EQITBTJC.js +0 -10
  297. package/dist/chunks/chunk-EXJA5RIX.js +0 -357
  298. package/dist/chunks/chunk-FF7UELTU.js +0 -4
  299. package/dist/chunks/chunk-FH74NME3.js +0 -115
  300. package/dist/chunks/chunk-FOQ7VLIL.js +0 -17
  301. package/dist/chunks/chunk-FX6MOGLR.js +0 -11
  302. package/dist/chunks/chunk-G2V65UBA.js +0 -4
  303. package/dist/chunks/chunk-HGPBHTVD.js +0 -6
  304. package/dist/chunks/chunk-J5DVLUKY.js +0 -6
  305. package/dist/chunks/chunk-JW2HFMTF.js +0 -4
  306. package/dist/chunks/chunk-KDYEGGMW.js +0 -4
  307. package/dist/chunks/chunk-KIGMAATV.js +0 -23
  308. package/dist/chunks/chunk-KIU5FAPY.js +0 -5
  309. package/dist/chunks/chunk-KIWMQPH7.js +0 -739
  310. package/dist/chunks/chunk-L6VCIGWS.js +0 -11
  311. package/dist/chunks/chunk-LACGULCN.js +0 -10
  312. package/dist/chunks/chunk-LMSQZ6TQ.js +0 -4
  313. package/dist/chunks/chunk-MEPASGPP.js +0 -6
  314. package/dist/chunks/chunk-MFAEUHMV.js +0 -28
  315. package/dist/chunks/chunk-NAA7GF6Q.js +0 -5
  316. package/dist/chunks/chunk-NKDMKRSB.js +0 -68
  317. package/dist/chunks/chunk-NKXV32S6.js +0 -4
  318. package/dist/chunks/chunk-NVX5IPRN.js +0 -4
  319. package/dist/chunks/chunk-O3JW2F7D.js +0 -8
  320. package/dist/chunks/chunk-OE4KH3NJ.js +0 -4
  321. package/dist/chunks/chunk-OISO5JXB.js +0 -4
  322. package/dist/chunks/chunk-OPYXNSMY.js +0 -4
  323. package/dist/chunks/chunk-OSEIQ7SS.js +0 -4
  324. package/dist/chunks/chunk-P52RMIYX.js +0 -6
  325. package/dist/chunks/chunk-PBJ5MPPX.js +0 -60
  326. package/dist/chunks/chunk-PZMGBKUR.js +0 -13
  327. package/dist/chunks/chunk-PZMXHA6X.js +0 -9
  328. package/dist/chunks/chunk-Q7CE3UIE.js +0 -133
  329. package/dist/chunks/chunk-QBKCAIJG.js +0 -4
  330. package/dist/chunks/chunk-QEOFEETJ.js +0 -4
  331. package/dist/chunks/chunk-QUUEQRIT.js +0 -4
  332. package/dist/chunks/chunk-RA6HKFBV.js +0 -4
  333. package/dist/chunks/chunk-REPYBMQS.js +0 -4
  334. package/dist/chunks/chunk-SKHLZ6XY.js +0 -9
  335. package/dist/chunks/chunk-TAWLERZA.js +0 -4
  336. package/dist/chunks/chunk-TWAEABGG.js +0 -52
  337. package/dist/chunks/chunk-TZFLHVOQ.js +0 -7
  338. package/dist/chunks/chunk-UD3NMUHR.js +0 -12
  339. package/dist/chunks/chunk-UNVEZI57.js +0 -4
  340. package/dist/chunks/chunk-VQUPKMDR.js +0 -4
  341. package/dist/chunks/chunk-W25TB3PU.js +0 -4
  342. package/dist/chunks/chunk-W5LGYSPZ.js +0 -4
  343. package/dist/chunks/chunk-WEZWKMYU.js +0 -4
  344. package/dist/chunks/chunk-XAJLZR7C.js +0 -28
  345. package/dist/chunks/chunk-XH6FMP3N.js +0 -71
  346. package/dist/chunks/chunk-XSRZHN63.js +0 -4
  347. package/dist/chunks/chunk-Y3GFB5XM.js +0 -8
  348. package/dist/chunks/chunk-YG7OEPR2.js +0 -6
  349. package/dist/chunks/chunk-YHIWOGVL.js +0 -4
  350. package/dist/chunks/chunk-YKKEI5GI.js +0 -4
  351. package/dist/chunks/chunk-YZSHTWNM.js +0 -92
  352. package/dist/chunks/chunk-Z4H3VDHI.js +0 -4
  353. package/dist/chunks/cli-5DBTRMHU.js +0 -53
  354. package/dist/chunks/client-XOGYH5UR.js +0 -4
  355. package/dist/chunks/cloudflare-workers-ai-system-one-32JCFHI3.js +0 -4
  356. package/dist/chunks/config-DJSQI77S-335IXHSM.js +0 -4
  357. package/dist/chunks/context-VCQH5OB6.js +0 -4
  358. package/dist/chunks/cost-PGGFI7QJ.js +0 -5
  359. package/dist/chunks/dist-PUKMZ7GW.js +0 -4
  360. package/dist/chunks/easter-egg-3d-MO4MOEVF.js +0 -4
  361. package/dist/chunks/es5-VNTQPCKX.js +0 -4
  362. package/dist/chunks/file-7BN7RCAY.js +0 -4
  363. package/dist/chunks/gateway-UCRPMR75.js +0 -36
  364. package/dist/chunks/github-copilot-HAI2DA62.js +0 -4
  365. package/dist/chunks/google-generative-ai-2VXWLHWI.js +0 -4
  366. package/dist/chunks/google-vertex-UA36QP2U.js +0 -4
  367. package/dist/chunks/init-HA7FAQ73.js +0 -4
  368. package/dist/chunks/kimi-coding-HMJRKCPA.js +0 -4
  369. package/dist/chunks/local-client-stop-SQRU7ZZM.js +0 -4
  370. package/dist/chunks/meta-KY3LNFV2.js +0 -4
  371. package/dist/chunks/mistral-conversations-34F66L3O.js +0 -7
  372. package/dist/chunks/model-resolver-N3DTAQ2S.js +0 -4
  373. package/dist/chunks/openai-codex-responses-ZBVHREB3.js +0 -12
  374. package/dist/chunks/openai-completions-VVIB26SH.js +0 -9
  375. package/dist/chunks/openai-responses-735XA2ZX.js +0 -6
  376. package/dist/chunks/openrouter-images-3IKETHAC.js +0 -4
  377. package/dist/chunks/pi-messages-I3E4ZFHA.js +0 -10
  378. package/dist/chunks/radius-HXRZVBDB.js +0 -4
  379. package/dist/chunks/remote-ops-BALZYKH6.js +0 -14
  380. package/dist/chunks/runner-PLVZDGHB.js +0 -4
  381. package/dist/chunks/runtime-6YLTA2ZD.js +0 -4
  382. package/dist/chunks/schedule-cli-OLASBBYJ.js +0 -4
  383. package/dist/chunks/slack-WAGSPZUX.js +0 -4
  384. package/dist/chunks/start-ui-http-QALT7C3P.js +0 -43
  385. package/dist/chunks/subagent-E3UC7ZHC.js +0 -4
  386. package/dist/chunks/tool-shims-Q6P6UXVC.js +0 -4
  387. package/dist/chunks/typesafe-system-one-6ULACYD4.js +0 -4
  388. package/dist/chunks/ui-board-4GYW6KKW.js +0 -5
  389. package/dist/chunks/ui-decision-U2FXSEC2.js +0 -4
  390. package/dist/chunks/ui-view-O7PLANT7.js +0 -4
  391. package/dist/chunks/virtual-modules-IDC5YKZJ.js +0 -4
  392. package/dist/chunks/waitpoint-2FGQBIAC.js +0 -5
  393. package/dist/chunks/workers-XN4PSTH6.js +0 -4
  394. package/vendor/aistatus/gateway-cli.js +0 -21
  395. package/vendor/pi/examples/extensions/sandbox/index.ts +0 -321
  396. package/vendor/pi/examples/extensions/sandbox/package-lock.json +0 -92
  397. package/vendor/pi/examples/extensions/sandbox/package.json +0 -19
  398. package/web/dist/assets/index-BHZpFXhc.js +0 -525
  399. package/web/dist/assets/index-DqWMdMkh.css +0 -1
  400. package/web/dist/assets/pdf-worker-Hp15W1QJ.js +0 -57
  401. package/web/dist/assets/pdf.worker.min-DnhTvCwe.js +0 -55
@@ -13,7 +13,8 @@ function resolveLevel(level) {
13
13
  }
14
14
 
15
15
  function postJson(path, payload, timeoutMs) {
16
- const port = parseInt(process.env.WEBHOOK_PORT || '3001', 10);
16
+ // The server puts its main port in the env of everything it spawns, hooks included.
17
+ const port = parseInt(process.env.CORTEX_UI_PORT || '26789', 10);
17
18
  const body = JSON.stringify(payload);
18
19
  return new Promise((resolve, reject) => {
19
20
  const req = http.request({
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+ // PostToolUse hook on every Claude process Cortex starts (see hooks-builder.ts, withQuotaStopHook).
3
+ // While this process's account is past its five-hour stop threshold, it ends an automatic turn once
4
+ // the tool that just ran has finished: `continue: false` stops the loop without undoing the tool.
5
+ // The server writes the state file (domain/costs/quota-stop.ts) only while some account is stopped:
6
+ // { "routes": { "<account>": { "utilization", "threshold", "resetsAt" (epoch s), … } },
7
+ // "exempt": ["<session id of a turn a person opened>", …] }
8
+
9
+ import { readFileSync } from 'node:fs';
10
+
11
+ /** Too close to the reset, a stop would outlive its reason. */
12
+ const RESET_MARGIN_S = 60;
13
+
14
+ function readJson(source) {
15
+ try { return JSON.parse(readFileSync(source, 'utf8')); } catch { return null; }
16
+ }
17
+
18
+ function percent(value) {
19
+ return `${Math.round(value * 100)}%`;
20
+ }
21
+
22
+ function stopReason(route, entry) {
23
+ return `Cortex quota stop: the ${route} five-hour window at ${percent(entry.utilization)} `
24
+ + `(stop threshold ${percent(entry.threshold)}). This automatic turn resumes after the window resets.`;
25
+ }
26
+
27
+ function spared(state, input) {
28
+ const exempt = new Set(Array.isArray(state.exempt) ? state.exempt : []);
29
+ return exempt.has(process.env.CORTEX_SESSION_ID) || exempt.has(input?.session_id);
30
+ }
31
+
32
+ const state = readJson(process.argv[2]);
33
+ const route = process.env.CORTEX_QUOTA_ROUTE;
34
+ const entry = route ? state?.routes?.[route] : undefined;
35
+ if (entry && Date.now() / 1000 < entry.resetsAt - RESET_MARGIN_S && !spared(state, readJson(0))) {
36
+ process.stdout.write(JSON.stringify({ continue: false, stopReason: stopReason(route, entry) }));
37
+ }
@@ -4,8 +4,8 @@ description: "Use when creating, deploying, updating, or troubleshooting cortex-
4
4
  allowed-tools: Read, Write, Edit, Bash, mcp__cortex-core__remote_bash, mcp__cortex-core__remote_read, mcp__cortex-core__remote_write, mcp__cortex-core__remote_edit, mcp__cortex-core__remote_glob, mcp__cortex-core__remote_grep
5
5
  metadata:
6
6
  author: "Cortex"
7
- version: "1.4.1"
8
- date: "2026-10-22"
7
+ version: "1.4.2"
8
+ date: "2026-10-29"
9
9
  ---
10
10
 
11
11
  # Client Manage
@@ -18,15 +18,23 @@ The server (`client-manager.ts`) starts clients automatically. Your job is to en
18
18
 
19
19
  ```
20
20
  cortex-agent-server ──SSH──► starts cortex-client on remote device
21
- ▲ │
22
- │ WebSocket wss://<tunnel-host> │
23
- │ (or ws://<serverHost>:3002 on LAN) │
24
- └────────────────────────────────────┘
21
+ ▲ │
22
+ │ WebSocket wss://<tunnel-host> │
23
+ │ (or ws://<serverHost>:26789 on LAN) │
24
+ └──────────────────────────────────────┘
25
25
  (client initiates this connection back to server)
26
26
  ```
27
27
 
28
28
  **Critical:** The WebSocket connection is initiated FROM the remote device TO the server. The client's target is resolved from `serverUrl` (a full `wss://`/`ws://` URL — used for Cloudflare Tunnel / cross-NAT) or `ws://<serverHost>:<serverPort>` (LAN/Tailscale), and that target MUST be reachable from the remote device. When both server and client are behind NAT, expose the server's WS port via a Cloudflare Tunnel and set the client's `serverUrl` to `wss://<tunnel-host>`. The server's SSH access to the device is separate — it's used for lifecycle management (start/kill/update) but not for the real-time command channel.
29
29
 
30
+ ## The server's WS port
31
+
32
+ Clients connect to the server's main port: `CORTEX_UI_PORT` in the server's `.env`, `26789` by default (`cortex init` picks the next free port when that one is taken). Read it with `grep CORTEX_UI_PORT ~/.cortex/config/.env` on the server. If that `.env` also sets `CORTEX_CLIENT_PORT`, the server keeps a separate client listener on that port as well, bound to `CORTEX_CLIENT_HOST`, and either port works.
33
+
34
+ The main port listens on `127.0.0.1` unless `CORTEX_UI_HOST` says otherwise. For a direct LAN or Tailscale connection, set `CORTEX_UI_HOST` to an address the device can reach (or `0.0.0.0`) and restart the server; a Cloudflare Tunnel or reverse SSH route works with the default.
35
+
36
+ In the examples below, `26789` stands for that port.
37
+
30
38
  ## Authentication (WS bearer token)
31
39
 
32
40
  The server's WebSocket gate is fail-closed: every client must present `CORTEX_CLIENT_TOKEN` (sent as the `x-cortex-token` upgrade header) or the upgrade is rejected with `401`. The server auto-generates the token into its `.env` (`CORTEX_CLIENT_TOKEN`) on first start; read it from the server with `grep CORTEX_CLIENT_TOKEN ~/.cortex/config/.env`.
@@ -47,8 +55,8 @@ A remote client gets the token automatically when the server spawns it over SSH
47
55
 
48
56
  The client resolves its server URL by precedence (`server-url.ts`): `CORTEX_SERVER_URL` env > config `serverUrl` > `ws://<serverHost>:<serverPort>`.
49
57
 
50
- - `serverUrl` — **Preferred for cross-NAT / cross-network.** A full WebSocket URL the client dials. When both server and client are behind NAT (no public IP), expose the server's WS port through a **Cloudflare Tunnel** and point every client at `wss://<tunnel-host>` (e.g. the server runs `cloudflared` with an ingress `<tunnel-host> → http://localhost:3002`). The client dials outbound over wss/443 — no inbound or public IP needed on either side. If set, `serverHost`/`serverPort` are ignored.
51
- - `serverHost` / `serverPort` — Legacy LAN/same-machine path: `ws://serverHost:serverPort` (default port 3002). `serverHost` must be an IP the remote device can reach (LAN IP, Tailscale IP, or `127.0.0.1` for same-machine). Use only when there is a direct/Tailscale route; for NAT-to-NAT use `serverUrl`.
58
+ - `serverUrl` — **Preferred for cross-NAT / cross-network.** A full WebSocket URL the client dials. When both server and client are behind NAT (no public IP), expose the server's WS port through a **Cloudflare Tunnel** and point every client at `wss://<tunnel-host>` (e.g. the server runs `cloudflared` with an ingress `<tunnel-host> → http://localhost:26789`). The client dials outbound over wss/443 — no inbound or public IP needed on either side. If set, `serverHost`/`serverPort` are ignored.
59
+ - `serverHost` / `serverPort` — LAN/same-machine path: `ws://serverHost:serverPort` (the server's WS port, see above). `serverHost` must be an IP the remote device can reach (LAN IP, Tailscale IP, or `127.0.0.1` for same-machine). Use only when there is a direct/Tailscale route; for NAT-to-NAT use `serverUrl`.
52
60
  - `clientToken` — The server's `CORTEX_CLIENT_TOKEN` (see Authentication). Required unless injected via the `CORTEX_CLIENT_TOKEN` env at launch.
53
61
  - `deviceName` — Must match the name in `machines.json` on the server.
54
62
 
@@ -66,7 +74,7 @@ The bidirectional path must work:
66
74
 
67
75
  ```
68
76
  server → remote: SSH (server starts/kills/updates client)
69
- remote → server: WebSocket to <serverHost>:3002 (client connects back)
77
+ remote → server: WebSocket to <serverHost>:26789 (client connects back)
70
78
  ```
71
79
 
72
80
  ### Verify the Return Path
@@ -74,7 +82,7 @@ remote → server: WebSocket to <serverHost>:3002 (client connects back)
74
82
  When bootstrapping a new device or debugging connection issues, ALWAYS verify the remote device can reach the server's WebSocket port:
75
83
 
76
84
  ```bash
77
- ssh user@host "timeout 3 bash -c 'echo > /dev/tcp/<serverHost>/3002' 2>&1 && echo REACHABLE || echo UNREACHABLE"
85
+ ssh user@host "timeout 3 bash -c 'echo > /dev/tcp/<serverHost>/26789' 2>&1 && echo REACHABLE || echo UNREACHABLE"
78
86
  ```
79
87
 
80
88
  ### How to Fix Connectivity
@@ -82,11 +90,11 @@ ssh user@host "timeout 3 bash -c 'echo > /dev/tcp/<serverHost>/3002' 2>&1 && ech
82
90
  | Situation | Fix |
83
91
  |-----------|-----|
84
92
  | Both sides behind NAT (no public IP) | Expose the server WS through a Cloudflare Tunnel; set client `serverUrl` to `wss://<tunnel-host>` (preferred when neither side is publicly reachable) |
85
- | Same LAN, unreachable | Check firewall: `sudo ufw allow 3002` on server |
93
+ | Same LAN, unreachable | Check that `CORTEX_UI_HOST` is not loopback, then the firewall: `sudo ufw allow 26789` on server |
86
94
  | Different network | Use Tailscale IP (works through NAT) or a Cloudflare Tunnel `serverUrl` |
87
- | STCP tunnel only | Use Tailscale or set up reverse SSH: `ssh -R 3002:localhost:3002 user@host` on server |
95
+ | STCP tunnel only | Use Tailscale or set up reverse SSH: `ssh -R 26789:localhost:26789 user@host` on server |
88
96
  | Tailscale but unreachable | `tailscale status` — ensure both devices are connected, check ACLs |
89
- | Can SSH but can't TCP | SSH works on port 22 only. Either open port 3002 or use Tailscale / Cloudflare Tunnel / reverse tunnel |
97
+ | Can SSH but can't TCP | SSH works on port 22 only. Either open the server's WS port or use Tailscale / Cloudflare Tunnel / reverse tunnel |
90
98
 
91
99
  ### Determine the Right serverHost
92
100
 
@@ -142,7 +150,7 @@ First, determine the correct `serverHost` (see Connectivity section above). Then
142
150
  ssh user@host 'mkdir -p ~/.cortex/config && cat > ~/.cortex/config/cortex-client.json << EOF
143
151
  {
144
152
  "serverHost": "<REACHABLE_IP>",
145
- "serverPort": 3002,
153
+ "serverPort": 26789,
146
154
  "deviceName": "<device-name>"
147
155
  }
148
156
  EOF'
@@ -153,7 +161,7 @@ Or use `mcp__cortex-core__remote_write` if the device is already reachable via a
153
161
  ### 4. Verify connectivity
154
162
 
155
163
  ```bash
156
- ssh user@host "timeout 3 bash -c 'echo > /dev/tcp/<serverHost>/3002' 2>&1 && echo REACHABLE || echo UNREACHABLE"
164
+ ssh user@host "timeout 3 bash -c 'echo > /dev/tcp/<serverHost>/26789' 2>&1 && echo REACHABLE || echo UNREACHABLE"
157
165
  ```
158
166
 
159
167
  ### 5. Start or restart the server
@@ -5,6 +5,11 @@ sources for this task. You may also access files or directories outside the work
5
5
  user explicitly authorizes for this task, within the authorized paths and operations. Files given
6
6
  for the task are in `inputs/`; treat them as reference unless asked to change them.
7
7
 
8
+ The most recent `[Authorized Paths]` block is the current list of authorized paths; use each one
9
+ only with the access it lists, and stop using a path once a newer block drops it. A path written
10
+ `<device>:<path>` is on that connected device: reach it with the remote_* tools. A path the user
11
+ authorizes in the conversation itself is authorized too.
12
+
8
13
  - Read, search and list files only inside the workspace or user-authorized paths. Do not open,
9
14
  grep, glob or ls anywhere else — home, parent directories, other projects, configuration or
10
15
  history folders — however relevant a path looks.
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __cortexCreateRequire } from 'node:module';
2
2
  const require = __cortexCreateRequire(import.meta.url);
3
3
  const __cortexPackageRoot = new URL("../../../", import.meta.url);
4
- import{a as m,b as p,c as l,d as u}from"../../chunks/chunk-3F6WW7HR.js";import{a as f,b as d}from"../../chunks/chunk-Z4H3VDHI.js";import{I as c,L as i}from"../../chunks/chunk-FOQ7VLIL.js";import"../../chunks/chunk-KRXTI4JO.js";import{J as o}from"../../chunks/chunk-DPQPXBTP.js";import{e as s}from"../../chunks/chunk-NAA7GF6Q.js";import{b as a}from"../../chunks/chunk-QWAQHHRS.js";import"../../chunks/chunk-J5DVLUKY.js";import"../../chunks/chunk-WHC7AYZD.js";import{createHash as x}from"node:crypto";import h from"node:fs";import g from"node:path";var y=s("claude-remote-mcp-proxy"),S=o.object({type:o.enum(["streamable-http","sse"]),url:o.string().url().refine(e=>["http:","https:"].includes(new URL(e).protocol)),headers:o.record(o.string(),o.string())}).strict();function R(e){return x("sha256").update(e,"utf8").digest("hex")}function C(e){let t=h.lstatSync(e);if(!t.isFile()||t.isSymbolicLink()||(t.mode&63)!==0)throw new Error(`Claude remote MCP proxy config is not private: ${e}`);let r=h.readFileSync(e,"utf8");if(g.basename(e)!==`${R(r)}.json`)throw new Error(`Claude remote MCP proxy config identity mismatch: ${e}`);return S.parse(JSON.parse(r))}function T(e){let t={...e.headers},r=u(t);return e.type==="streamable-http"?new p(new URL(e.url),{requestInit:{headers:t},fetch:r}):new l(new URL(e.url),{fetch:r,eventSourceInit:{fetch:r},requestInit:{headers:t}})}function v(e,t){e.setRequestHandler(c,async()=>t.listTools()),e.setRequestHandler(i,async r=>t.callTool(r.params))}async function b(e){let t=C(e),r=new m({name:"cortex-claude-remote-proxy",version:"1.0.0"});await r.connect(T(t));let n=new f({name:"cortex-claude-remote-proxy",version:"1.0.0"},{capabilities:{tools:{}}});v(n,r),n.onclose=()=>{r.close().catch(w=>y.warn(w))},await n.connect(new d)}a(new URL("dist/agent-adapter/claude/remote-mcp-proxy.js",__cortexPackageRoot).href)&&b(process.argv[2]??"").catch(e=>{y.error(e),process.exit(1)});export{b as startClaudeRemoteMcpProxy};
4
+ import{a as m,b as p,c as l,d as u}from"../../chunks/chunk-R6CGBSTC.js";import{a as f,b as d}from"../../chunks/chunk-WZYS2HAK.js";import{H as c,K as i}from"../../chunks/chunk-TMV2ZDOI.js";import"../../chunks/chunk-KRXTI4JO.js";import{K as o}from"../../chunks/chunk-W34AK4SK.js";import{e as s}from"../../chunks/chunk-7W7VYUTK.js";import{b as a}from"../../chunks/chunk-JGUEIW2W.js";import"../../chunks/chunk-T54CZKNJ.js";import"../../chunks/chunk-WHC7AYZD.js";import{createHash as x}from"node:crypto";import h from"node:fs";import g from"node:path";var y=s("claude-remote-mcp-proxy"),S=o.object({type:o.enum(["streamable-http","sse"]),url:o.string().url().refine(e=>["http:","https:"].includes(new URL(e).protocol)),headers:o.record(o.string(),o.string())}).strict();function R(e){return x("sha256").update(e,"utf8").digest("hex")}function C(e){let t=h.lstatSync(e);if(!t.isFile()||t.isSymbolicLink()||(t.mode&63)!==0)throw new Error(`Claude remote MCP proxy config is not private: ${e}`);let r=h.readFileSync(e,"utf8");if(g.basename(e)!==`${R(r)}.json`)throw new Error(`Claude remote MCP proxy config identity mismatch: ${e}`);return S.parse(JSON.parse(r))}function T(e){let t={...e.headers},r=u(t);return e.type==="streamable-http"?new p(new URL(e.url),{requestInit:{headers:t},fetch:r}):new l(new URL(e.url),{fetch:r,eventSourceInit:{fetch:r},requestInit:{headers:t}})}function v(e,t){e.setRequestHandler(c,async()=>t.listTools()),e.setRequestHandler(i,async r=>t.callTool(r.params))}async function b(e){let t=C(e),r=new m({name:"cortex-claude-remote-proxy",version:"1.0.0"});await r.connect(T(t));let n=new f({name:"cortex-claude-remote-proxy",version:"1.0.0"},{capabilities:{tools:{}}});v(n,r),n.onclose=()=>{r.close().catch(w=>y.warn(w))},await n.connect(new d)}a(new URL("dist/agent-adapter/claude/remote-mcp-proxy.js",__cortexPackageRoot).href)&&b(process.argv[2]??"").catch(e=>{y.error(e),process.exit(1)});export{b as startClaudeRemoteMcpProxy};
@@ -0,0 +1,4 @@
1
+ import { createRequire as __cortexCreateRequire } from 'node:module';
2
+ const require = __cortexCreateRequire(import.meta.url);
3
+ const __cortexPackageRoot = new URL("../../", import.meta.url);
4
+ import{Ub as a,Vb as b}from"./chunk-FYD57YRO.js";import"./chunk-TURBFBYN.js";import"./chunk-ZYQ4TDTT.js";import"./chunk-IVZ7QUEG.js";import"./chunk-LE6QPXN6.js";import"./chunk-PVVEEBUU.js";import"./chunk-NT32UURL.js";import"./chunk-TJ4GQRT6.js";import"./chunk-ZAVX7G2M.js";import"./chunk-Y3AOGNDT.js";import"./chunk-LMDWRRX4.js";import"./chunk-3EZNVLBF.js";import"./chunk-IA6IODY3.js";import"./chunk-UHXPRU6G.js";import"./chunk-NHD2ESHA.js";import"./chunk-QN44UXQR.js";import"./chunk-I6OPDRVF.js";import"./chunk-B3XBQEFM.js";import"./chunk-TZGNSHOL.js";import"./chunk-2YTYYG4K.js";import"./chunk-CMSOOLJB.js";import"./chunk-ZNAMETPQ.js";import"./chunk-4KQHDDC5.js";import"./chunk-QXFWIL4C.js";import"./chunk-Y6ZEVVL5.js";import"./chunk-R6CGBSTC.js";import"./chunk-WZYS2HAK.js";import"./chunk-TMV2ZDOI.js";import"./chunk-JKL3AK5D.js";import"./chunk-LP72AF56.js";import"./chunk-N6BTQN7R.js";import"./chunk-SAJD4EKE.js";import"./chunk-IOWBF7UK.js";import"./chunk-2ABET62E.js";import"./chunk-2WFL62UO.js";import"./chunk-5LBLRAHS.js";import"./chunk-IWY2HIFK.js";import"./chunk-PG7452XE.js";import"./chunk-RW2F2QNP.js";import"./chunk-5DVSAXOI.js";import"./chunk-HVN37UXD.js";import"./chunk-Y6DGVTKM.js";import"./chunk-OZXMPBUX.js";import"./chunk-V7K3KNDM.js";import"./chunk-5T7IX5KN.js";import"./chunk-UEEW2R4E.js";import"./chunk-VHX2GHBF.js";import"./chunk-C6YVF7EI.js";import"./chunk-ITGCWQFK.js";import"./chunk-PTS3J4DQ.js";import"./chunk-IMMGYDAB.js";import"./chunk-OJ37ZWBG.js";import"./chunk-SKHFU5DI.js";import"./chunk-V35MFAUQ.js";import"./chunk-OKRK6JPY.js";import"./chunk-52VCLZS5.js";import"./chunk-B3NB243Z.js";import"./chunk-LCKVYFMD.js";import"./chunk-5M4PFLRW.js";import"./chunk-BVEDNESB.js";import"./chunk-BKYP6AGM.js";import"./chunk-KST6OY76.js";import"./chunk-AXYAZTTN.js";import"./chunk-SM45TH22.js";import"./chunk-R2CCD4OF.js";import"./chunk-KRXTI4JO.js";import"./chunk-W34AK4SK.js";import"./chunk-LIIZI3HY.js";import"./chunk-Q4UGYGU5.js";import"./chunk-TRXLIL7V.js";import"./chunk-7GGPYU5E.js";import"./chunk-7W7VYUTK.js";import"./chunk-JGUEIW2W.js";import"./chunk-T54CZKNJ.js";import"./chunk-WHC7AYZD.js";export{a as AgentRunner,b as agentRunner};
@@ -0,0 +1,8 @@
1
+ import { createRequire as __cortexCreateRequire } from 'node:module';
2
+ const require = __cortexCreateRequire(import.meta.url);
3
+ const __cortexPackageRoot = new URL("../../", import.meta.url);
4
+ import{d as ne,e as se,f as re,g as oe,h as ie}from"./chunk-4KKV7VKE.js";import{a as le,b as de}from"./chunk-UPQVWHZ3.js";import{a as ge,b as me}from"./chunk-BGYR4ID3.js";import{a as ce}from"./chunk-V3AQJSWR.js";import{a as Te,b as xe,c as be}from"./chunk-ZY6N5LVQ.js";import{a as te}from"./chunk-OIV4DIMB.js";import{b as X,f as ee}from"./chunk-BWDJS6A4.js";import{a as C}from"./chunk-6R73ICDB.js";import{a as pe}from"./chunk-23PRJECN.js";import{a as F,b as fe,f as he,i as _e,k as ye,o as ke,p as we,q as j}from"./chunk-7TYSMLUV.js";import{G as U,p as Z,r as L,v as Q}from"./chunk-DE5EGVKG.js";import{d as N}from"./chunk-D6VMBA4C.js";import{a as b}from"./chunk-USBJFDJ6.js";import{b as ae}from"./chunk-ZD4O6NPV.js";import{a as ue}from"./chunk-K4NTZEDJ.js";import{h as H}from"./chunk-3XLHL5YT.js";import{b as J,c as Y}from"./chunk-X2TKJ7KR.js";import"./chunk-NW4GW47L.js";import{b as $}from"./chunk-CXT5IR5T.js";import{m as P}from"./chunk-VW7TLY3P.js";import"./chunk-WHC7AYZD.js";function Ee(e,n){return e||(C("PI_CACHE_RETENTION",n)==="long"?"long":"short")}function Le(e,n,t){let s=Ee(n,t);if(s==="none")return{retention:s};let i=s==="long"&&O(e).supportsLongCacheRetention?"1h":void 0;return{retention:s,cacheControl:{type:"ephemeral",...i&&{ttl:i}}}}var Pe="2.1.322",De=["Read","Write","Edit","Bash","Grep","Glob","AskUserQuestion","EnterPlanMode","ExitPlanMode","KillShell","NotebookEdit","Skill","Task","TaskOutput","TodoWrite","WebFetch","WebSearch"],Be=new Map(De.map(e=>[e.toLowerCase(),e])),V=e=>Be.get(e.toLowerCase())??e,He=(e,n)=>{if(n&&n.length>0){let t=e.toLowerCase(),s=n.find(i=>i.name.toLowerCase()===t);if(s)return s.name}return e};function z(e){return{type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}}}function Ue(e){if(!e.some(i=>i.type==="image"))return b(e.map(i=>i.text).join(`
5
+ `));let t=e.map(i=>i.type==="text"?{type:"text",text:b(i.text)}:z(i));return t.some(i=>i.type==="text")||t.unshift({type:"text",text:"(see attached image)"}),t}var Fe="fine-grained-tool-streaming-2025-05-14",je="interleaved-thinking-2025-05-14",We="server-side-fallback-2026-07-01",qe="mid-conversation-output-config-2026-07-01",Ge="thinking-binding-controls-2026-08-01",Ke="inline-tools-2026-09-15",Ve="message-threads-2026-08-12",ze={name:"__pi_deferred_placeholder__",description:"Reserved placeholder. Never available. Never call this.",input_schema:{type:"object",properties:{},required:[]},defer_loading:!0};function $e(e){return(e.compat?.allowedFallbackModels?.length??0)>0}function O(e){let n=e.provider==="openrouter"||e.baseUrl.includes("openrouter.ai");return{supportsEagerToolInputStreaming:e.compat?.supportsEagerToolInputStreaming??!0,supportsLongCacheRetention:e.compat?.supportsLongCacheRetention??!0,sendSessionAffinityHeaders:e.compat?.sendSessionAffinityHeaders??n,sessionAffinityFormat:e.compat?.sessionAffinityFormat??(n?"openrouter":void 0),supportsCacheControlOnTools:e.compat?.supportsCacheControlOnTools??!0,supportsTemperature:e.compat?.supportsTemperature??!0,allowEmptySignature:e.compat?.allowEmptySignature??!1,supportsStrictTools:e.compat?.supportsStrictTools??!1,supportsMidConvoSystemMessages:e.compat?.supportsMidConvoSystemMessages??!1,supportsMidConvoToolChanges:e.compat?.supportsMidConvoToolChanges??!1,supportsMessageThreads:e.compat?.supportsMessageThreads??e.baseUrl.includes("api.anthropic.com")}}var S=new Map,Je=1e4,Ye=new Set(["thread_not_found","thread_already_continued","thread_continue_in_flight","thread_fingerprint_mismatch"]);function Se(e,n){if(S.delete(e),S.set(e,n),S.size>Je){let t=S.keys().next().value;t!==void 0&&S.delete(t)}}te(e=>{e?S.delete(e):S.clear()});function Re(e,n,t){let{system:s,tools:i,thinking:a,output_config:c,tool_choice:r,betas:l,fallbacks:m}=n,u=JSON.stringify([e.provider,e.baseUrl,n.model,s,i,a,c,r,l,m]),d=JSON.stringify(t,(h,_)=>{if(h!=="cache_control")return h==="content"&&typeof _=="string"?[{type:"text",text:_}]:_});return ce(u+d)}function Ce(e,n){return{sessionId:e,body:{...n,thread:{type:"create"}}}}function Ze(e,n,t){let s=S.get(n);if(s!=="off"){if(s!==void 0&&t.messages.length>s.prefixCount&&Re(e,t,t.messages.slice(0,s.prefixCount))===s.prefixHash){S.delete(n);let{system:i,tools:a,...c}=t;return{body:{...c,messages:t.messages.slice(s.prefixCount),thread:{type:"continue",previous_message_id:s.replyId}},sessionId:n}}return Ce(n,t)}}function Qe(e){let t=e.error?.error?.details?.error_code;return typeof t=="string"?t:void 0}async function Xe(e,n,t,s,i){try{return{response:await t(e.body),thread:e}}catch(a){if(i?.aborted||!(a instanceof P.APIError))throw a;let c=Qe(a),r=c!==void 0&&Ye.has(c),l=c==="thread_unsupported_request"||c===void 0&&a.status===400&&a.message.includes("thread");if(!r&&!l)throw a;if(N(s,{type:"anthropic_thread_fallback",timestamp:Date.now(),error:{message:a.message},details:{reason:c??String(a.status)}}),r){let u=Ce(e.sessionId,n);return{response:await t(u.body),thread:u}}let m=await t(n);return Se(e.sessionId,"off"),{response:m,thread:void 0}}}function et(e,n,t,s,i,a){if(s.responseId===void 0||s.responseModel!==void 0)return;let c=Ne(j([s],e,Oe),i,void 0,a).messages.filter(l=>l.role==="assistant"),r=[...t.messages,...c];Se(n.sessionId,{prefixCount:r.length,prefixHash:Re(e,t,r),replyId:s.responseId})}function W(...e){let n={};for(let t of e)t&&Object.assign(n,t);return n}function q(e,n){if(!e)return!1;let t=n.toLowerCase();for(let[s,i]of Object.entries(e))if(s.toLowerCase()===t&&i!==null&&i.trim().length>0)return!0;return!1}function ve(e,n){return!!e||q(n,"authorization")||q(n,"x-api-key")||q(n,"cf-aig-authorization")}function Ie(e,n,t){if(!ve(n,t))throw new Error(`No API key for provider: ${e}`)}var M=class extends P{_shouldResolveDefaultCredentials(){return!1}};function Ae(e,n,t,s){if(e.provider!=="anthropic"||ve(n,t))return;let i=C(ne,s),a=C(se,s),c=C(oe,s);if(!(!i||!a||!c))return{organization_id:a,workspace_id:C(ie,s),authentication:{type:"oidc_federation",federation_rule_id:i,service_account_id:C(re,s),identity_token:{source:"file",path:c}}}}var D,tt=new Set(["message_start","message_delta","message_stop","content_block_start","content_block_delta","content_block_stop"]);function Me(e){if(!e.event&&e.data.length===0)return null;let n={event:e.event,data:e.data.join(`
6
+ `),raw:[...e.raw]};return e.event=null,e.data=[],e.raw=[],n}function G(e,n){if(e==="")return Me(n);if(n.raw.push(e),e.startsWith(":"))return null;let t=e.indexOf(":"),s=t===-1?e:e.slice(0,t),i=t===-1?"":e.slice(t+1);return i.startsWith(" ")&&(i=i.slice(1)),s==="event"?n.event=i:s==="data"&&n.data.push(i),null}function nt(e){let n=e.indexOf("\r"),t=e.indexOf(`
7
+ `);return n===-1?t:t===-1?n:Math.min(n,t)}function B(e){let n=nt(e);if(n===-1)return null;let t=n+1;return e[n]==="\r"&&e[t]===`
8
+ `&&(t+=1),{line:e.slice(0,n),rest:e.slice(t)}}async function*st(e,n){let t=e.getReader(),s=new TextDecoder,i={event:null,data:[],raw:[]},a="";try{for(;;){if(n?.aborted)throw new Error("Request was aborted");let{value:l,done:m}=await t.read();if(m)break;a+=s.decode(l,{stream:!0});let u=B(a);for(;u;){a=u.rest;let d=G(u.line,i);d&&(yield d),u=B(a)}}a+=s.decode();let c=B(a);for(;c;){a=c.rest;let l=G(c.line,i);l&&(yield l),c=B(a)}if(a.length>0){let l=G(a,i);l&&(yield l)}let r=Me(i);r&&(yield r)}finally{t.releaseLock()}}async function*rt(e,n){if(!e.body)throw new Error("Attempted to iterate over an Anthropic response with no body");let t=!1,s=!1;for await(let i of st(e.body,n)){if(i.event==="error")throw new Error(i.data);if(tt.has(i.event??""))try{let a=X(i.data);a.type==="message_start"?t=!0:a.type==="message_stop"&&(s=!0),yield a}catch(a){let c=a instanceof Error?a.message:String(a);throw new Error(`Could not parse Anthropic SSE event ${i.event}: ${c}; data=${i.data}; raw=${i.raw.join("\\n")}`)}}if(t&&!s)throw new Error("Anthropic stream ended before message_stop")}var K=(e,n,t)=>{let s=new $,i=O(e),a=Q(n,i.supportsMidConvoSystemMessages),c=L(a.messages);return(async()=>{let r={role:"assistant",content:[],api:e.api,provider:e.provider,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"pending",timestamp:Date.now()};try{let l,m,u=e,d,_=Ee(t?.cacheRetention,t?.env)==="none"?void 0:t?.sessionId,p=i.supportsMessageThreads?_:void 0;if(t?.client)l=t.client,m=!1;else{let o=t?.apiKey,f=Ae(e,o,t?.headers,t?.env);f||Ie(e.provider,o,t?.headers);let g;if(e.provider==="github-copilot"){let A=ge(a.messages);g=me({messages:a.messages,hasImages:A})}let y=at(e,o,t?.headers,t?.fetch,g,_,f,t?.identity);l=y.client,m=y.isOAuthToken}let x={...t?.signal?{signal:t.signal}:{},...t?.timeoutMs!==void 0?{timeout:t.timeoutMs}:{},maxRetries:0},k=o=>pe(()=>l.beta.messages.create(o,x).asResponse(),{maxRetries:t?.maxRetries,maxRetryDelayMs:t?.maxRetryDelayMs,signal:t?.signal}),v=be(t?.sessionId),R,w,T;for(;;){t?.signal?.throwIfAborted();let o=ut(e,a,m,t,{disablePreferredStrictTools:v,messageThreads:p!==void 0});o.providerThinkingLevel&&(r.providerThinkingLevel=o.providerThinkingLevel),w=o.params;let f=await t?.onPayload?.(w,e);f!==void 0&&(w={...f,stream:!0});let g=p!==void 0&&t?.disableContinuation!==!0?Ze(e,p,w):void 0;try{let y=g?await Xe(g,w,k,r,t?.signal):{response:await k(w),thread:void 0};R=y.response,T=y.thread;break}catch(y){if(t?.signal?.aborted||v||!o.hasPreferredStrictTools||!(y instanceof P.APIError)||y.status!==400||y.type!=="invalid_request_error"||!Te(y.message))throw y;v=!0,xe(t?.sessionId),N(r,{type:"anthropic_strict_tools_fallback",timestamp:Date.now(),error:{message:y.message},details:{reason:"strict_tool_limits_exceeded"}})}}await t?.onResponse?.({status:R.status,headers:ue(R.headers)},e),s.push({type:"start",partial:r});let E=new Map,I=o=>{let f=E.get(o);return f===void 0?void 0:{...f,block:r.content[f.contentIndex]}};for await(let o of rt(R,t?.signal))if(await t?.onProviderStreamEvent?.(o,e),o.type==="message_start"){r.responseId=o.message.id;let f=o.message.input_transformations;Array.isArray(f)&&(d=f);let g=o.message.model;g!==e.id&&(r.responseModel=g);let y=g===e.id?void 0:e.compat?.allowedFallbackModels?.find(A=>A.provider===e.provider&&A.model===g)?.cost;u=y?{...e,id:g,cost:y}:e,r.usage.input=o.message.usage.input_tokens||0,r.usage.output=o.message.usage.output_tokens||0,r.usage.cacheRead=o.message.usage.cache_read_input_tokens||0,r.usage.cacheWrite=o.message.usage.cache_creation_input_tokens||0,r.usage.cacheWrite1h=o.message.usage.cache_creation?.ephemeral_1h_input_tokens||0,r.usage.totalTokens=r.usage.input+r.usage.output+r.usage.cacheRead+r.usage.cacheWrite,U(u,r.usage)}else if(o.type==="content_block_start"){if(o.content_block.type==="fallback"){if(r.content.length>0)throw new Error("Anthropic performed an unsupported mid-output model fallback");continue}o.content_block.type==="text"?(r.content.push({type:"text",text:o.content_block.text??""}),E.set(o.index,{contentIndex:r.content.length-1}),s.push({type:"text_start",contentIndex:r.content.length-1,partial:r})):o.content_block.type==="thinking"?(r.content.push({type:"thinking",thinking:o.content_block.thinking??"",thinkingSignature:o.content_block.signature??""}),E.set(o.index,{contentIndex:r.content.length-1}),s.push({type:"thinking_start",contentIndex:r.content.length-1,partial:r})):o.content_block.type==="redacted_thinking"?(r.content.push({type:"thinking",thinking:"[Reasoning redacted]",thinkingSignature:o.content_block.data,redacted:!0}),E.set(o.index,{contentIndex:r.content.length-1}),s.push({type:"thinking_start",contentIndex:r.content.length-1,partial:r})):o.content_block.type==="tool_use"&&(r.content.push({type:"toolCall",id:o.content_block.id,name:m?He(o.content_block.name,c):o.content_block.name,arguments:o.content_block.input??{}}),E.set(o.index,{contentIndex:r.content.length-1,arguments:new ee}),s.push({type:"toolcall_start",contentIndex:r.content.length-1,partial:r}))}else if(o.type==="content_block_delta"){let f=I(o.index);o.delta.type==="text_delta"?f?.block.type==="text"&&(f.block.text+=o.delta.text,s.push({type:"text_delta",contentIndex:f.contentIndex,delta:o.delta.text,partial:r})):o.delta.type==="thinking_delta"?f?.block.type==="thinking"&&(f.block.thinking+=o.delta.thinking,s.push({type:"thinking_delta",contentIndex:f.contentIndex,delta:o.delta.thinking,partial:r})):o.delta.type==="input_json_delta"?f?.block.type==="toolCall"&&f.arguments!==void 0&&(f.block.arguments=f.arguments.append(o.delta.partial_json),s.push({type:"toolcall_delta",contentIndex:f.contentIndex,delta:o.delta.partial_json,partial:r})):o.delta.type==="signature_delta"&&f?.block.type==="thinking"&&(f.block.thinkingSignature=f.block.thinkingSignature||"",f.block.thinkingSignature+=o.delta.signature)}else if(o.type==="content_block_stop"){let f=I(o.index);if(E.delete(o.index),f){let{block:g,contentIndex:y}=f;g.type==="text"?s.push({type:"text_end",contentIndex:y,content:g.text,partial:r}):g.type==="thinking"?s.push({type:"thinking_end",contentIndex:y,content:g.thinking,partial:r}):g.type==="toolCall"&&f.arguments!==void 0&&(Object.assign(g,f.arguments.finish()),s.push({type:"toolcall_end",contentIndex:y,toolCall:g,partial:r}))}}else if(o.type==="message_delta"){let f=o.input_transformations;if(Array.isArray(f)&&(d=f),o.delta.stop_reason){r.rawStopReason=o.delta.stop_reason;let g=yt(o.delta.stop_reason,o.delta.stop_details);r.stopReason=g.stopReason,g.errorMessage&&(r.errorMessage=g.errorMessage)}if(o.usage){o.usage.input_tokens!=null&&(r.usage.input=o.usage.input_tokens),o.usage.output_tokens!=null&&(r.usage.output=o.usage.output_tokens),o.usage.cache_read_input_tokens!=null&&(r.usage.cacheRead=o.usage.cache_read_input_tokens),o.usage.cache_creation_input_tokens!=null&&(r.usage.cacheWrite=o.usage.cache_creation_input_tokens);let g=o.usage.cache_creation;g?.ephemeral_1h_input_tokens!=null&&(r.usage.cacheWrite1h=g.ephemeral_1h_input_tokens);let y=o.usage.output_tokens_details?.thinking_tokens;y!=null&&(r.usage.reasoning=y)}r.usage.totalTokens=r.usage.input+r.usage.output+r.usage.cacheRead+r.usage.cacheWrite,U(u,r.usage),le(e)&&o.usage&&de(r.usage,o.usage)}if(t?.signal?.aborted)throw new Error("Request was aborted");if(r.stopReason==="pending")throw new Error("Anthropic stream ended without a stop reason");if(r.stopReason==="aborted"||r.stopReason==="error")throw new Error(r.errorMessage||"An unknown error occurred");T&&et(e,T,w,r,m,i.allowEmptySignature),d&&d.length>0&&N(r,{type:"anthropic_input_transformations",timestamp:Date.now(),details:{transformations:d.map(o=>({type:o.type??void 0,path:o.path??void 0,reason:o.reason??void 0}))}}),s.push({type:"done",reason:r.stopReason,message:r}),s.end()}catch(l){r.stopReason=t?.signal?.aborted?"aborted":"error",r.errorMessage=l instanceof Error?ae(l):JSON.stringify(l),s.push({type:"error",reason:r.stopReason,error:r}),s.end()}})(),s};function ot(e,n){let t=n?e.thinkingLevelMap?.[n]:void 0;if(typeof t=="string")return t;switch(n){case"minimal":case"low":return"low";case"medium":return"medium";case"high":return"high";default:return"high"}}var Wt=(e,n,t)=>{Ae(e,t?.apiKey,t?.headers,t?.env)||Ie(e.provider,t?.apiKey,t?.headers);let s={...ye(e,n,t,t?.apiKey),toolChoice:t?.toolChoice};if(!t?.reasoning)return K(e,n,{...s,thinkingEnabled:!1});if(e.compat?.forceAdaptiveThinking===!0){let c=ot(e,t.reasoning);return K(e,n,{...s,thinkingEnabled:!0,effort:c})}let i=ke(s.maxTokens,e.maxTokens,t.reasoning,t.thinkingBudgets),a=_e(e,n,i.maxTokens);return K(e,n,{...s,maxTokens:a,thinkingEnabled:!0,thinkingBudgetTokens:Math.min(i.thinkingBudget,Math.max(0,a-1024))})};function it(e){return e.includes("sk-ant-oat")}function at(e,n,t,s,i,a,c,r){if(e.provider==="github-copilot")return{client:new M({apiKey:null,authToken:n??null,baseURL:e.baseUrl,dangerouslyAllowBrowser:!0,fetch:s,defaultHeaders:W(H(e,r),{accept:"application/json","anthropic-dangerous-direct-browser-access":"true"},e.headers,i,t)}),isOAuthToken:!1};if(n&&it(n))return{client:new M({apiKey:null,authToken:n,baseURL:e.baseUrl,dangerouslyAllowBrowser:!0,fetch:s,defaultHeaders:W({accept:"application/json","anthropic-dangerous-direct-browser-access":"true","user-agent":`claude-cli/${Pe}`,"x-app":"cli"},e.headers,t)}),isOAuthToken:!0};let l=O(e),m={};if(a&&l.sendSessionAffinityHeaders){let h=l.sessionAffinityFormat==="openrouter"?"x-session-id":"x-session-affinity";m[h]=a}let u=W(H(e,r),{accept:"application/json","anthropic-dangerous-direct-browser-access":"true"},m,e.headers,t);if(c){let h=JSON.stringify([e.baseUrl,c]);if(D?.key!==h||D.fetch!==s){let _=new M({apiKey:null,authToken:null,config:c,baseURL:e.baseUrl,dangerouslyAllowBrowser:!0,fetch:s});D={key:h,fetch:s,client:_}}return{client:D.client.withOptions({defaultHeaders:u}),isOAuthToken:!1}}return{client:new M({apiKey:n??null,authToken:null,baseURL:e.baseUrl,dangerouslyAllowBrowser:!0,fetch:s,defaultHeaders:u}),isOAuthToken:!1}}function ct(e,n,t,{isOAuthToken:s,nativeToolChanges:i,messageThreads:a}){let c;for(let l of[e.headers,t?.headers])for(let[m,u]of Object.entries(l??{}))m.toLowerCase()==="anthropic-beta"&&(c=u);if(c===null)return[];if(c!==void 0)return[...new Set(c.split(",").map(l=>l.trim()).filter(l=>l.length>0))];let r=[];return s&&r.push("claude-code-20250219","oauth-2025-04-20"),ft(e,n)&&r.push(Fe),e.reasoning&&t?.thinkingEnabled===!0&&(t.interleavedThinking??!0)&&e.compat?.forceAdaptiveThinking!==!0&&r.push(je),$e(e)&&r.push(We),e.compat?.supportsMidConvoEffort===!0&&r.push(qe,Ge),i&&r.push(Ke),a&&r.push(Ve),[...new Set(r)]}function ut(e,n,t,s,i){let{cacheControl:a}=Le(e,s?.cacheRetention,s?.env),c=O(e),r=Z(n.messages),l=r?J(r):"",m=j(n.messages,e,Oe),u=r?m.slice(1):m,d=!1,h=(o,f)=>{let g=_t(o,t,c.supportsEagerToolInputStreaming,c.supportsStrictTools,f,i.disablePreferredStrictTools);return g.some((y,A)=>y.strict===!0&&F(o[A]))&&(d=!0),g},_=r?.toolsAdded??[],p=c.supportsMidConvoSystemMessages&&c.supportsMidConvoToolChanges&&_.length>0,x=e.reasoning&&s?.thinkingEnabled===!1&&e.thinkingLevelMap?.off!==null,k=e.compat?.supportsMidConvoEffort===!0&&!x,v=Ne(u,t,a,c.allowEmptySignature,k?e.provider:void 0,p?h:void 0),R=s?.effort??"high",w=ct(e,n,s,{isOAuthToken:t,nativeToolChanges:p,messageThreads:i.messageThreads}),T={model:e.id,messages:k?pt(v,R):v.messages,max_tokens:s?.maxTokens??e.maxTokens,stream:!0,...w.length>0?{betas:w}:{}};t?(T.system=[{type:"text",text:"You are Claude Code, Anthropic's official CLI for Claude.",...a?{cache_control:a}:{}}],l&&T.system.push({type:"text",text:b(l),...a?{cache_control:a}:{}})):l&&(T.system=[{type:"text",text:b(l),...a?{cache_control:a}:{}}]),s?.temperature!==void 0&&!s?.thinkingEnabled&&e.compat?.supportsMidConvoEffort!==!0&&c.supportsTemperature&&(T.temperature=s.temperature);let E=c.supportsCacheControlOnTools?a:void 0;if(p)T.tools=[...h(_,E),ze];else{let o=L(n.messages);o.length>0&&(T.tools=h(o,E))}if(x)T.thinking={type:"disabled"};else if(k)T.thinking={type:"adaptive",display:s?.thinkingDisplay??"summarized",block_binding:{prefix_mismatch_behavior:"drop_block"}},T.output_config={effort:"low"};else if(e.reasoning&&s?.thinkingEnabled){let o=s.thinkingDisplay??"summarized";e.compat?.forceAdaptiveThinking===!0?(T.thinking={type:"adaptive",display:o},s.effort&&(T.output_config={effort:s.effort})):T.thinking={type:"enabled",budget_tokens:s.thinkingBudgetTokens||1024,display:o}}if(s?.metadata){let o=s.metadata.user_id;typeof o=="string"&&(T.metadata={user_id:o})}s?.toolChoice&&(typeof s.toolChoice=="string"?T.tool_choice={type:s.toolChoice}:T.tool_choice=s.toolChoice);let I=e.compat?.allowedFallbackModels;return I&&I.length>0&&(T.fallbacks=I.map(o=>({model:o.model}))),{params:T,hasPreferredStrictTools:d,providerThinkingLevel:k?R:void 0}}function Oe(e){return e.replace(/[^a-zA-Z0-9_-]/g,"_").slice(0,64)}function lt(e,n=e.content){return{type:"tool_result",tool_use_id:e.toolCallId,content:Ue(n),is_error:e.isError}}function Ne(e,n,t,s=!1,i,a){let c=[],r=new Map,l=[],m=()=>{c.push(...l),l.length=0};for(let u=0;u<e.length;u++){let d=e[u];if(d.role==="system"){let h=Y(d),_=[];if(h.length>0&&_.push({type:"text",text:b(h)}),a){let p=d.toolsAdded??[],x=new Set(p.map(k=>k.name));for(let k of d.toolsRemoved??[])x.has(k.name)||_.push({type:"tool_removal",tool:{type:"tool_reference",name:n?V(k.name):k.name}});for(let k of a(p))_.push({type:"tool_addition",tool:{type:"tool_definition",definition:k}})}_.length>0&&l.push({role:"system",content:_})}else if(d.role==="user")if(typeof d.content=="string")d.content.trim().length>0&&c.push({role:"user",content:b(d.content)});else{let _=d.content.map(p=>p.type==="text"?{type:"text",text:b(p.text)}:z(p)).filter(p=>p.type==="text"?p.text.trim().length>0:!0);if(_.length===0)continue;c.push({role:"user",content:_})}else if(d.role==="assistant"){let h=[];for(let p of d.content)if(p.type==="text"){if(p.text.trim().length===0)continue;h.push({type:"text",text:b(p.text)})}else if(p.type==="thinking"){if(p.redacted){h.push({type:"redacted_thinking",data:p.thinkingSignature});continue}let x=p.thinkingSignature,k=!!x&&x.trim().length>0;if(p.thinking.trim().length===0&&!k)continue;k?h.push({type:"thinking",thinking:b(p.thinking),signature:x}):h.push(s?{type:"thinking",thinking:b(p.thinking),signature:""}:{type:"text",text:b(p.thinking)})}else p.type==="toolCall"&&h.push({type:"tool_use",id:p.id,name:n?V(p.name):p.name,input:p.arguments??{}});if(h.length===0)continue;m();let _=c.length;c.push({role:"assistant",content:h}),i!==void 0&&d.api==="anthropic-messages"&&d.provider===i&&dt(d.providerThinkingLevel)&&r.set(_,d.providerThinkingLevel)}else if(d.role==="toolResult"){let h=[],_=[],p=u;for(;p<e.length&&e[p].role==="toolResult";){let x=e[p],k=we(x);h.push(lt(x,k?.content)),k&&_.push({type:"text",text:k.caption},...k.images.map(z)),p++}u=p-1,c.push({role:"user",content:[...h,..._]})}}if(m(),t&&c.length>0){let u=c[c.length-1];if(u.role==="user"||u.role==="system")if(Array.isArray(u.content)){let d=u.content[u.content.length-1];d&&(d.type==="text"||d.type==="image"||d.type==="tool_result"||d.type==="tool_addition"||d.type==="tool_removal")&&(d.cache_control=t)}else typeof u.content=="string"&&(u.content=[{type:"text",text:u.content,cache_control:t}])}return{messages:c,assistantLevels:r}}function dt(e){return e==="low"||e==="medium"||e==="high"||e==="xhigh"||e==="max"}function pt(e,n){let t=[];for(let s=0;s<e.messages.length;s++){let i=e.assistantLevels.get(s);i!==void 0&&t.push({role:"system",content:[],output_config:{effort:i}}),t.push(e.messages[s])}return t.push({role:"system",content:[],output_config:{effort:n}}),t}function ft(e,n){return L(n.messages).length>0&&!O(e).supportsEagerToolInputStreaming}var ht=new Set(["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf","maxItems","uniqueItems","minContains","maxContains","minProperties","maxProperties"]),gt=new Set(["date-time","time","date","duration","email","hostname","uri","ipv4","ipv6","uuid"]),mt=(e,n)=>ht.has(e)?!0:e==="minItems"?n!==0&&n!==1:e==="format"?typeof n!="string"||!gt.has(n):!1;function _t(e,n,t,s,i,a=!1){return e?e.map((c,r)=>{let l=a&&F(c)?void 0:he(c,s,mt),m=fe(c,l),u=m,d={type:"object",properties:u.properties??{},required:u.required??[],...u.additionalProperties===void 0?{}:{additionalProperties:u.additionalProperties},...u.$defs===void 0?{}:{$defs:u.$defs},...u.definitions===void 0?{}:{definitions:u.definitions}},h=l===!0?{...m,...d}:d;return{name:n?V(c.name):c.name,description:c.description,...t?{eager_input_streaming:!0}:{},...l===!0?{strict:!0}:{},input_schema:h,...i&&r===e.length-1?{cache_control:i}:{}}}):[]}function yt(e,n){switch(e){case"end_turn":return{stopReason:"stop"};case"max_tokens":return{stopReason:"length"};case"tool_use":return{stopReason:"toolUse"};case"refusal":return{stopReason:"error",errorMessage:n?.explanation||"The model refused to complete the request"};case"pause_turn":return{stopReason:"stop"};case"stop_sequence":return{stopReason:"stop"};case"sensitive":return{stopReason:"error",errorMessage:"Provider stopped with: sensitive"};default:throw new Error(`Unhandled stop reason: ${e}`)}}export{K as stream,Wt as streamSimple};
@@ -0,0 +1,4 @@
1
+ import { createRequire as __cortexCreateRequire } from 'node:module';
2
+ const require = __cortexCreateRequire(import.meta.url);
3
+ const __cortexPackageRoot = new URL("../../", import.meta.url);
4
+ import{a as P,c as C}from"./chunk-ZNZFWSPH.js";import{a as _,b as k,c as x,d as z}from"./chunk-FE7HH5JS.js";import{a as b}from"./chunk-XIECJESP.js";import{b as I}from"./chunk-4SWD4JMP.js";import"./chunk-V3AQJSWR.js";import"./chunk-BWDJS6A4.js";import"./chunk-6R73ICDB.js";import{a as w}from"./chunk-23PRJECN.js";import{h as d,j as E,k as O}from"./chunk-7TYSMLUV.js";import{C as R,I as T,v,z as l}from"./chunk-DE5EGVKG.js";import"./chunk-D6VMBA4C.js";import"./chunk-USBJFDJ6.js";import{a as M,c as A}from"./chunk-ZD4O6NPV.js";import{a as S}from"./chunk-K4NTZEDJ.js";import{h as y}from"./chunk-3XLHL5YT.js";import"./chunk-X2TKJ7KR.js";import"./chunk-NW4GW47L.js";import{b as h}from"./chunk-CXT5IR5T.js";import"./chunk-WHC7AYZD.js";var N=new Set(["openai","openai-codex","opencode","azure"]),G=16;function K(r){return A(M(r),"Azure OpenAI API error")}var D=(r,a,e)=>{let t=new h,p=v(a,r.compat?.supportsMidConvoSystemMessages);return(async()=>{let n=P(r,e),s={role:"assistant",content:[],api:"azure-openai-responses",provider:r.provider,model:r.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"pending",timestamp:Date.now()};try{let i=e?.apiKey;if(!i)throw new Error(`No API key for provider: ${r.provider}`);let u=q(r,i,e),o=d(l(p.messages),r.compat?.supportsOpenAIGrammarTools??!1),m=U(r,p,e,n,o),c=await e?.onPayload?.(m,r);c!==void 0&&(m=c);let f={...e?.signal?{signal:e.signal}:{},...e?.timeoutMs!==void 0?{timeout:e.timeoutMs}:{},maxRetries:0},{data:L,response:g}=await w(()=>u.responses.create(m,f).withResponse(),{maxRetries:e?.maxRetries,maxRetryDelayMs:e?.maxRetryDelayMs,signal:e?.signal});if(await e?.onResponse?.({status:g.status,headers:S(g.headers)},r),t.push({type:"start",partial:s}),await z(L,s,t,r,{onProviderStreamEvent:e?.onProviderStreamEvent,grammarToolInputProperties:o}),e?.signal?.aborted)throw new Error("Request was aborted");if(s.stopReason==="pending")throw new Error("Azure OpenAI Responses stream ended without a stop reason");if(s.stopReason==="aborted"||s.stopReason==="error")throw new Error(s.errorMessage||"An unknown error occurred");t.push({type:"done",reason:s.stopReason,message:s}),t.end()}catch(i){s.stopReason=e?.signal?.aborted?"aborted":"error",s.errorMessage=K(i),t.push({type:"error",reason:s.stopReason,error:s}),t.end()}})(),t},re=(r,a,e)=>{let t=e?.apiKey;if(!t)throw new Error(`No API key for provider: ${r.provider}`);let p={...O(r,a,e,t),toolChoice:e?.toolChoice},n=e?.reasoning?T(r,e.reasoning):void 0;return D(r,a,{...p,reasoningEffort:n==="off"?void 0:n})};function q(r,a,e){let t={...y(r,e?.identity),...r.headers};e?.headers&&Object.assign(t,e.headers);let{baseUrl:p,apiVersion:n}=C(r,e);return new I({apiKey:a,apiVersion:n,dangerouslyAllowBrowser:!0,fetch:e?.fetch,defaultHeaders:t,baseURL:p})}function U(r,a,e,t,p=d(l(a.messages),r.compat?.supportsOpenAIGrammarTools??!1)){let n=r.compat?.supportsAdditionalTools??!1,s=r.compat?.supportsToolSearch??!1,i=R(a.messages,_({supportsMidConvoSystemMessages:r.compat?.supportsMidConvoSystemMessages??!1,supportsAdditionalTools:n,supportsToolSearch:s})),u=k(r,a,N,{grammarToolInputProperties:p,supportsMidConvoSystemMessages:r.compat?.supportsMidConvoSystemMessages??!1,supportsAdditionalTools:n,supportsToolSearch:s,toolOptions:{supportsStrictMode:r.compat?.supportsStrictMode??!0,supportsOpenAIGrammarTools:r.compat?.supportsOpenAIGrammarTools??!1}}),o={model:t,input:u,stream:!0,prompt_cache_key:r.compat?.promptCacheKeyMode==="disabled"?void 0:b(e?.sessionId),store:!1};e?.maxTokens&&(o.max_output_tokens=Math.max(e.maxTokens,G)),e?.temperature!==void 0&&(o.temperature=e?.temperature),i.requestTools.length>0&&(o.tools=x(i.requestTools,{supportsStrictMode:r.compat?.supportsStrictMode??!0,supportsOpenAIGrammarTools:r.compat?.supportsOpenAIGrammarTools??!1})),e?.toolChoice!==void 0&&(o.tool_choice=e.toolChoice);let m=e?.reasoningEffort??(e?.reasoningSummary?"medium":void 0);if(r.reasoning)if(m){let f=e?.reasoningEffort?r.thinkingLevelMap?.[e.reasoningEffort]??e.reasoningEffort:m;o.reasoning={effort:f,summary:e?.reasoningSummary||"auto"},o.include=["reasoning.encrypted_content"]}else r.thinkingLevelMap?.off!==null&&(o.reasoning={effort:r.thinkingLevelMap?.off??"none"});let c=E(r,m??"off",e?.samplingParams);return c&&Object.assign(o,c),o}export{D as stream,re as streamSimple};