@cortex-agent/server 2026.10.28 → 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 +36 -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-BPXakv_3.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-WCm6wwmM.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-BHZpFXhc.js +0 -525
  256. package/web/dist/assets/index-DqWMdMkh.css +0 -1
  257. package/web/dist/assets/pdf-worker-Hp15W1QJ.js +0 -57
  258. package/web/dist/assets/pdf.worker.min-DnhTvCwe.js +0 -55
@@ -1,5 +0,0 @@
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 B,c as v}from"./chunk-Y6ZEVVL5.js";import{a as _,b as $,e as H}from"./chunk-LMSQZ6TQ.js";import{a as K}from"./chunk-BGVHA2D4.js";import{a as O}from"./chunk-OE4KH3NJ.js";import{d as F}from"./chunk-MEPASGPP.js";import{e as j}from"./chunk-NAA7GF6Q.js";import{d as L,v as W,y as X}from"./chunk-J5DVLUKY.js";function S(){return{input:0,output:0,cacheRead:0,cacheWrite:0,cost:0,contextTokens:0,turns:0}}function g(t){return typeof t=="number"&&Number.isFinite(t)?t:0}function V(t,e){t.input+=e.input,t.output+=e.output,t.cacheRead+=e.cacheRead,t.cacheWrite+=e.cacheWrite,t.cost+=e.cost,t.contextTokens=e.contextTokens||t.contextTokens,t.turns+=e.turns}function lt(t,e){t.input+=e.input,t.output+=e.output,t.cacheRead+=e.cacheRead,t.cacheWrite+=e.cacheWrite,t.cost+=e.cost,t.contextTokens+=e.contextTokens,t.turns+=e.turns}function le(t){let e=S();for(let n of t)lt(e,n.usage);return e}import*as b from"node:path";function dt(t,e,n){return t.hasTrustRequiringProjectResources(e)?new t.ProjectTrustStore(n).get(e)===!0:!0}function pt(t,e,n){return n===null||!e||e<=n?t:e-n+Math.min(t,Math.floor(n/2))}function ft(t){let e=t.getCompactionReserveTokens.bind(t);t.getCompactionReserveTokens=n=>pt(e(n),n?.contextWindow,F().maxContextTokens)}function mt(t){if(process.platform!=="win32")return;let e=process.env.CORTEX_GIT_BASH_PATH;if(!e)return;let n=t.getShellPath.bind(t);t.getShellPath=()=>n()??e}function G(t,e,n){let o=t.SettingsManager.create(e,n,{projectTrusted:dt(t,e,n)});return o.getCacheWarmingMode=()=>"off",ft(o),mt(o),o}var A=j("pi-subagent");function gt(t,e,n){if(!e.model)return{model:void 0,thinkingLevel:void 0};let o=e.provider?`${e.provider}/${e.model}`:e.model,r=t.resolveCliModel({cliModel:e.thinking?`${o}:${e.thinking}`:o,modelRuntime:n});if(r.error)throw new Error(r.error);return r.warning&&A.warn(`PI subagent model resolution: ${r.warning}`),{model:r.model,thinkingLevel:r.thinkingLevel}}async function _t(t,e){let n=G(t,e.cwd,e.agentDir),o=await t.ModelRuntime.create({authPath:b.join(e.agentDir,"auth.json"),modelsPath:b.join(e.agentDir,"models.json"),allowModelNetwork:!1});return t.createAgentSessionServices({cwd:e.cwd,agentDir:e.agentDir,settingsManager:n,modelRuntime:o,resourceLoaderOptions:{noExtensions:!0,extensionFactories:e.extensions,appendSystemPrompt:e.appendSystemPrompt,noContextFiles:e.noContextFiles===!0}})}async function z(t){let e=await K(),n=await _t(e,t);for(let i of n.diagnostics)i.type==="error"&&A.warn(`PI subagent session: ${i.message}`);let{model:o,thinkingLevel:r}=gt(e,t,n.modelRuntime),s=await e.createAgentSessionFromServices({services:n,sessionManager:e.SessionManager.inMemory(t.cwd),model:o,thinkingLevel:r,tools:t.tools});return await s.session.bindExtensions({mode:"print",onError:i=>A.warn(`PI subagent extension ${i.extensionPath} failed on ${i.event}: ${String(i.error)}`)}),{session:s.session,dispose:()=>s.session.dispose()}}function E(t){if(!Array.isArray(t))return[];let e=[];for(let n of t){if(!n||typeof n!="object"||n.type!=="image")continue;let o=n,r=o.source;r&&r.type==="base64"&&typeof r.data=="string"&&r.data?e.push({mimeType:typeof r.media_type=="string"?r.media_type:"",data:r.data}):typeof o.data=="string"&&o.data&&e.push({mimeType:typeof o.mimeType=="string"?o.mimeType:"",data:o.data})}return e}function J(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.mimeType=="string"&&typeof e.data=="string"&&e.data.length>0}function Te(t,e,n=!1){if(!e||!t)return;let o=r=>{try{e(r)}catch{}};return{forChild(r,s){let i=`${t}#${r}`,c=n&&r>0;return(a,m)=>{let p=ht(i,s,m,a);for(let f=0;f<p.length;f++)o(c&&f===0?{...p[f],prompt:s.prompt}:p[f]);p.length&&(c=!1)}}}}function yt(t,e,n){return{ref:t,type:e.subagent_type,description:e.description,model:n.model??null,backend:"pi",...e.clean?{clean:!0}:{}}}function ht(t,e,n,o){let r=yt(t,e,n),s=o.type;if(s==="tool_execution_start"){let m=o.toolCallId,p=o.toolName;return typeof m!="string"||typeof p!="string"?[]:[{...r,kind:"tool_use",toolUseId:`${t}:${m}`,name:p,input:o.args??{}}]}if(s==="tool_execution_end")return Et(r,o);let i=P(o);if(!i||i.role!=="assistant")return[];let c=typeof i.model=="string"?i.model:r.model,a=N(i);return a?[{...r,model:c,kind:"assistant_text",text:a}]:[]}function Et(t,e){let n=e.toolCallId;if(typeof n!="string")return[];let o=E(e.result?.content);return[{...t,kind:"tool_result",toolUseId:`${t.ref}:${n}`,ok:e.isError!==!0,content:Tt(e.result),...o.length?{images:o}:{}}]}function P(t){return t.type!=="message_end"||!t.message||typeof t.message!="object"?null:t.message}function N(t){let e=t.content;return typeof e=="string"?e:Array.isArray(e)?e.filter(n=>!!n&&typeof n=="object"&&n.type==="text"&&typeof n.text=="string").map(n=>n.text).join(`
5
- `):""}function Tt(t){if(typeof t=="string")return t;if(!t||typeof t!="object")return"";let e=t.content;return typeof e=="string"?e:Array.isArray(e)?e.filter(n=>n&&typeof n=="object"&&n.type==="text").map(n=>String(n.text??"")).join(""):""}function Ie(t,e,n,o){return{ref:t,type:e.subagent_type,description:e.description,model:null,backend:n,kind:"end",status:o}}function Ct(t){let e=t.name;return t.backend==="claude"?e:_("pi",e)??e}function Y(t){if(t.kind==="end")return t.status?[{type:"subagent_end",parentToolUseId:t.ref,status:t.status}]:[];let e={parentToolUseId:t.ref,type:t.type||null,description:t.description||null,...t.prompt?{prompt:t.prompt}:{},model:t.model,...t.clean?{clean:!0}:{}};return t.kind==="tool_use"?[{type:"tool_use",toolUseId:t.toolUseId,name:Ct(t),input:t.input??{},subagent:e}]:t.kind==="tool_result"?[{type:"tool_result",toolUseId:t.toolUseId,ok:t.ok!==!1,content:t.content??"",subagent:e,...t.images?.length?{images:t.images}:{}}]:[{type:"assistant_text",text:t.text,subagent:e}]}var Rt=new Set(["pending","in_progress","completed"]);function Q(t){return typeof t=="string"?t:""}function It(t){return typeof t=="string"&&Rt.has(t)?t:"pending"}function kt(t){if(!t||typeof t!="object")return null;let e=t,n=Q(e.content).trim(),o=Q(e.activeForm).trim()||n;return!n&&!o?null:{content:n||o,activeForm:o,status:It(e.status)}}function xt(t,e=Date.now()){if(!t||typeof t!="object")return null;let n=t.todos;if(!Array.isArray(n))return null;let o=[];for(let i of n){let c=kt(i);c&&o.push(c)}let r=0,s=null;for(let i of o)i.status==="completed"?r+=1:i.status==="in_progress"&&s===null&&(s=i.activeForm);return{items:o,total:o.length,completed:r,activeLabel:s,updatedAt:e}}function Z(t,e,n,o=Date.now()){return _(t,e)!=="todo_write"?null:xt(n,o)}function Se(t,e=40){if(!t||t.total===0)return"";let n=`${t.completed}/${t.total}`,o=t.activeLabel?.trim();if(!o)return n;let r=o.length>e?`${o.slice(0,e-1).trimEnd()}\u2026`:o;return`${n} \xB7 ${r}`}function Ue(){return{turnProgressCount:0,pendingCompletion:U()}}function Me(t,e){let n=t;if(typeof n.type!="string")return[];let o=n.type;if(o==="message_update")return St(n);if(o==="tool_execution_start")return bt(n);if(o==="tool_execution_end")return At(n);if(o==="agent_end")return Nt(n,e);if(o==="agent_settled")return wt(e);if(o==="compaction_start")return[{type:"context_compacted",trigger:typeof n.reason=="string"&&n.reason.length>0?n.reason:"auto"}];if(o==="message_end")return e.turnProgressCount++,[{type:"turn_progress",numTurns:e.turnProgressCount}];if(o==="cortex_subagent_event"){let r=Bt(n.notice);return r?Y(r):[]}if(o==="cortex_subagent_usage")return Ft(n.report,e);if(o==="extension_error"){let r=n.error;return[{type:"error",message:typeof r=="string"&&r.length>0?r:"extension error",fatal:!1}]}return o==="extension_ui_request"?vt(n):[]}function R(t){return t!==null&&typeof t=="object"?t:void 0}function tt(t){let e=R(t),n=e?.id??e?.responseId;return typeof n=="string"?n:void 0}function q(t,e){let n=R(t)?.content;return!Array.isArray(n)||typeof e!="number"?!1:R(n[e])?.redacted===!0}function Ot(t,e){let n=e.redacted===!0||q(t.message,e.contentIndex)||q(e.partial,e.contentIndex),o=e.type==="thinking_end"?e.content:e.delta;if(n||typeof o!="string"||o.length===0)return[];let r=tt(t.message),s=r!==void 0&&typeof e.contentIndex=="number"?`${r}:t${e.contentIndex}`:void 0;return e.type==="thinking_end"?[{type:"assistant_thinking",text:o,...s!==void 0?{blockId:s}:{}}]:s!==void 0?[{type:"assistant_thinking_delta",text:o,blockId:s}]:[]}function St(t){let e=R(t.assistantMessageEvent);if(!e)return[];if(e.type==="thinking_delta"||e.type==="thinking_end")return Ot(t,e);if(e.type!=="text_delta"||typeof e.delta!="string"||e.delta.length===0)return[];let n=tt(t.message);return[{type:"assistant_text",text:e.delta,...n!==void 0?{blockId:n}:{}}]}function bt(t){let e=t.toolCallId,n=t.toolName,o=t.args??{};if(typeof e!="string"||typeof n!="string")return[];let r=_("pi",n)??n,s=[{type:"tool_use",toolUseId:e,name:r,input:o}],i=Z("pi",n,o);return i&&s.push({type:"todo_update",toolUseId:e,snapshot:i}),s}function At(t){let e=t.toolCallId;if(typeof e!="string")return[];let n=t.isError===!0,o=t.result,r="",s=[];if(o&&typeof o=="object"){let c=o.content;Array.isArray(c)?(r=c.filter(a=>l(a).type==="text").map(a=>String(l(a).text??"")).join(""),s=E(c)):typeof c=="string"&&(r=c)}return[{type:"tool_result",toolUseId:e,ok:!n,content:r,...s.length?{images:s}:{}}]}function et(t,e){if(t.type!=="tool_execution_end"||!e?.input||e.input.includes("image"))return t;let n=l(t.result),o=n.content;return!Array.isArray(o)||!o.some(r=>l(r).type==="image")?t:{...t,result:{...n,content:o.filter(r=>l(r).type!=="image")}}}function U(){return{numTurns:0,totalCostUsd:null,error:null}}function Pt(){return{...U(),provider:"",model:"",tokensIn:0,tokensOut:0,cacheReadTokens:0,cacheWriteTokens:0,inputReported:!0,outputReported:!0,cacheReadReported:!0,cacheWriteReported:!0}}function Nt(t,e){let n=Array.isArray(t.messages)?t.messages:[],o=Ut(n);if(jt(e,o),o.provider==="")return[];let r=C(o.tokensIn,o.inputReported),s=C(o.tokensOut,o.outputReported),i=C(o.cacheReadTokens,o.cacheReadReported),c=C(o.cacheWriteTokens,o.cacheWriteReported),a=Xt(r,i,c);return[{type:"cost_record",provider:o.provider,model:o.model,tokens_in:o.tokensIn,tokens_out:o.tokensOut,prompt_tokens:a,cached_tokens:i,input_tokens:r,output_tokens:s,cache_read_tokens:i,cache_creation_tokens:c,provider_requests:o.numTurns>0?o.numTurns:null,cost_usd:o.totalCostUsd}]}function wt(t){let e=t.pendingCompletion;t.pendingCompletion=U();let n={type:"turn_complete",numTurns:e.numTurns,totalCostUsd:e.totalCostUsd};return e.error===null?[n]:[{...n,error:e.error}]}function Ut(t){let e=Pt();for(let n of t){let o=l(n);o.role==="assistant"&&(e.numTurns++,Mt(e,o),Dt(e,o),Wt(e,o))}return e}function Mt(t,e){let n=e.provider,o=e.model;t.provider===""&&typeof n=="string"&&n.length>0&&(t.provider=n),t.model===""&&typeof o=="string"&&o.length>0&&(t.model=o)}function Dt(t,e){if(t.error!==null||e.stopReason!=="error")return;let n=e.errorMessage;t.error=typeof n=="string"&&n.length>0?n:"PI agent reported an error during execution"}function Lt(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0}function T(t,e,n){return Lt(n)?[t+n,e]:[t,!1]}function Wt(t,e){let n=l(e.usage);[t.tokensIn,t.inputReported]=T(t.tokensIn,t.inputReported,n.input),[t.tokensOut,t.outputReported]=T(t.tokensOut,t.outputReported,n.output),[t.cacheReadTokens,t.cacheReadReported]=T(t.cacheReadTokens,t.cacheReadReported,n.cacheRead),[t.cacheWriteTokens,t.cacheWriteReported]=T(t.cacheWriteTokens,t.cacheWriteReported,n.cacheWrite);let o=l(n.cost).total;typeof o=="number"&&isFinite(o)&&(t.totalCostUsd=(t.totalCostUsd??0)+o)}function C(t,e){return e?t:null}function Xt(...t){return t.some(e=>e===null)?null:t.reduce((e,n)=>e+n,0)}function jt(t,e){let n=t.pendingCompletion;n.numTurns+=e.numTurns,n.totalCostUsd=nt(n.totalCostUsd,e.totalCostUsd),n.error=e.error}function nt(t,e){return t===null&&e===null?null:(t??0)+(e??0)}function Ft(t,e){let n=l(t),o=n.provider;if(typeof o!="string"||o==="")return[];let r=l(n.usage),s=h(r.input),i=h(r.output),c=h(r.cacheRead),a=h(r.cacheWrite),m=h(r.turns),p=w(r.cost);e.pendingCompletion.totalCostUsd=nt(e.pendingCompletion.totalCostUsd,p);let f=n.model;return[{type:"cost_record",provider:o,model:typeof f=="string"?f:"",tokens_in:s,tokens_out:i,prompt_tokens:s+c+a,cached_tokens:c,input_tokens:s,output_tokens:i,cache_read_tokens:c,cache_creation_tokens:a,provider_requests:m>0?m:null,cost_usd:p}]}function $t(t){return t==="completed"||t==="failed"||t==="killed"}function Bt(t){if(!t||typeof t!="object"||Array.isArray(t))return null;let e=t,{ref:n,kind:o}=e;if(typeof n!="string"||!n||o!=="tool_use"&&o!=="tool_result"&&o!=="assistant_text"&&o!=="end")return null;let r={ref:n,kind:o,type:typeof e.type=="string"?e.type:"",description:typeof e.description=="string"?e.description:"",...typeof e.prompt=="string"?{prompt:e.prompt}:{},model:typeof e.model=="string"?e.model:null};if(o==="tool_use")return typeof e.name!="string"||typeof e.toolUseId!="string"?null:(r.name=e.name,r.toolUseId=e.toolUseId,r.input=e.input??{},r);if(o==="tool_result"){if(typeof e.toolUseId!="string")return null;r.toolUseId=e.toolUseId,r.ok=e.ok!==!1,r.content=typeof e.content=="string"?e.content:"";let s=Array.isArray(e.images)?e.images.filter(J):[];return s.length&&(r.images=s),r}return o==="end"?$t(e.status)?(r.status=e.status,r):null:typeof e.text!="string"||!e.text?null:(r.text=e.text,r)}function vt(t){let e=t.id,n=t.method;if(typeof e!="string"||typeof n!="string")return[];if(n!=="select"&&n!=="confirm"&&n!=="input"&&n!=="editor")return[];let o=t.title,r=typeof o=="string"&&o.length>0?o:`${n} request`,s;if(n==="select"){let i=t.options,c=Array.isArray(i)?i.map(String):void 0;s={question:r},c&&(s.options=c)}else if(n==="confirm"){let i=t.message,c=typeof i=="string"&&i.length>0?`: ${i}`:"";s={question:r+c,options:["Yes","No"]}}else n==="editor"?s={question:r,multi:!0}:s={question:r};return[{type:"ask_user_question",toolUseId:e,questions:[s]}]}function De(t,e=null){let n=l(l(t).contextUsage),o=n.contextWindow;if(typeof o!="number"||!Number.isFinite(o)||o<=0)return null;let r=w(n.tokens);if(e===null||o<=e){let i=w(n.percent);return{usedTokens:r,contextWindow:o,percent:i,accuracy:"estimate"}}let s=r===null?null:r/e*100;return{usedTokens:r,contextWindow:e,percent:s,accuracy:"estimate"}}function h(t){return typeof t=="number"&&Number.isFinite(t)&&t>0?Math.floor(t):0}function w(t){return typeof t=="number"&&Number.isFinite(t)&&t>=0?t:null}function l(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}function ot(t){return t??"direct"}var rt="CORTEX_PI_MCP_COMPOSITION",I="CORTEX_PI_INTERACTION_BRIDGE",k="CORTEX_PI_TEAM_LEAD",x="CORTEX_PI_TEAM_WORKER",st="CORTEX_PI_CLEAN_WORKSPACE",Kt=["SLACK_CHANNEL","FEISHU_CHANNEL","CORTEX_SESSION_ID","CORTEX_PROFILE","CORTEX_BACKEND","CORTEX_MODEL","CORTEX_PROVIDER","CORTEX_THINKING","CORTEX_MODE","CORTEX_PROJECT","CORTEX_SESSION_NAME","CORTEX_EXECUTION_ID","CORTEX_CALLBACK_SOURCE","CORTEX_SCHEDULE_TASK_ID","CORTEX_CONFIG_IMMUTABLE","CORTEX_PRODUCTION_AUTH_FILE","CORTEX_WEBHOOK_BENCHMARK_ONLY","CORTEX_PI_ALLOWED_TOOLS","CORTEX_PI_SUBAGENT",rt,I,k,x,st,O];function u(t,e,n){n!=null&&n!==""&&(t[e]=String(n))}function Ht(t,e){let n=e.context;u(t,"CORTEX_MODEL",n?.selection?.model),u(t,"CORTEX_PROVIDER",n?.selection?.provider),u(t,"CORTEX_THINKING",n?.selection?.thinking),u(t,"CORTEX_MODE",n?.selection?.mode),u(t,"CORTEX_SESSION_ID",n?.trackSessionId??e.sessionId),u(t,"CORTEX_CALLBACK_SOURCE",e.callbackSource),u(t,"CORTEX_SCHEDULE_TASK_ID",e.scheduleTaskId),u(t,"CORTEX_PROJECT",n?.project),u(t,"CORTEX_EXECUTION_ID",n?.executionId)}function Vt(t,e=process.env){let n={...e,...t.routeEnv??{}};for(let o of Kt)delete n[o];for(let o of t.unsetEnv??[])delete n[o];return n.PI_CODING_AGENT_DIR=t.piAgentDir,n.CORTEX_BACKEND="pi",t.channel&&(n.SLACK_CHANNEL=t.channel,n.FEISHU_CHANNEL=t.channel),u(n,"CORTEX_PI_ALLOWED_TOOLS",t.allowedTools),u(n,rt,t.mcpComposition),t.mcpToolAllowlist!==void 0&&t.mcpToolAllowlist!==null&&(n[O]=JSON.stringify(t.mcpToolAllowlist)),t.enableInteractionBridge===!0&&(n[I]="1"),t.enableTeamLead===!0&&(n[k]="1"),t.enableTeamWorker===!0&&(n[x]="1"),u(n,"CORTEX_PI_SUBAGENT",t.subagentMarker),u(n,st,t.cleanWorkspace),Ht(n,t),n}function Gt(t){return t.replace(/\[.*?\]$/,"")}function zt(t){return t?(Array.isArray(t)?t:[t]).filter(e=>e.length>0):[]}function Jt(t){let e=t.tools.canonical&&t.tools.canonical.length>0?t.tools.canonical.map(n=>$("claude",n)).filter(n=>!!n).join(","):void 0;return t.tools.rawClaude??e}function Yt(t){return t.env.sets?.CORTEX_PI_SUBAGENT==="1"?"1":void 0}function Qt(t,e){return e!=="direct"?[]:[...t.mcp.servers??[]]}function $e(t,e){let n=ot(t.mcp.composition),o=Yt(t),r=Vt({sessionId:t.resume.backendSessionId,channel:t.context.channel,callbackSource:t.context.callbackSource,scheduleTaskId:t.context.scheduleTaskId,routeEnv:t.env.sets,unsetEnv:t.env.unsets,context:t.env.context,piAgentDir:e.agentDir,allowedTools:Jt(t),mcpComposition:n,mcpToolAllowlist:t.mcp.allowlist,enableInteractionBridge:n==="direct"&&t.flags.isUserInitiated===!0&&o===void 0,enableTeamLead:n==="direct"&&t.flags.teamLead===!0&&o===void 0,enableTeamWorker:n==="direct"&&t.flags.teamWorker===!0&&o===void 0,subagentMarker:o,cleanWorkspace:t.flags.clean?e.cwd:null},t.env.pinned);return{sessionKey:t.engineKey,cwd:e.cwd,agentDir:e.agentDir,sessionDir:e.sessionDir,sessionPath:e.sessionPath,provider:t.model.provider??null,model:t.model.id?Gt(t.model.id):null,benchmarkMaxOutputTokens:t.model.benchmarkMaxOutputTokens,thinking:t.model.thinking??null,systemPrompt:t.prompt.system||null,appendSystemPrompt:zt(t.prompt.append),skillPaths:t.flags.disableSkills?[]:[...t.plugins.skillDirs??[],...t.plugins.dirs??[]],disableHooks:t.flags.disableHooks===!0,...t.flags.clean?{noContextFiles:!0}:{},reportsProviderQuota:!!t.route.gatewayBaseUrl,pluginMcpServers:Qt(t,n),env:r,streamDeltas:e.streamDeltas}}var Zt=new Set(["CORTEX_EXECUTION_ID"]);function Be(t){let{sessionPath:e,env:n,...o}=t,r=Object.entries(n).filter(([s])=>!Zt.has(s)).sort(([s],[i])=>s<i?-1:s>i?1:0);return JSON.stringify({...o,env:r})}import{existsSync as qt,mkdirSync as M,readFileSync as te,promises as y}from"node:fs";import*as ct from"node:os";import*as d from"node:path";var at="inputs",it="clean-workspace.md";function Ge(t){return t?.clean===!0&&t.workspaceDir?t.workspaceDir:null}function ze(t,e=W){M(e,{recursive:!0});for(let n=1;;n++){let o=d.join(e,n===1?t:`${t}-${n}`);if(ee(o))return M(d.join(o,at)),o}}function ee(t){try{return M(t),!0}catch(e){if(e.code==="EEXIST")return!1;throw e}}async function Je(t,e,n){let o=d.join(t,at);await y.mkdir(o,{recursive:!0});let r=B(n||d.basename(e)),s=d.join(o,r);if(await ne(e,s))return s;let{destPath:i}=await v(o,r);return await y.cp(e,i,{recursive:!0}),i}async function ne(t,e){let[n,o]=await Promise.all([y.stat(t).catch(()=>null),y.stat(e).catch(()=>null)]);if(!n?.isFile()||!o?.isFile()||n.size!==o.size)return!1;let[r,s]=await Promise.all([y.readFile(t),y.readFile(e)]);return r.equals(s)}function Ye(t,e){let n=t==="~"||t.startsWith("~/")?d.join(ct.homedir(),t.slice(1)):t;return d.resolve(e,n)}function ut(t){let e=d.join(X,it),n=qt(e)?e:d.join(L,"prompts",it);return te(n,"utf8").replaceAll("{{workspace}}",t).trim()}function oe(t,e){let n={...t,PI_CODING_AGENT_DIR:e,CORTEX_PI_SUBAGENT:"1"};return delete n[I],delete n[k],delete n[x],n}async function sn(t){let{task:e,role:n}=t,o=t.model??{},r=t.createSession??z,s=t.workspace??null,i=await r({cwd:s??t.cwd,agentDir:t.agentDir,provider:o.provider??null,model:o.model??null,thinking:o.thinking??null,tools:H(n,"pi"),appendSystemPrompt:[...n.systemPrompt?[n.systemPrompt]:[],...s?[ut(s)]:[]],...s?{noContextFiles:!0}:{},extensions:t.childExtensions(oe(t.parentEnv,t.agentDir),o.provider??null)});try{let c=await re(i,e,t.signal,t.forward);return c.model||(c.model=o.model),c}finally{i.dispose()}}async function re(t,e,n,o){if(n?.aborted)throw new Error("Subagent was aborted.");let r={output:"",usage:S()},s=t.session.subscribe(c=>{ie(r,et(c,t.session.model),o)}),i=()=>{t.session.abort().catch(()=>{})};n?.addEventListener("abort",i,{once:!0});try{await t.session.prompt(`Task: ${e.prompt}`)}finally{n?.removeEventListener("abort",i),s()}if(n?.aborted)throw new Error("Subagent was aborted.");return se(e,r)}function se(t,e){return{description:t.description,prompt:t.prompt,subagentType:t.subagent_type,output:e.output,usage:e.usage,model:e.model,provider:e.provider,backend:"pi",stopReason:e.stopReason,errorMessage:e.errorMessage}}function ie(t,e,n){if(n)try{n(e,t)}catch{}let o=P(e);o&&(ce(t,o),ue(t,o))}function ce(t,e){if(e.role!=="assistant")return;let n=e.usage,o=n?.cost;V(t.usage,{input:g(n?.input),output:g(n?.output),cacheRead:g(n?.cacheRead),cacheWrite:g(n?.cacheWrite),cost:g(o?.total),contextTokens:g(n?.totalTokens),turns:1})}function D(t,e){return typeof t=="string"?t:e}function ae(t,e){let n=typeof e.stopReason=="string"?e.stopReason:void 0;if(!n){t.errorMessage=D(e.errorMessage,t.errorMessage);return}t.stopReason=n,t.errorMessage=typeof e.errorMessage=="string"?e.errorMessage:void 0}function ue(t,e){e.role==="assistant"&&(t.output=N(e)||t.output,t.model=D(e.model,t.model),t.provider=D(e.provider,t.provider),ae(t,e))}export{xt as a,Z as b,Se as c,ot as d,E as e,Ie as f,Y as g,Ue as h,Me as i,et as j,De as k,rt as l,I as m,k as n,x as o,st as p,$e as q,Be as r,G as s,z as t,S as u,le as v,Te as w,ht as x,Ge as y,ze as z,Je as A,Ye as B,ut as C,oe as D,sn as E,se as F};