@cortex-agent/server 2026.10.27 → 2026.11.17

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 (258) hide show
  1. package/LICENSE +255 -21
  2. package/README.md +54 -7
  3. package/THIRD_PARTY_NOTICES.txt +1109 -278
  4. package/defaults/hooks/cortex-hook-api.mjs +2 -1
  5. package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +23 -15
  6. package/dist/agent-adapter/claude/remote-mcp-proxy.js +1 -1
  7. package/dist/chunks/{anthropic-messages-M3SMXACA.js → anthropic-messages-M732OMEE.js} +1 -1
  8. package/dist/chunks/{azure-openai-responses-76YWXHSB.js → azure-openai-responses-RAKTV6JY.js} +1 -1
  9. package/dist/chunks/bedrock-converse-stream-WNUGNZ27.js +62 -0
  10. package/dist/chunks/bowser-MLGGLXTZ.js +20 -0
  11. package/dist/chunks/child-runner-MO5RT6FH.js +4 -0
  12. package/dist/chunks/chunk-2ATTYCRJ.js +4 -0
  13. package/dist/chunks/{chunk-PXS5SHOV.js → chunk-2ROGTDM2.js} +1 -1
  14. package/dist/chunks/chunk-2VVRTJQN.js +4 -0
  15. package/dist/chunks/{chunk-OZGBWAT2.js → chunk-2YTYYG4K.js} +1 -1
  16. package/dist/chunks/chunk-3CPIMAYX.js +30 -0
  17. package/dist/chunks/{chunk-FXDIR3SQ.js → chunk-3CZPBLB3.js} +1 -1
  18. package/dist/chunks/chunk-3ORG56I5.js +8 -0
  19. package/dist/chunks/{chunk-LEUENXI2.js → chunk-4YLAGSDM.js} +1 -1
  20. package/dist/chunks/{chunk-HU6UIDEJ.js → chunk-53TQNK7Z.js} +1 -1
  21. package/dist/chunks/{chunk-4U7XXM4W.js → chunk-5A6CA5TM.js} +1 -1
  22. package/dist/chunks/{chunk-PBJ5MPPX.js → chunk-5DF5WJNM.js} +1 -1
  23. package/dist/chunks/chunk-5PAW3DEU.js +50 -0
  24. package/dist/chunks/{chunk-DXBSQXJL.js → chunk-7GAYFN52.js} +1 -1
  25. package/dist/chunks/chunk-7GEBDPTT.js +4 -0
  26. package/dist/chunks/{chunk-NR6U3WIZ.js → chunk-AFTBQRPN.js} +1 -1
  27. package/dist/chunks/chunk-AVXDF7AG.js +4 -0
  28. package/dist/chunks/chunk-BDLKI2NT.js +4 -0
  29. package/dist/chunks/{chunk-P52RMIYX.js → chunk-BJGYGEZO.js} +1 -1
  30. package/dist/chunks/chunk-BUZQBTV2.js +10 -0
  31. package/dist/chunks/chunk-BZDIAI5M.js +125 -0
  32. package/dist/chunks/{chunk-A34TDMIC.js → chunk-CEGSDGYQ.js} +1 -1
  33. package/dist/chunks/{chunk-Q7CE3UIE.js → chunk-CK3P345X.js} +69 -69
  34. package/dist/chunks/{chunk-YAEVYJAR.js → chunk-EE3WT25T.js} +1 -1
  35. package/dist/chunks/chunk-ETIBCA2S.js +4 -0
  36. package/dist/chunks/{chunk-REBNWCKI.js → chunk-FP7ML72L.js} +1 -1
  37. package/dist/chunks/{chunk-H2FP6DG4.js → chunk-H4QZ2P3Z.js} +1 -1
  38. package/dist/chunks/chunk-IA6IODY3.js +4 -0
  39. package/dist/chunks/{chunk-D3NXKK2L.js → chunk-IKLTEWA3.js} +1 -1
  40. package/dist/chunks/chunk-IYVZHGUQ.js +5 -0
  41. package/dist/chunks/chunk-JJDEQ6N2.js +4 -0
  42. package/dist/chunks/chunk-JKL3AK5D.js +106 -0
  43. package/dist/chunks/chunk-KDPY2YA3.js +129 -0
  44. package/dist/chunks/{chunk-SUFW24P4.js → chunk-KUDK7GPS.js} +1 -1
  45. package/dist/chunks/chunk-LAWOWPZX.js +363 -0
  46. package/dist/chunks/chunk-LEAV3FFG.js +4 -0
  47. package/dist/chunks/chunk-LP72AF56.js +45 -0
  48. package/dist/chunks/{chunk-KENCMLRE.js → chunk-LP7T32PW.js} +1 -1
  49. package/dist/chunks/chunk-LQTFDC67.js +4 -0
  50. package/dist/chunks/{chunk-HALUQ7ZF.js → chunk-MGYYSX7Y.js} +1 -1
  51. package/dist/chunks/chunk-NNBSSISP.js +4 -0
  52. package/dist/chunks/chunk-NNTQUHLO.js +877 -0
  53. package/dist/chunks/{chunk-PFMEUFJ7.js → chunk-NRD57ICT.js} +1 -1
  54. package/dist/chunks/{chunk-QWAQHHRS.js → chunk-NXZS5PEW.js} +1 -1
  55. package/dist/chunks/chunk-OFEPDNRB.js +4 -0
  56. package/dist/chunks/{chunk-6LZK4DDH.js → chunk-P7TVR4GY.js} +1 -1
  57. package/dist/chunks/chunk-QEL6CMLE.js +4 -0
  58. package/dist/chunks/chunk-QMSSIDRQ.js +70 -0
  59. package/dist/chunks/chunk-QUXPMNFQ.js +4 -0
  60. package/dist/chunks/chunk-R52AVUQB.js +5 -0
  61. package/dist/chunks/chunk-R6CGBSTC.js +22 -0
  62. package/dist/chunks/chunk-RA2BUYI3.js +6 -0
  63. package/dist/chunks/chunk-RDW6FRF5.js +4 -0
  64. package/dist/chunks/chunk-RF4JLYBX.js +6 -0
  65. package/dist/chunks/{chunk-YPK2CAIZ.js → chunk-ROVKOIHF.js} +1 -1
  66. package/dist/chunks/chunk-RYLSRII6.js +7 -0
  67. package/dist/chunks/{chunk-XNSSUVT6.js → chunk-S3MR37DL.js} +1 -1
  68. package/dist/chunks/chunk-SAJD4EKE.js +10 -0
  69. package/dist/chunks/chunk-SFX7V5O2.js +10 -0
  70. package/dist/chunks/chunk-STCNHXPJ.js +6 -0
  71. package/dist/chunks/{chunk-FOJQXLL2.js → chunk-SY2HV3V5.js} +1 -1
  72. package/dist/chunks/chunk-T73GHMFB.js +4 -0
  73. package/dist/chunks/chunk-TKFFQNAP.js +19 -0
  74. package/dist/chunks/chunk-TMV2ZDOI.js +18 -0
  75. package/dist/chunks/chunk-TX46YMGI.js +5 -0
  76. package/dist/chunks/chunk-U23S37TT.js +6 -0
  77. package/dist/chunks/chunk-UT6DGZDO.js +4 -0
  78. package/dist/chunks/{chunk-JERCOLY3.js → chunk-V35MFAUQ.js} +4 -6
  79. package/dist/chunks/chunk-V6X7Y62J.js +7 -0
  80. package/dist/chunks/chunk-V7K3KNDM.js +4 -0
  81. package/dist/chunks/{chunk-NAA7GF6Q.js → chunk-VBN2JSER.js} +1 -1
  82. package/dist/chunks/chunk-VIMHSW6J.js +4 -0
  83. package/dist/chunks/chunk-VK5J556O.js +4 -0
  84. package/dist/chunks/chunk-VPVSKJGX.js +6 -0
  85. package/dist/chunks/chunk-VTL3Z2OP.js +23 -0
  86. package/dist/chunks/{chunk-X2GYYRVM.js → chunk-VW7TLY3P.js} +1 -1
  87. package/dist/chunks/chunk-W34AK4SK.js +65 -0
  88. package/dist/chunks/chunk-W6AKCEYF.js +8 -0
  89. package/dist/chunks/chunk-WBSE3EF3.js +27 -0
  90. package/dist/chunks/chunk-WZYS2HAK.js +4 -0
  91. package/dist/chunks/{chunk-UNVEZI57.js → chunk-XEBEWR6Y.js} +1 -1
  92. package/dist/chunks/chunk-XPPZ6Y3X.js +8 -0
  93. package/dist/chunks/chunk-XYSXL3KX.js +4 -0
  94. package/dist/chunks/chunk-YAAKL3QS.js +80 -0
  95. package/dist/chunks/chunk-YB5LUJHS.js +65 -0
  96. package/dist/chunks/chunk-Z24SBRJK.js +4 -0
  97. package/dist/chunks/cloudflare-workers-ai-system-one-32JCFHI3.js +1 -1
  98. package/dist/chunks/context-GQKWKFRM.js +4 -0
  99. package/dist/chunks/cost-OOO32GLC.js +5 -0
  100. package/dist/chunks/dist-V5FRMUFH.js +4 -0
  101. package/dist/chunks/easter-egg-3d-CZH7AYZ7.js +4 -0
  102. package/dist/chunks/{event-streams-3JSFPOTZ.js → event-streams-AVE4MSS6.js} +1 -1
  103. package/dist/chunks/execution-repo-XXL4FXC6.js +4 -0
  104. package/dist/chunks/{executions-6ARGR3IO.js → executions-BN6OLLVM.js} +1 -1
  105. package/dist/chunks/file-H572PL2Z.js +4 -0
  106. package/dist/chunks/google-generative-ai-2G4ITOZL.js +4 -0
  107. package/dist/chunks/google-vertex-PACHCMRZ.js +4 -0
  108. package/dist/chunks/init-75F4V7SK.js +4 -0
  109. package/dist/chunks/{install-cli-4IZCSDFZ.js → install-cli-ABBD7DO5.js} +1 -1
  110. package/dist/chunks/{interaction-ask-G5T3H3CG.js → interaction-ask-EE2UPR3Q.js} +1 -1
  111. package/dist/chunks/{interaction-plan-E5V42MUP.js → interaction-plan-C446T2GZ.js} +1 -1
  112. package/dist/chunks/{llama-cpp-classify-OTXZWCMW.js → llama-cpp-classify-IA2F2H7A.js} +1 -1
  113. package/dist/chunks/local-client-stop-5YOLXGYT.js +4 -0
  114. package/dist/chunks/memory-cli-5SSF6YJM.js +11 -0
  115. package/dist/chunks/{mistral-conversations-34F66L3O.js → mistral-conversations-VHP63CDS.js} +1 -1
  116. package/dist/chunks/{model-resolver-N3DTAQ2S.js → model-resolver-FVJNZ6NA.js} +1 -1
  117. package/dist/chunks/{node-PTK2HCDV.js → node-DAO3SX7O.js} +1 -1
  118. package/dist/chunks/{openai-codex-2REL6UQU.js → openai-codex-JULCKICT.js} +1 -1
  119. package/dist/chunks/{openai-codex-responses-ZBVHREB3.js → openai-codex-responses-EHJ4AZBE.js} +1 -1
  120. package/dist/chunks/{openai-completions-VVIB26SH.js → openai-completions-CRAGQFCE.js} +1 -1
  121. package/dist/chunks/{openai-decisions-2N6ZRPZC.js → openai-decisions-P5UX7BWY.js} +1 -1
  122. package/dist/chunks/{openai-responses-735XA2ZX.js → openai-responses-IZ22NVQ7.js} +1 -1
  123. package/dist/chunks/{openrouter-images-3IKETHAC.js → openrouter-images-W2JAMSRH.js} +1 -1
  124. package/dist/chunks/{pi-messages-I3E4ZFHA.js → pi-messages-MJEEQU2R.js} +1 -1
  125. package/dist/chunks/{radius-HXRZVBDB.js → radius-ZM7ZRMXF.js} +1 -1
  126. package/dist/chunks/{remote-ops-BALZYKH6.js → remote-ops-O5CR4RGA.js} +1 -1
  127. package/dist/chunks/runner-S6R3US24.js +4 -0
  128. package/dist/chunks/schedule-cli-4T4YC5V5.js +4 -0
  129. package/dist/chunks/slack-2CGM4SMY.js +4 -0
  130. package/dist/chunks/start-ui-http-3D7QNHGB.js +43 -0
  131. package/dist/chunks/subagent-OZGUOV3J.js +4 -0
  132. package/dist/chunks/{time-KEHDQT6K.js → time-P6PE52WL.js} +1 -1
  133. package/dist/chunks/tool-shims-IA2WELXJ.js +4 -0
  134. package/dist/chunks/typesafe-system-one-6ULACYD4.js +1 -1
  135. package/dist/chunks/ui-board-H4INJD6C.js +5 -0
  136. package/dist/chunks/ui-decision-6HHNROIT.js +4 -0
  137. package/dist/chunks/{ui-file-GVH53O3X.js → ui-file-6PLXHSTB.js} +1 -1
  138. package/dist/chunks/ui-view-6MDU4GXY.js +4 -0
  139. package/dist/chunks/virtual-modules-OFI7QKYH.js +4 -0
  140. package/dist/chunks/waitpoint-W5M3BE55.js +5 -0
  141. package/dist/chunks/workers-GTFP75MS.js +4 -0
  142. package/dist/client-bundle/client.mjs +44 -31
  143. package/dist/client-bundle/manifest.json +2 -2
  144. package/dist/core/pi-sdk.js +1 -1
  145. package/dist/domain/auth/cc-auth-cli.js +1 -1
  146. package/dist/domain/mcp/bundled-server.js +1 -1
  147. package/dist/domain/mcp/feishu/client.js +4 -0
  148. package/dist/entry/app.js +201 -191
  149. package/dist/entry/browser-cli.js +10 -10
  150. package/dist/entry/cli.js +1 -1
  151. package/dist/entry/cortex-cli.js +1 -1
  152. package/dist/entry/daemon.js +4 -4
  153. package/dist/entry/hook-cli.js +2 -2
  154. package/dist/entry/production-app-bootstrap.js +1 -1
  155. package/dist/entry/production-evidence-export-cli.js +1 -1
  156. package/dist/entry/signal-cli.js +2 -2
  157. package/dist/tui/index.js +41 -41
  158. package/package.json +3 -3
  159. package/vendor/pi/dist/core/extensions/loader.js +1 -1
  160. package/vendor/pi/dist/extensions/codemode/execute.js +1 -1
  161. package/vendor/pi-ai/bedrock.js +1 -1
  162. package/vendor/pi-ai/oauth-load.js +1 -1
  163. package/web/dist/assets/{board-math-css-BmiXB1z5.js → board-math-css-BgIyUG-C.js} +1 -1
  164. package/web/dist/assets/index-9lyu2S6W.css +1 -0
  165. package/web/dist/assets/index-C-hpzey7.js +532 -0
  166. package/web/dist/assets/{index-XBRXpnC5.js → index-C2eMpcuI.js} +1 -1
  167. package/web/dist/assets/pdf-worker-DdZgk2mV.js +57 -0
  168. package/web/dist/assets/pdf.worker.min-Bz_KHX45.js +55 -0
  169. package/web/dist/index.html +2 -2
  170. package/web/dist/theme.css +22 -0
  171. package/dist/chunks/api-GM53PHIL-GFHEXXE6.js +0 -4
  172. package/dist/chunks/bedrock-converse-stream-5UPX4NTQ.js +0 -58
  173. package/dist/chunks/child-runner-3GHOWGZP.js +0 -4
  174. package/dist/chunks/chunk-2ZNLUY2U.js +0 -128
  175. package/dist/chunks/chunk-3F6WW7HR.js +0 -13
  176. package/dist/chunks/chunk-3OKHUVEM.js +0 -7
  177. package/dist/chunks/chunk-3THJYAEF.js +0 -4
  178. package/dist/chunks/chunk-3YHOCPQU.js +0 -10
  179. package/dist/chunks/chunk-4LLH5OWM.js +0 -10
  180. package/dist/chunks/chunk-52T37Y47.js +0 -8
  181. package/dist/chunks/chunk-7MU2AKNM.js +0 -4
  182. package/dist/chunks/chunk-AAA3UBIS.js +0 -4
  183. package/dist/chunks/chunk-ASYQHJVQ.js +0 -9
  184. package/dist/chunks/chunk-BGVHA2D4.js +0 -4
  185. package/dist/chunks/chunk-BKHDWCRT.js +0 -79
  186. package/dist/chunks/chunk-CQLH4UVX.js +0 -4
  187. package/dist/chunks/chunk-D6UA4BZC.js +0 -19
  188. package/dist/chunks/chunk-DGMNI4AO.js +0 -4
  189. package/dist/chunks/chunk-DHSA5ACV.js +0 -125
  190. package/dist/chunks/chunk-DPQPXBTP.js +0 -68
  191. package/dist/chunks/chunk-E7ZMYIY6.js +0 -30
  192. package/dist/chunks/chunk-EQITBTJC.js +0 -10
  193. package/dist/chunks/chunk-EXJA5RIX.js +0 -357
  194. package/dist/chunks/chunk-FH74NME3.js +0 -115
  195. package/dist/chunks/chunk-FOQ7VLIL.js +0 -17
  196. package/dist/chunks/chunk-J5DVLUKY.js +0 -6
  197. package/dist/chunks/chunk-JW2HFMTF.js +0 -4
  198. package/dist/chunks/chunk-KIGMAATV.js +0 -23
  199. package/dist/chunks/chunk-KIU5FAPY.js +0 -5
  200. package/dist/chunks/chunk-KIWMQPH7.js +0 -739
  201. package/dist/chunks/chunk-LMSQZ6TQ.js +0 -4
  202. package/dist/chunks/chunk-MEPASGPP.js +0 -6
  203. package/dist/chunks/chunk-MFAEUHMV.js +0 -28
  204. package/dist/chunks/chunk-NKDMKRSB.js +0 -68
  205. package/dist/chunks/chunk-NKXV32S6.js +0 -4
  206. package/dist/chunks/chunk-NVX5IPRN.js +0 -4
  207. package/dist/chunks/chunk-O3JW2F7D.js +0 -8
  208. package/dist/chunks/chunk-OISO5JXB.js +0 -4
  209. package/dist/chunks/chunk-OPYXNSMY.js +0 -4
  210. package/dist/chunks/chunk-PZMXHA6X.js +0 -9
  211. package/dist/chunks/chunk-QEOFEETJ.js +0 -4
  212. package/dist/chunks/chunk-REPYBMQS.js +0 -4
  213. package/dist/chunks/chunk-TAWLERZA.js +0 -4
  214. package/dist/chunks/chunk-TWAEABGG.js +0 -52
  215. package/dist/chunks/chunk-TZFLHVOQ.js +0 -7
  216. package/dist/chunks/chunk-UD3NMUHR.js +0 -12
  217. package/dist/chunks/chunk-W25TB3PU.js +0 -4
  218. package/dist/chunks/chunk-W5LGYSPZ.js +0 -4
  219. package/dist/chunks/chunk-XAJLZR7C.js +0 -28
  220. package/dist/chunks/chunk-XH6FMP3N.js +0 -71
  221. package/dist/chunks/chunk-XSRZHN63.js +0 -4
  222. package/dist/chunks/chunk-YG7OEPR2.js +0 -6
  223. package/dist/chunks/chunk-YHIWOGVL.js +0 -4
  224. package/dist/chunks/chunk-YZSHTWNM.js +0 -92
  225. package/dist/chunks/chunk-Z4H3VDHI.js +0 -4
  226. package/dist/chunks/client-XOGYH5UR.js +0 -4
  227. package/dist/chunks/config-DJSQI77S-335IXHSM.js +0 -4
  228. package/dist/chunks/context-VCQH5OB6.js +0 -4
  229. package/dist/chunks/cost-PGGFI7QJ.js +0 -5
  230. package/dist/chunks/dist-PUKMZ7GW.js +0 -4
  231. package/dist/chunks/easter-egg-3d-MO4MOEVF.js +0 -4
  232. package/dist/chunks/es5-VNTQPCKX.js +0 -4
  233. package/dist/chunks/execution-repo-ZLJTBWFC.js +0 -4
  234. package/dist/chunks/file-7BN7RCAY.js +0 -4
  235. package/dist/chunks/gateway-UCRPMR75.js +0 -36
  236. package/dist/chunks/google-generative-ai-2VXWLHWI.js +0 -4
  237. package/dist/chunks/google-vertex-UA36QP2U.js +0 -4
  238. package/dist/chunks/init-HA7FAQ73.js +0 -4
  239. package/dist/chunks/local-client-stop-SQRU7ZZM.js +0 -4
  240. package/dist/chunks/memory-cli-PYOILNN5.js +0 -11
  241. package/dist/chunks/models-L5VF4I5O-XXNJYQMQ.js +0 -4
  242. package/dist/chunks/runner-PLVZDGHB.js +0 -4
  243. package/dist/chunks/schedule-cli-OLASBBYJ.js +0 -4
  244. package/dist/chunks/slack-WAGSPZUX.js +0 -4
  245. package/dist/chunks/start-ui-http-QALT7C3P.js +0 -43
  246. package/dist/chunks/subagent-E3UC7ZHC.js +0 -4
  247. package/dist/chunks/tool-shims-Q6P6UXVC.js +0 -4
  248. package/dist/chunks/ui-board-4GYW6KKW.js +0 -5
  249. package/dist/chunks/ui-decision-U2FXSEC2.js +0 -4
  250. package/dist/chunks/ui-view-O7PLANT7.js +0 -4
  251. package/dist/chunks/virtual-modules-IDC5YKZJ.js +0 -4
  252. package/dist/chunks/waitpoint-2FGQBIAC.js +0 -5
  253. package/dist/chunks/workers-XN4PSTH6.js +0 -4
  254. package/vendor/aistatus/gateway-cli.js +0 -21
  255. package/web/dist/assets/index-DqWMdMkh.css +0 -1
  256. package/web/dist/assets/index-btKNdkvc.js +0 -525
  257. package/web/dist/assets/pdf-worker-Hp15W1QJ.js +0 -57
  258. 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({
@@ -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
@@ -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-VBN2JSER.js";import{b as a}from"../../chunks/chunk-NXZS5PEW.js";import"../../chunks/chunk-Z24SBRJK.js";import"../../chunks/chunk-VPVSKJGX.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};
@@ -1,7 +1,7 @@
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{d as Z,e as Q,f as X,g as ee,h as te}from"./chunk-KDYEGGMW.js";import{a as ie,b as ae}from"./chunk-BGYR4ID3.js";import{a as se}from"./chunk-23PRJECN.js";import{a as oe,d as re,g as ce,i as le,m as ue,n as pe,o as de}from"./chunk-QBKCAIJG.js";import{J as L,o as K,p as V,s as G,u as E,y as J}from"./chunk-PZMGBKUR.js";import{a as w}from"./chunk-6R73ICDB.js";import{b as z,c as $,d as Y}from"./chunk-SKHLZ6XY.js";import{d as O}from"./chunk-D6VMBA4C.js";import{a as T}from"./chunk-USBJFDJ6.js";import{a as ne}from"./chunk-K4NTZEDJ.js";import{h as N}from"./chunk-6AKUD3CF.js";import"./chunk-OSEIQ7SS.js";import{b as q}from"./chunk-CXT5IR5T.js";import{m as P}from"./chunk-X2GYYRVM.js";import"./chunk-WHC7AYZD.js";function fe(e,o){return e||(w("PI_CACHE_RETENTION",o)==="long"?"long":"short")}function Te(e,o,n){let r=fe(o,n);if(r==="none")return{retention:r};let i=r==="long"&&C(e).supportsLongCacheRetention?"1h":void 0;return{retention:r,cacheControl:{type:"ephemeral",...i&&{ttl:i}}}}var be="2.1.280",we=["Read","Write","Edit","Bash","Grep","Glob","AskUserQuestion","EnterPlanMode","ExitPlanMode","KillShell","NotebookEdit","Skill","Task","TaskOutput","TodoWrite","WebFetch","WebSearch"],ve=new Map(we.map(e=>[e.toLowerCase(),e])),H=e=>ve.get(e.toLowerCase())??e,Ce=(e,o)=>{if(o&&o.length>0){let n=e.toLowerCase(),r=o.find(i=>i.name.toLowerCase()===n);if(r)return r.name}return e};function j(e){return{type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}}}function Re(e){if(!e.some(i=>i.type==="image"))return T(e.map(i=>i.text).join(`
4
+ import{d as Z,e as Q,f as X,g as ee,h as te}from"./chunk-KDYEGGMW.js";import{a as ie,b as ae}from"./chunk-BGYR4ID3.js";import{b as z,c as $,d as Y}from"./chunk-SKHLZ6XY.js";import{a as w}from"./chunk-6R73ICDB.js";import{a as se}from"./chunk-23PRJECN.js";import{a as oe,d as re,g as ce,i as le,m as ue,n as pe,o as de}from"./chunk-QBKCAIJG.js";import{J as L,o as K,p as V,s as G,u as E,y as J}from"./chunk-PZMGBKUR.js";import{d as O}from"./chunk-D6VMBA4C.js";import{a as T}from"./chunk-USBJFDJ6.js";import{a as ne}from"./chunk-K4NTZEDJ.js";import{h as N}from"./chunk-6AKUD3CF.js";import"./chunk-OSEIQ7SS.js";import{b as q}from"./chunk-CXT5IR5T.js";import{m as P}from"./chunk-VW7TLY3P.js";import"./chunk-WHC7AYZD.js";function fe(e,o){return e||(w("PI_CACHE_RETENTION",o)==="long"?"long":"short")}function Te(e,o,n){let r=fe(o,n);if(r==="none")return{retention:r};let i=r==="long"&&C(e).supportsLongCacheRetention?"1h":void 0;return{retention:r,cacheControl:{type:"ephemeral",...i&&{ttl:i}}}}var be="2.1.280",we=["Read","Write","Edit","Bash","Grep","Glob","AskUserQuestion","EnterPlanMode","ExitPlanMode","KillShell","NotebookEdit","Skill","Task","TaskOutput","TodoWrite","WebFetch","WebSearch"],ve=new Map(we.map(e=>[e.toLowerCase(),e])),H=e=>ve.get(e.toLowerCase())??e,Ce=(e,o)=>{if(o&&o.length>0){let n=e.toLowerCase(),r=o.find(i=>i.name.toLowerCase()===n);if(r)return r.name}return e};function j(e){return{type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}}}function Re(e){if(!e.some(i=>i.type==="image"))return T(e.map(i=>i.text).join(`
5
5
  `));let n=e.map(i=>i.type==="text"?{type:"text",text:T(i.text)}:j(i));return n.some(i=>i.type==="text")||n.unshift({type:"text",text:"(see attached image)"}),n}var Ee="fine-grained-tool-streaming-2025-05-14",Se="interleaved-thinking-2025-05-14",Ie="server-side-fallback-2026-07-01",Ae="mid-conversation-output-config-2026-07-01",Me="thinking-binding-controls-2026-08-01",Oe="inline-tools-2026-09-15",Ne={name:"__pi_deferred_placeholder__",description:"Reserved placeholder. Never available. Never call this.",input_schema:{type:"object",properties:{},required:[]},defer_loading:!0};function Le(e){return(e.compat?.allowedFallbackModels?.length??0)>0}function C(e){let o=e.provider==="openrouter"||e.baseUrl.includes("openrouter.ai");return{supportsEagerToolInputStreaming:e.compat?.supportsEagerToolInputStreaming??!0,supportsLongCacheRetention:e.compat?.supportsLongCacheRetention??!0,sendSessionAffinityHeaders:e.compat?.sendSessionAffinityHeaders??o,sessionAffinityFormat:e.compat?.sessionAffinityFormat??(o?"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}}function D(...e){let o={};for(let n of e)n&&Object.assign(o,n);return o}function B(e,o){if(!e)return!1;let n=o.toLowerCase();for(let[r,i]of Object.entries(e))if(r.toLowerCase()===n&&i!==null&&i.trim().length>0)return!0;return!1}function ge(e,o){return!!e||B(o,"authorization")||B(o,"x-api-key")||B(o,"cf-aig-authorization")}function he(e,o,n){if(!ge(o,n))throw new Error(`No API key for provider: ${e}`)}var v=class extends P{_shouldResolveDefaultCredentials(){return!1}};function me(e,o,n,r){if(e.provider!=="anthropic"||ge(o,n))return;let i=w(Z,r),l=w(Q,r),t=w(ee,r);if(!(!i||!l||!t))return{organization_id:l,workspace_id:w(te,r),authentication:{type:"oidc_federation",federation_rule_id:i,service_account_id:w(X,r),identity_token:{source:"file",path:t}}}}var S,Pe=new Set(["message_start","message_delta","message_stop","content_block_start","content_block_delta","content_block_stop"]);function _e(e){if(!e.event&&e.data.length===0)return null;let o={event:e.event,data:e.data.join(`
6
6
  `),raw:[...e.raw]};return e.event=null,e.data=[],e.raw=[],o}function F(e,o){if(e==="")return _e(o);if(o.raw.push(e),e.startsWith(":"))return null;let n=e.indexOf(":"),r=n===-1?e:e.slice(0,n),i=n===-1?"":e.slice(n+1);return i.startsWith(" ")&&(i=i.slice(1)),r==="event"?o.event=i:r==="data"&&o.data.push(i),null}function De(e){let o=e.indexOf("\r"),n=e.indexOf(`
7
7
  `);return o===-1?n:n===-1?o:Math.min(o,n)}function I(e){let o=De(e);if(o===-1)return null;let n=o+1;return e[o]==="\r"&&e[n]===`
@@ -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 P,c as C}from"./chunk-ZNZFWSPH.js";import{a as k,b as _,c as x,d as z}from"./chunk-DXBSQXJL.js";import{a as b}from"./chunk-XIECJESP.js";import"./chunk-V3AQJSWR.js";import{b as E}from"./chunk-CVC66CFV.js";import{a as M}from"./chunk-23PRJECN.js";import{a as O,b as I}from"./chunk-FF7UELTU.js";import{f as d,h as S,i as w}from"./chunk-QBKCAIJG.js";import{C as l,F as R,L as T,y as v}from"./chunk-PZMGBKUR.js";import"./chunk-6R73ICDB.js";import"./chunk-SKHLZ6XY.js";import"./chunk-D6VMBA4C.js";import"./chunk-USBJFDJ6.js";import{a as A}from"./chunk-K4NTZEDJ.js";import{h as y}from"./chunk-6AKUD3CF.js";import"./chunk-OSEIQ7SS.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 D(r){return I(O(r),"Azure OpenAI API error")}var K=(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 c=q(r,i,e),o=d(l(p.messages),r.compat?.supportsOpenAIGrammarTools??!1),m=U(r,p,e,n,o),u=await e?.onPayload?.(m,r);u!==void 0&&(m=u);let f={...e?.signal?{signal:e.signal}:{},...e?.timeoutMs!==void 0?{timeout:e.timeoutMs}:{},maxRetries:0},{data:L,response:g}=await M(()=>c.responses.create(m,f).withResponse(),{maxRetries:e?.maxRetries,maxRetryDelayMs:e?.maxRetryDelayMs,signal:e?.signal});if(await e?.onResponse?.({status:g.status,headers:A(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){for(let c of s.content)delete c.index,delete c.partialJson,delete c.customInput;s.stopReason=e?.signal?.aborted?"aborted":"error",s.errorMessage=D(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={...w(r,a,e,t),toolChoice:e?.toolChoice},n=e?.reasoning?T(r,e.reasoning):void 0;return K(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 E({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,k({supportsMidConvoSystemMessages:r.compat?.supportsMidConvoSystemMessages??!1,supportsAdditionalTools:n,supportsToolSearch:s})),c=_(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:c,stream:!0,prompt_cache_key: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 u=S(r,m??"off",e?.samplingParams);return u&&Object.assign(o,u),o}export{K as stream,re as streamSimple};
4
+ import{a as P,c as C}from"./chunk-ZNZFWSPH.js";import{a as k,b as _,c as x,d as z}from"./chunk-7GAYFN52.js";import{a as b}from"./chunk-XIECJESP.js";import"./chunk-V3AQJSWR.js";import{b as E}from"./chunk-CVC66CFV.js";import{a as O,b as I}from"./chunk-FF7UELTU.js";import"./chunk-SKHLZ6XY.js";import"./chunk-6R73ICDB.js";import{a as M}from"./chunk-23PRJECN.js";import{f as d,h as S,i as w}from"./chunk-QBKCAIJG.js";import{C as l,F as R,L as T,y as v}from"./chunk-PZMGBKUR.js";import"./chunk-D6VMBA4C.js";import"./chunk-USBJFDJ6.js";import{a as A}from"./chunk-K4NTZEDJ.js";import{h as y}from"./chunk-6AKUD3CF.js";import"./chunk-OSEIQ7SS.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 D(r){return I(O(r),"Azure OpenAI API error")}var K=(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 c=q(r,i,e),o=d(l(p.messages),r.compat?.supportsOpenAIGrammarTools??!1),m=U(r,p,e,n,o),u=await e?.onPayload?.(m,r);u!==void 0&&(m=u);let f={...e?.signal?{signal:e.signal}:{},...e?.timeoutMs!==void 0?{timeout:e.timeoutMs}:{},maxRetries:0},{data:L,response:g}=await M(()=>c.responses.create(m,f).withResponse(),{maxRetries:e?.maxRetries,maxRetryDelayMs:e?.maxRetryDelayMs,signal:e?.signal});if(await e?.onResponse?.({status:g.status,headers:A(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){for(let c of s.content)delete c.index,delete c.partialJson,delete c.customInput;s.stopReason=e?.signal?.aborted?"aborted":"error",s.errorMessage=D(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={...w(r,a,e,t),toolChoice:e?.toolChoice},n=e?.reasoning?T(r,e.reasoning):void 0;return K(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 E({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,k({supportsMidConvoSystemMessages:r.compat?.supportsMidConvoSystemMessages??!1,supportsAdditionalTools:n,supportsToolSearch:s})),c=_(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:c,stream:!0,prompt_cache_key: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 u=S(r,m??"off",e?.samplingParams);return u&&Object.assign(o,u),o}export{K as stream,re as streamSimple};