nolo-cli 0.149.0-alpha.1 → 0.151.0-alpha.2

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/{_executeModel-OW3H7ICR.js → _executeModel-XHAFJ2MM.js} +134 -91
  2. package/accountResolver-7RYB4D2P.js +300 -0
  3. package/action-SXJD5N5R.js +23 -0
  4. package/{addContentAction-B2DRF7P6.js → addContentAction-ZV774PHH.js} +20 -14
  5. package/{addDialogAgentAction-2P2FLTLD.js → addDialogAgentAction-A6SMKAGH.js} +26 -22
  6. package/{agentDeleteCommand-7IDWF6E3.js → agentDeleteCommand-DPUUS56Z.js} +181 -93
  7. package/{agentEmailCommands-A6XBQZBN.js → agentEmailCommands-V4P5EFLP.js} +132 -112
  8. package/{agentGrantCommands-M3XFO6EN.js → agentGrantCommands-HOJ3JBBQ.js} +3 -3
  9. package/agentListCommands-TWFLUYIZ.js +802 -0
  10. package/{agentMachineCommands-DQPUIMAC.js → agentMachineCommands-MELPAZZI.js} +58 -62
  11. package/{agentProviderCommands-YK2BIIXZ.js → agentProviderCommands-HL6MBLCL.js} +149 -2
  12. package/{agentPullCommand-HF4A42D4.js → agentPullCommand-FA43RBRU.js} +7 -7
  13. package/agentRecordCommands-FSWSSQIO.js +154 -0
  14. package/agentRunCommand-GDBJVOAT.js +183 -0
  15. package/{agentRunControl-2SKCR4SB.js → agentRunControl-IFM7IGMG.js} +10 -2
  16. package/{agentRuntimeLocal-AK2QVJHY.js → agentRuntimeLocal-KKSQJMTE.js} +47 -50
  17. package/{agentSlice-O4RUQUMT.js → agentSlice-YO2ZLJMD.js} +23 -16
  18. package/{appDeleteCommands-N3XEVVYC.js → appDeleteCommands-4PL4KYRN.js} +58 -59
  19. package/{appDeployCommands-AWFIXYVW.js → appDeployCommands-EEEXCEB6.js} +67 -63
  20. package/{appDeployStatusCommands-CZRON2FO.js → appDeployStatusCommands-35ZX7T66.js} +56 -56
  21. package/{appGetCommands-XQIUY4TD.js → appGetCommands-WFCHXJWF.js} +56 -56
  22. package/{appListCommands-NNG4H36Y.js → appListCommands-XY2U6DPF.js} +57 -59
  23. package/{authCommand-UBJ4EWYZ.js → authCommand-QYN47CQD.js} +371 -68
  24. package/{authCommands-H6WKKCRW.js → authCommands-77CHYBGF.js} +12 -9
  25. package/{builtinSkillRegistry-ZMF6YGNO.js → builtinSkillRegistry-TDQ6JB2E.js} +13 -11
  26. package/{chromeCommands-2N6MEWRU.js → chromeCommands-OBBNJCLS.js} +314 -13
  27. package/chromeOpsCommands-3Z34RKSE.js +472 -0
  28. package/{chunk-ALXHV7NK.js → chunk-2GGXHQIW.js} +43 -4
  29. package/{localRuntimeAuthority-5W6IJRAD.js → chunk-2IXDJNZI.js} +154 -75
  30. package/{chunk-IVZJWTDI.js → chunk-36OMEXXR.js} +89 -21
  31. package/{chunk-H6A6X4EK.js → chunk-3MZAGMYY.js} +16 -0
  32. package/chunk-3PVYUPXK.js +40 -0
  33. package/chunk-3SZA4U64.js +1192 -0
  34. package/{chunk-GNMAFAIS.js → chunk-44WXLHFI.js} +1 -1
  35. package/{chunk-AGGIDPCZ.js → chunk-4JH2UMJR.js} +6 -0
  36. package/chunk-4LCOCOR5.js +50 -0
  37. package/chunk-4YRTZIVN.js +871 -0
  38. package/chunk-556RW72X.js +14110 -0
  39. package/{chunk-N7J63Q6C.js → chunk-56GBUMO5.js} +10 -1
  40. package/{chunk-W7XHHYWM.js → chunk-5BHQICF2.js} +5 -1
  41. package/{chunk-XUWRURDF.js → chunk-5EBLANFT.js} +1 -1
  42. package/{chunk-3AH7LNUB.js → chunk-5EMSBTQ6.js} +33 -14
  43. package/{chunk-YRRASA5Q.js → chunk-5MM7NNO6.js} +113 -52
  44. package/chunk-5MMAK75Q.js +15 -0
  45. package/{chunk-M5PVFLD4.js → chunk-64K7WX26.js} +90 -21
  46. package/{chunk-AKG5W4LG.js → chunk-6CCFTVBP.js} +76 -221
  47. package/chunk-6MJNEXUU.js +614 -0
  48. package/{chunk-62IL3KQV.js → chunk-6MXDOUMH.js} +15 -3
  49. package/{chunk-QOKAKDPE.js → chunk-6Q7UTJKR.js} +6 -94
  50. package/chunk-6QDYSCPW.js +223 -0
  51. package/{chunk-HYZIYH2H.js → chunk-74RAWNQN.js} +56 -63
  52. package/chunk-7DPNBQSV.js +9 -0
  53. package/chunk-7MOXKPHC.js +119 -0
  54. package/{chunk-ZUEK6A6C.js → chunk-7XKL25PW.js} +1973 -754
  55. package/{chunk-IAESIMK7.js → chunk-A4MW3YZL.js} +10 -14
  56. package/chunk-AGIM7IMJ.js +147 -0
  57. package/{chunk-7CHC4W22.js → chunk-AIZE5TDM.js} +3 -3
  58. package/{chunk-YAQJJDC2.js → chunk-AOCM7HPT.js} +214 -51
  59. package/{chunk-5GVBDNTO.js → chunk-AU7AXHUL.js} +1 -1
  60. package/{chunk-4H22P2JV.js → chunk-AUIJZACN.js} +2073 -1275
  61. package/{chunk-CIF4X6ZM.js → chunk-AWVFQMOV.js} +25 -3
  62. package/{chunk-RYZINGPM.js → chunk-BPMPOFWP.js} +347 -235
  63. package/{chunk-YUNJN43V.js → chunk-BU2YQBV4.js} +215 -28
  64. package/{chunk-XPRWFQQK.js → chunk-CBHGZRCE.js} +38 -12
  65. package/{chunk-Y3PMXGLH.js → chunk-CHCS6XPJ.js} +365 -144
  66. package/chunk-CHOZJMJS.js +78 -0
  67. package/{chunk-GBRG75BQ.js → chunk-D2MDMY2M.js} +1 -0
  68. package/{chunk-3SV7RM24.js → chunk-D2QN6CTI.js} +117 -72
  69. package/{chunk-5TEEECZM.js → chunk-E2AKSW7L.js} +10 -7
  70. package/{chunk-RSEEDUMS.js → chunk-EDX5XSJM.js} +2 -2
  71. package/{chunk-ATLTFRYJ.js → chunk-ES633ZS5.js} +280 -98
  72. package/{chunk-QDSINZM3.js → chunk-EUGTFFO6.js} +2 -23
  73. package/{chunk-UNYJU5L6.js → chunk-EYLGAEB4.js} +5 -1
  74. package/{chunk-CU3QB4HW.js → chunk-EYWJT7A2.js} +12 -12
  75. package/{chunk-BNGW5ASC.js → chunk-EZVK3N5L.js} +66 -18
  76. package/{chunk-6FGTMQCL.js → chunk-F32Z66T4.js} +6 -10
  77. package/chunk-FJMRBOPO.js +11507 -0
  78. package/{chunk-ZOVKKMF6.js → chunk-FY4SDK2E.js} +1 -1
  79. package/chunk-G6OOUQWJ.js +417 -0
  80. package/{chunk-PQWU42UQ.js → chunk-GCKHQECX.js} +6 -6
  81. package/chunk-GKXCHNTE.js +15 -0
  82. package/{chunk-TXH4IWJL.js → chunk-GQN2WLAI.js} +20 -11
  83. package/{chunk-P6GMCCAT.js → chunk-GQV5KHJU.js} +78 -12
  84. package/{chunk-B2XUQXQX.js → chunk-HIQ4GF53.js} +191 -68
  85. package/{chunk-MST6R3E4.js → chunk-HKX3ULQB.js} +34 -22
  86. package/{chunk-GMZLP5DV.js → chunk-HNUWUO75.js} +30 -19
  87. package/{chunk-5UTFL4QJ.js → chunk-I2ZMGXXF.js} +10 -5
  88. package/chunk-I42VC5KR.js +15 -0
  89. package/{chunk-3BXNTXYI.js → chunk-I4SN4NUQ.js} +1199 -56
  90. package/chunk-IA7TRNNR.js +11 -0
  91. package/{chunk-WIWM4FE3.js → chunk-IJERIUXS.js} +55 -748
  92. package/{chunk-CPUFH46E.js → chunk-ILU2NPWY.js} +10 -10
  93. package/{chunk-SLLGJZDT.js → chunk-ISQL4V7C.js} +4 -4
  94. package/chunk-IT3ZZRJE.js +12 -0
  95. package/{chunk-TZZ2WRBL.js → chunk-IZ7OJB6K.js} +20 -16
  96. package/{chunk-DY7ANLKG.js → chunk-JKMLSTZK.js} +43 -12
  97. package/{chunk-6TPOEJMQ.js → chunk-JZX2XLKC.js} +64 -23
  98. package/{chunk-27ONFIEY.js → chunk-K2AER7RX.js} +19 -12
  99. package/{chunk-O2OWEFII.js → chunk-KFHQQ3NO.js} +1 -1
  100. package/{chunk-QXGPFY6J.js → chunk-LGN377P3.js} +27 -17
  101. package/{chunk-L36OWPP3.js → chunk-LIQJTQRN.js} +118 -139
  102. package/{chunk-UASIEDKM.js → chunk-LTRUTOHX.js} +36 -31
  103. package/{chunk-BFU6C242.js → chunk-NMFV26UG.js} +1 -1
  104. package/{chunk-5J3PYNUP.js → chunk-NYYFIKHI.js} +17 -3
  105. package/{chunk-6O4IK4V2.js → chunk-OFFL4DCR.js} +1 -1
  106. package/{chunk-B6SAMB33.js → chunk-OWYYDMGJ.js} +209 -9
  107. package/{chunk-KQHGZWSV.js → chunk-OXME3PEE.js} +1 -1
  108. package/{chunk-CTUQJVQM.js → chunk-P5QACQDK.js} +1 -1
  109. package/{chunk-DXHL7G2L.js → chunk-PCKVQXYV.js} +274 -93
  110. package/{chunk-4JMDLJAD.js → chunk-PJNFNEJE.js} +114 -37
  111. package/{chunk-Z4CSIXYP.js → chunk-PLSVXHSA.js} +3 -3
  112. package/{chunk-BIDGLJQ3.js → chunk-PLXDDGBK.js} +45 -8
  113. package/chunk-PWTNI4N7.js +47 -0
  114. package/chunk-QFEW2ULV.js +42 -0
  115. package/{chunk-RGNEEJ3Y.js → chunk-QLQ573SU.js} +35 -9
  116. package/chunk-QQ56R7KS.js +88 -0
  117. package/chunk-QYPE3TS3.js +43 -0
  118. package/{chunk-4DPP773Q.js → chunk-RSHPU4PD.js} +59 -11
  119. package/chunk-RVWMAFIT.js +134 -0
  120. package/{chunk-ESHYE7WU.js → chunk-S73EPYNC.js} +10 -7
  121. package/{chunk-UQNS32WZ.js → chunk-SCMHQUMK.js} +1 -1
  122. package/{chunk-HTVYCXBP.js → chunk-SMENBO3M.js} +354 -120
  123. package/{chunk-OMRJYNCI.js → chunk-SSFDFOVT.js} +26 -31
  124. package/chunk-SW4S4XYB.js +1794 -0
  125. package/{chunk-TB3MIBRC.js → chunk-T6X3D7NB.js} +572 -430
  126. package/chunk-TY3TIUJK.js +89 -0
  127. package/{chunk-X2QRZXZH.js → chunk-TYJ5XFEA.js} +4 -4
  128. package/{chunk-ALFH24P3.js → chunk-TYYRSFBG.js} +197 -155
  129. package/{chunk-7KVZ5LDQ.js → chunk-UBUH2TCC.js} +18 -4
  130. package/chunk-UEILX4EV.js +15 -0
  131. package/chunk-UHTDNB5Y.js +140 -0
  132. package/{chunk-YYLHWIW6.js → chunk-UKZX3NHN.js} +1 -1
  133. package/{chunk-OHOVNO7I.js → chunk-UOKFKFPO.js} +6 -3
  134. package/{chunk-XISEYOGH.js → chunk-USHQX6VT.js} +5 -5
  135. package/chunk-UUPR3TD7.js +53 -0
  136. package/{chunk-HDLLCBRF.js → chunk-VEA7H5FG.js} +2 -2
  137. package/chunk-VHGD6FHV.js +116 -0
  138. package/chunk-VIWDGTDA.js +8 -0
  139. package/{chunk-GOH6RW6F.js → chunk-VJXHL6MH.js} +34 -11
  140. package/{chunk-4XEYAFLY.js → chunk-VL5KOY2C.js} +623 -94
  141. package/{chunk-EADNWBAZ.js → chunk-VP3BINY7.js} +13 -0
  142. package/{chunk-EOARMOVD.js → chunk-W4S6OTSC.js} +6 -3
  143. package/chunk-WD4XYDYC.js +567 -0
  144. package/chunk-WJZOQR2J.js +151 -0
  145. package/{chunk-AUDNYVRC.js → chunk-XETG4RIX.js} +5 -5
  146. package/{chunk-MX574M24.js → chunk-XI7DGLUK.js} +4 -4
  147. package/{chunk-3L2WKC3W.js → chunk-XPWGOTBQ.js} +8 -1
  148. package/chunk-XRUSXPCQ.js +514 -0
  149. package/{chunk-I4OPU5TK.js → chunk-XS47QOFV.js} +273 -11
  150. package/{chunk-S5XGT6GB.js → chunk-XZNCX52W.js} +30 -9
  151. package/{chunk-ID7LNBWR.js → chunk-Y2DXOPSO.js} +1920 -644
  152. package/{chunk-5OA5HMTL.js → chunk-YLMMECCH.js} +1 -1
  153. package/{chunk-CFT5HBGW.js → chunk-YVLQXTUB.js} +448 -12
  154. package/chunk-YVPQATSC.js +709 -0
  155. package/{chunk-3DAVPNFT.js → chunk-Z7OJUX6S.js} +122 -107
  156. package/chunk-ZEZC7IIM.js +126 -0
  157. package/{chunk-ALGORS6Y.js → chunk-ZF6526IQ.js} +43 -8
  158. package/chunk-ZIWPQEFU.js +165 -0
  159. package/chunk-ZKZ5X2HS.js +7012 -0
  160. package/chunk-ZRAU6T47.js +56 -0
  161. package/{cliExecutor-AWYR3T33.js → cliExecutor-BWBF2MTI.js} +4 -3
  162. package/{clipboardy-BX4NMYHE.js → clipboardy-GCO3GT3I.js} +3 -8
  163. package/{commandRegistry-2KBOXZQC.js → commandRegistry-XN7C5GHO.js} +183 -107
  164. package/contentThunks-5L7YQI3S.js +84 -0
  165. package/{cooldownCommands-ZLEPIB4A.js → cooldownCommands-JFKTYS2D.js} +2 -2
  166. package/{createAgentAutomationAction-5UGTB26P.js → createAgentAutomationAction-QOPOLCRK.js} +53 -44
  167. package/createDialogAction-MZ66VY5Q.js +76 -0
  168. package/{createPageAction-CDLDKPRM.js → createPageAction-VQDJIXMY.js} +65 -54
  169. package/cursorProvider-YGGNMVWX.js +6123 -0
  170. package/{db-VQSAOWAO.js → db-2QOTXYGH.js} +11 -5
  171. package/{dbSlice-DQ32LYTJ.js → dbSlice-J37OGIXH.js} +19 -13
  172. package/{deleteFile-NX6QHCWZ.js → deleteFile-6JWDDRVP.js} +10 -6
  173. package/dialogCommands-YZLSJB6X.js +113 -0
  174. package/{dialogSlice-N3YB65G5.js → dialogSlice-6RODVYCK.js} +53 -39
  175. package/{docCreateCommands-ZSLGVBZT.js → docCreateCommands-JB2RRMRJ.js} +54 -57
  176. package/{docDeleteCommands-5N4GVZBG.js → docDeleteCommands-AQENULNM.js} +56 -58
  177. package/{docReadCommands-YJSAA7AV.js → docReadCommands-DYD25YLQ.js} +53 -56
  178. package/{docStore-E3CEOV5Q.js → docStore-ZZA3OPM5.js} +25 -16
  179. package/{docUpdateCommands-WEMLSW6W.js → docUpdateCommands-3GVS23QL.js} +54 -57
  180. package/{fetchMessages-67MEFPZR.js → fetchMessages-IIJWQ3HR.js} +5 -4
  181. package/{getPricing-NMMFT3YI.js → getPricing-FKK3F5EJ.js} +11 -9
  182. package/{handleSendMessageAction-DQAD5ERJ.js → handleSendMessageAction-DVG5U26T.js} +422 -118
  183. package/index.js +11 -7
  184. package/{lib-FRRS27KN.js → lib-4YTWAGY7.js} +581 -248
  185. package/{localDialogRead-EBRS242U.js → localDialogRead-FSOMOPDZ.js} +2 -2
  186. package/localRuntimeAdapter-HXRHFKRC.js +244 -0
  187. package/localRuntimeAuthority-JDAD7CB6.js +16 -0
  188. package/{localRuntimeDb-3LRMNLCM.js → localRuntimeDb-CVC62PM5.js} +1 -1
  189. package/{machineCommands-HAP75VSG.js → machineCommands-5KBF4RCC.js} +503 -161
  190. package/{machineInfo-66ZFUMLE.js → machineInfo-UKPTZO5Y.js} +2 -2
  191. package/machineWsRunDispatch-4OQDEDOR.js +169 -0
  192. package/{memberThunks-5ZXPR63F.js → memberThunks-66DH6ABQ.js} +25 -18
  193. package/{models-ZPU5EDF4.js → models-LAS4B2B5.js} +2 -2
  194. package/package.json +1 -1
  195. package/{providerPresetApply-DD6NGWW6.js → providerPresetApply-MY66I6NT.js} +10 -10
  196. package/{providerRegistry-XDRLMYGJ.js → providerRegistry-QOE2FT57.js} +13 -9
  197. package/{read-EPTJRAEF.js → read-DC4NUGN6.js} +12 -8
  198. package/{readDocTool-W4NDXNEX.js → readDocTool-NCJ5NT25.js} +1 -1
  199. package/{readlineWorkspace-7BC66QSX.js → readlineWorkspace-RIE62QVZ.js} +5022 -921
  200. package/{removeDialogAgentAction-OSYNZRX7.js → removeDialogAgentAction-E2H3OZU6.js} +29 -28
  201. package/{runAgentClientLoop-6E6UC3CE.js → runAgentClientLoop-KLUUXBZS.js} +154 -97
  202. package/{runtimeDoctorCommands-ID23PNNZ.js → runtimeDoctorCommands-GIOGC5SC.js} +17 -17
  203. package/secretCommands-ZXZRLR3R.js +700 -0
  204. package/setDialogExtraReferencesAction-SITRPMYU.js +37 -0
  205. package/{setPrimaryDialogAgentAction-WZ7KI3YA.js → setPrimaryDialogAgentAction-U7N45TGC.js} +30 -29
  206. package/{chunk-SONWNI3L.js → settingThunks-Y7SVJOMZ.js} +223 -928
  207. package/{skillDiscovery-ZBU76COE.js → skillDiscovery-QC35EQY4.js} +2 -2
  208. package/{slateUtils-RIZES3PV.js → slateUtils-NGV2NMKM.js} +1 -1
  209. package/{spaceCommands-UJOVU4XI.js → spaceCommands-ZR5BR3GX.js} +59 -59
  210. package/{streamAgentChatTurn-3UXPYFNX.js → streamAgentChatTurn-MN2SSPGA.js} +309 -165
  211. package/{switchDialogAgentAction-GMR7WN3P.js → switchDialogAgentAction-OMGBD3N2.js} +26 -22
  212. package/{tableCommands-G7RV3RU3.js → tableCommands-U3QDY4L6.js} +19 -17
  213. package/{toolApiClient-CVGWM4PN.js → toolApiClient-7WSJJJBV.js} +6 -5
  214. package/tools-W2MOLERY.js +124 -0
  215. package/tuiSummaryLlmCaller-BM3VSTBU.js +130 -0
  216. package/{updateCommands-4EHDLF5J.js → updateCommands-NQXAGFM7.js} +3 -3
  217. package/{updateDialogTitleAction-UPFV7TDT.js → updateDialogTitleAction-Z4JX6REN.js} +102 -57
  218. package/workloadLifecycle-36DXRZKU.js +320 -0
  219. package/action-GI44T4DR.js +0 -31
  220. package/agentListCommands-IW3GQVUP.js +0 -427
  221. package/agentRecordCommands-VCA76W6B.js +0 -134
  222. package/agentRunCommand-YNLDKVR7.js +0 -161
  223. package/browser-image-compression-MFDTD7K6.js +0 -1763
  224. package/chatQueueReduxAdapter-TJRMXMYA.js +0 -186
  225. package/chromeOpsCommands-IXRLN57H.js +0 -289
  226. package/chunk-36KZDDO5.js +0 -2415
  227. package/chunk-ACQD6YI2.js +0 -25363
  228. package/chunk-CQ3WA2NE.js +0 -299
  229. package/chunk-CYSYR67N.js +0 -93
  230. package/chunk-JBTJAPUF.js +0 -35
  231. package/chunk-K2CSUCHJ.js +0 -620
  232. package/chunk-LTRXGFMS.js +0 -83
  233. package/chunk-M76ECQRD.js +0 -13658
  234. package/chunk-MEYIRKDN.js +0 -8967
  235. package/chunk-OCZKATRC.js +0 -129
  236. package/chunk-OTGFTBLI.js +0 -13
  237. package/chunk-PUOC4YRO.js +0 -394
  238. package/chunk-PZZTFEKK.js +0 -34
  239. package/chunk-URMS4XY2.js +0 -10
  240. package/chunk-UV6VISQJ.js +0 -20
  241. package/chunk-VJVNU77E.js +0 -83
  242. package/chunk-XYJSY4KG.js +0 -13807
  243. package/chunk-Y5GCAMGP.js +0 -9
  244. package/chunk-YPREESF4.js +0 -225
  245. package/contentThunks-BDIQRZR6.js +0 -73
  246. package/createDialogAction-B7VGVEVU.js +0 -66
  247. package/dialogCommands-G7YBVAMC.js +0 -102
  248. package/levelLazyShim-GZBKODGI.js +0 -7
  249. package/machineWsRunDispatch-L32G7C4P.js +0 -149
  250. package/serverStoreFactory-YMXDF4NI.js +0 -20
  251. package/setDialogExtraReferencesAction-M32UYNCG.js +0 -30
  252. package/settingSlice-Q6EKL7EQ.js +0 -204
  253. package/syncMapping-N6RGXGBW.js +0 -437
  254. package/tools-MKYDMWA4.js +0 -111
  255. package/tuiSummaryLlmCaller-3YFNHCTW.js +0 -128
  256. package/{chunk-SV5IJK6K.js → chunk-NBTY7YJF.js} +3 -3
  257. package/{chunk-2SYTUTLI.js → chunk-YBNHPX4S.js} +3 -3
  258. package/{offlineMarxistsAgentCommand-HGXZV4XJ.js → offlineMarxistsAgentCommand-2QTHJCHV.js} +4 -4
@@ -0,0 +1,1192 @@
1
+ import {
2
+ getModelContextWindow
3
+ } from "./chunk-BPMPOFWP.js";
4
+ import {
5
+ isRecord
6
+ } from "./chunk-KUG52IAP.js";
7
+ import {
8
+ asOptionalTrimmedString
9
+ } from "./chunk-G3SUCT4W.js";
10
+ import {
11
+ PLATFORM_HOSTED_KIMI_K3_MODEL,
12
+ isFireworksKimiModel,
13
+ isNoloHostedProvider
14
+ } from "./chunk-CHCS6XPJ.js";
15
+ import {
16
+ asTrimmedLowercaseString
17
+ } from "./chunk-QSJ3HFEF.js";
18
+
19
+ // packages/integrations/openai/responsesHelpers.ts
20
+ var RESPONSES_TOP_LEVEL_SCHEMA_KEYS = ["anyOf", "oneOf", "allOf", "enum", "not"];
21
+ var sanitizeResponsesParameters = (parameters) => {
22
+ if (!isRecord(parameters)) {
23
+ return parameters;
24
+ }
25
+ const next = { ...parameters };
26
+ for (const key of RESPONSES_TOP_LEVEL_SCHEMA_KEYS) {
27
+ delete next[key];
28
+ }
29
+ return next;
30
+ };
31
+ var appendTextPart = (parts, text, role) => {
32
+ if (!text) return;
33
+ const last = parts.at(-1);
34
+ const textType = role === "assistant" ? "output_text" : "input_text";
35
+ if (last?.type === textType) {
36
+ last.text += text;
37
+ return;
38
+ }
39
+ parts.push({ type: textType, text });
40
+ };
41
+ var normalizeMessageParts = (content, role) => {
42
+ if (typeof content === "string") {
43
+ if (!content) return [];
44
+ return [
45
+ {
46
+ type: role === "assistant" ? "output_text" : "input_text",
47
+ text: content
48
+ }
49
+ ];
50
+ }
51
+ const parts = [];
52
+ for (const part of content ?? []) {
53
+ const typedPart = part;
54
+ if (typedPart?.type === "text" && typeof typedPart.text === "string") {
55
+ appendTextPart(parts, typedPart.text, role);
56
+ continue;
57
+ }
58
+ if (typedPart?.type === "image_url" && typeof typedPart.image_url?.url === "string" && typedPart.image_url.url) {
59
+ if (role === "assistant") continue;
60
+ parts.push({
61
+ type: "input_image",
62
+ image_url: typedPart.image_url.url,
63
+ detail: typedPart.image_url.detail
64
+ });
65
+ }
66
+ }
67
+ return parts;
68
+ };
69
+ var normalizeToolOutput = (content) => {
70
+ if (typeof content === "string") return content;
71
+ return JSON.stringify(content ?? "");
72
+ };
73
+ var toResponsesTools = (tools) => {
74
+ if (!Array.isArray(tools) || tools.length === 0) return void 0;
75
+ const normalized = tools.map((tool) => {
76
+ const fn = tool?.function;
77
+ const name = fn?.name ?? tool?.name;
78
+ if (!name) return null;
79
+ const parameters = fn?.parameters ?? tool?.parameters;
80
+ return {
81
+ type: "function",
82
+ name,
83
+ ...typeof (fn?.description ?? tool?.description) === "string" ? { description: fn?.description ?? tool?.description } : {},
84
+ parameters: sanitizeResponsesParameters(parameters),
85
+ ...fn?.strict !== void 0 || tool?.strict !== void 0 ? { strict: fn?.strict ?? tool?.strict } : {}
86
+ };
87
+ }).filter(Boolean);
88
+ return normalized.length > 0 ? normalized : void 0;
89
+ };
90
+ var convertMessagesToResponsesInput = (messages, options) => {
91
+ const input = [];
92
+ for (const message of messages) {
93
+ if (!message?.role) continue;
94
+ if (message.role === "tool") {
95
+ if (!message.tool_call_id) continue;
96
+ input.push({
97
+ type: "function_call_output",
98
+ call_id: message.tool_call_id,
99
+ output: normalizeToolOutput(message.content)
100
+ });
101
+ continue;
102
+ }
103
+ const role = message.role;
104
+ if (role === "assistant" && !options?.stripReasoningContent && typeof message.reasoning_content === "string" && message.reasoning_content) {
105
+ input.push({
106
+ type: "reasoning",
107
+ content: [
108
+ { type: "reasoning_text", text: message.reasoning_content }
109
+ ]
110
+ });
111
+ }
112
+ const contentParts = normalizeMessageParts(message.content, role);
113
+ if (contentParts.length > 0) {
114
+ input.push({
115
+ type: "message",
116
+ role,
117
+ content: contentParts
118
+ });
119
+ }
120
+ if (role === "assistant" && Array.isArray(message.content)) {
121
+ const replayImages = message.content.map((part) => part).filter(
122
+ (part) => part?.type === "image_url" && typeof part.image_url?.url === "string" && Boolean(part.image_url.url)
123
+ ).map((part) => ({
124
+ type: "input_image",
125
+ image_url: part.image_url.url,
126
+ detail: part.image_url.detail
127
+ }));
128
+ if (replayImages.length > 0) {
129
+ input.push({
130
+ type: "message",
131
+ role: "user",
132
+ content: replayImages
133
+ });
134
+ }
135
+ }
136
+ if (role === "assistant" && Array.isArray(message.tool_calls)) {
137
+ for (const toolCall of message.tool_calls) {
138
+ if (!toolCall?.id || !toolCall.function?.name) continue;
139
+ input.push({
140
+ type: "function_call",
141
+ call_id: toolCall.id,
142
+ name: toolCall.function.name,
143
+ arguments: typeof toolCall.function.arguments === "string" ? toolCall.function.arguments : JSON.stringify(toolCall.function.arguments ?? {})
144
+ });
145
+ }
146
+ }
147
+ }
148
+ return input;
149
+ };
150
+ var extractTextFromResponseOutput = (response) => {
151
+ const parts = [];
152
+ for (const item of response?.output ?? []) {
153
+ if (item?.type !== "message") continue;
154
+ for (const content of item.content ?? []) {
155
+ if (content?.type === "output_text" && typeof content.text === "string") {
156
+ parts.push(content.text);
157
+ }
158
+ }
159
+ }
160
+ return parts.join("");
161
+ };
162
+ var extractReasoningFromResponseOutput = (response) => {
163
+ const parts = [];
164
+ for (const item of response?.output ?? []) {
165
+ if (item?.type !== "reasoning") continue;
166
+ if (typeof item.content === "string") {
167
+ parts.push(item.content);
168
+ continue;
169
+ }
170
+ for (const content of item.content ?? []) {
171
+ if (typeof content === "string") parts.push(content);
172
+ else if (typeof content?.text === "string") parts.push(content.text);
173
+ }
174
+ }
175
+ return parts.join("");
176
+ };
177
+ var toDataUrl = (base64Data, mimeType) => {
178
+ const normalizedMimeType = asOptionalTrimmedString(mimeType) ?? "image/png";
179
+ return `data:${normalizedMimeType};base64,${base64Data}`;
180
+ };
181
+ var extractImagePartsFromResponseOutput = (response) => {
182
+ const images = [];
183
+ for (const item of response?.output ?? []) {
184
+ if (item?.type === "image_generation_call") {
185
+ const result = asOptionalTrimmedString(item.result);
186
+ if (result) {
187
+ const outputFormat = asOptionalTrimmedString(item.output_format);
188
+ images.push({
189
+ type: "image_url",
190
+ image_url: {
191
+ url: toDataUrl(
192
+ result,
193
+ outputFormat ? `image/${outputFormat}` : void 0
194
+ )
195
+ }
196
+ });
197
+ }
198
+ continue;
199
+ }
200
+ if (item?.type !== "message") continue;
201
+ for (const content of item.content ?? []) {
202
+ const result = asOptionalTrimmedString(content?.result);
203
+ if (content?.type === "output_image" && result) {
204
+ images.push({
205
+ type: "image_url",
206
+ image_url: {
207
+ url: toDataUrl(
208
+ result,
209
+ content.mime_type ?? content.mimeType ?? null
210
+ )
211
+ }
212
+ });
213
+ }
214
+ }
215
+ }
216
+ return images;
217
+ };
218
+ var extractToolCallsFromResponseOutput = (response) => {
219
+ const calls = [];
220
+ for (const item of response?.output ?? []) {
221
+ if (item?.type !== "function_call") continue;
222
+ if (!item.call_id || !item.name) continue;
223
+ calls.push({
224
+ id: item.call_id,
225
+ type: "function",
226
+ function: {
227
+ name: item.name,
228
+ arguments: typeof item.arguments === "string" ? item.arguments : JSON.stringify(item.arguments ?? {})
229
+ }
230
+ });
231
+ }
232
+ return calls;
233
+ };
234
+
235
+ // packages/agent-runtime/declaredToolNames.ts
236
+ function extractDeclaredToolNames(tools) {
237
+ if (!Array.isArray(tools)) return void 0;
238
+ const names = /* @__PURE__ */ new Set();
239
+ for (const t of tools) {
240
+ const fn = t?.function;
241
+ if (fn && typeof fn.name === "string" && fn.name) names.add(fn.name);
242
+ }
243
+ return names;
244
+ }
245
+
246
+ // packages/agent-runtime/toolArgsShape.ts
247
+ function scanRawToolArgs(input) {
248
+ const stack = [];
249
+ const commaAtDepth = [];
250
+ let inString = false;
251
+ let escaped = false;
252
+ const closersOf2 = () => stack.slice().reverse().map((ch) => ch === "{" ? "}" : "]").join("");
253
+ for (let i = 0; i < input.length; i += 1) {
254
+ const ch = input[i];
255
+ if (inString) {
256
+ if (escaped) escaped = false;
257
+ else if (ch === "\\") escaped = true;
258
+ else if (ch === '"') inString = false;
259
+ continue;
260
+ }
261
+ if (ch === '"') {
262
+ inString = true;
263
+ } else if (ch === "{" || ch === "[") {
264
+ stack.push(ch);
265
+ commaAtDepth[stack.length] = void 0;
266
+ } else if (ch === "}" || ch === "]") {
267
+ const open = stack.pop();
268
+ if (open !== (ch === "}" ? "{" : "[")) {
269
+ return {
270
+ inString,
271
+ mismatched: true,
272
+ unclosed: false,
273
+ // 结构已坏:与迁移前一致,不再给出尾部数组逗号坐标。
274
+ tailArrayComma: null
275
+ };
276
+ }
277
+ commaAtDepth[stack.length + 1] = void 0;
278
+ } else if (ch === "," && stack[stack.length - 1] === "[") {
279
+ commaAtDepth[stack.length] = { index: i, closers: closersOf2() };
280
+ }
281
+ }
282
+ let tailArrayComma = null;
283
+ for (let d = stack.length; d >= 1; d -= 1) {
284
+ const c = commaAtDepth[d];
285
+ if (c && stack[d - 1] === "[") {
286
+ tailArrayComma = c;
287
+ break;
288
+ }
289
+ }
290
+ return {
291
+ inString,
292
+ mismatched: false,
293
+ unclosed: stack.length > 0,
294
+ tailArrayComma
295
+ };
296
+ }
297
+ function scanTruncation(input) {
298
+ const scan = scanRawToolArgs(input);
299
+ return {
300
+ inString: scan.inString,
301
+ malformed: scan.mismatched,
302
+ tailArrayComma: scan.tailArrayComma
303
+ };
304
+ }
305
+ function classifyUnparsableToolArgs(raw) {
306
+ if (typeof raw !== "string") return "malformed";
307
+ const scan = scanRawToolArgs(raw);
308
+ if (scan.inString) return "truncated";
309
+ return scan.mismatched || scan.unclosed ? "truncated" : "malformed";
310
+ }
311
+
312
+ // packages/agent-runtime/outboundHistorySanitize.ts
313
+ var DOWNGRADED_TOOL_TURN_ORIGIN = Symbol(
314
+ "nolo.downgradedToolTurnOrigin"
315
+ );
316
+ function markDowngradedToolTurnOrigin(message) {
317
+ Object.defineProperty(message, DOWNGRADED_TOOL_TURN_ORIGIN, {
318
+ value: true,
319
+ enumerable: false,
320
+ writable: false,
321
+ configurable: true
322
+ });
323
+ return message;
324
+ }
325
+ function transferDowngradedToolTurnOrigin(source, rebuilt) {
326
+ if (hasDowngradedToolTurnOrigin(source)) markDowngradedToolTurnOrigin(rebuilt);
327
+ return rebuilt;
328
+ }
329
+ function hasDowngradedToolTurnOrigin(message) {
330
+ return typeof message === "object" && message !== null && message[DOWNGRADED_TOOL_TURN_ORIGIN] === true;
331
+ }
332
+ function emptyToolArgsProjectionStats() {
333
+ return {
334
+ badArguments: { truncated: 0, malformed: 0 },
335
+ rewrittenToolCalls: 0,
336
+ rewrittenAssistantMessages: 0,
337
+ rewrittenToolMessages: 0
338
+ };
339
+ }
340
+ function sanitizeForOutbound(messages, tools) {
341
+ return sanitizeOutboundHistory(messages, {
342
+ declaredToolNames: extractDeclaredToolNames(tools)
343
+ });
344
+ }
345
+ function stableToolCallId(assistantIndex, callIndex) {
346
+ return `call_sanitize_${assistantIndex}_${callIndex}`;
347
+ }
348
+ function isString(v) {
349
+ return typeof v === "string";
350
+ }
351
+ function isNonEmptyString(v) {
352
+ return typeof v === "string" && v.length > 0;
353
+ }
354
+ function joinLines(...parts) {
355
+ return parts.filter(isNonEmptyString).join("\n");
356
+ }
357
+ function jsonStringifyArguments(args) {
358
+ if (typeof args === "string") return args;
359
+ try {
360
+ return JSON.stringify(args ?? "");
361
+ } catch {
362
+ return "";
363
+ }
364
+ }
365
+ function renderToolCallAsText(call) {
366
+ const c = call && typeof call === "object" ? call : {};
367
+ const name = isString(c.function?.name) && c.function.name.length > 0 ? c.function.name : "unknown";
368
+ const rawArgs = c.function?.arguments;
369
+ const args = jsonStringifyArguments(rawArgs);
370
+ return `[tool_call: ${name}(${args})]`;
371
+ }
372
+ function renderToolResultAsText(message) {
373
+ const name = isNonEmptyString(message.toolName) ? message.toolName : "tool";
374
+ const body = typeof message.content === "string" ? message.content : "";
375
+ return `[tool_result: ${name}: ${body}]`;
376
+ }
377
+ function normalizeToolCall(call, assistantIndex, callIndex) {
378
+ if (!call || typeof call !== "object") return null;
379
+ const c = call;
380
+ const fn = c.function;
381
+ if (!fn || typeof fn !== "object" || !isString(fn.name) || fn.name.length === 0) return null;
382
+ const id = isNonEmptyString(c.id) ? c.id : stableToolCallId(assistantIndex, callIndex);
383
+ return {
384
+ id,
385
+ type: isString(c.type) && c.type ? c.type : "function",
386
+ function: { name: fn.name, arguments: jsonStringifyArguments(fn.arguments) },
387
+ ...typeof c.extra_content?.google?.thought_signature === "string" ? { extra_content: { google: { thought_signature: c.extra_content.google.thought_signature } } } : {},
388
+ ...typeof c.thought_signature === "string" ? { thought_signature: c.thought_signature } : {}
389
+ };
390
+ }
391
+ function classifyAssistantCalls(toolCalls, assistantIndex) {
392
+ const callIds = [];
393
+ const idCounts = /* @__PURE__ */ new Map();
394
+ const unparsableIndices = /* @__PURE__ */ new Set();
395
+ const unparsableIds = /* @__PURE__ */ new Set();
396
+ toolCalls.forEach((rawCall, callIndex) => {
397
+ const c = rawCall && typeof rawCall === "object" ? rawCall : {};
398
+ const id = isNonEmptyString(c.id) ? c.id : stableToolCallId(assistantIndex, callIndex);
399
+ callIds.push(id);
400
+ idCounts.set(id, (idCounts.get(id) ?? 0) + 1);
401
+ if (!hasParsableObjectArguments(c.function?.arguments)) {
402
+ unparsableIndices.add(callIndex);
403
+ unparsableIds.add(id);
404
+ }
405
+ });
406
+ const duplicateIds = /* @__PURE__ */ new Set();
407
+ for (const [id, count] of idCounts) {
408
+ if (count > 1) duplicateIds.add(id);
409
+ }
410
+ return { callIds, duplicateIds, unparsableIndices, unparsableIds };
411
+ }
412
+ function sanitizeOutboundHistory(messages, options) {
413
+ if (!Array.isArray(messages) || messages.length === 0) return messages;
414
+ const declared = options?.declaredToolNames;
415
+ const keptCallIndicesPerAssistant = /* @__PURE__ */ new Map();
416
+ const keptToolIndices = /* @__PURE__ */ new Set();
417
+ let i = 0;
418
+ while (i < messages.length) {
419
+ const m = messages[i];
420
+ if (m.role === "assistant" && Array.isArray(m.tool_calls) && m.tool_calls.length > 0) {
421
+ const asstIdx = i;
422
+ const { callIds, duplicateIds, unparsableIndices } = classifyAssistantCalls(m.tool_calls, asstIdx);
423
+ const candidateCallMap = /* @__PURE__ */ new Map();
424
+ m.tool_calls.forEach((call, callIndex) => {
425
+ const id = callIds[callIndex];
426
+ if (duplicateIds.has(id)) return;
427
+ if (unparsableIndices.has(callIndex)) return;
428
+ const name = call?.function?.name;
429
+ if (!isString(name) || name.length === 0) return;
430
+ const declaredAllows = !declared || declared.has(name);
431
+ if (!declaredAllows) return;
432
+ candidateCallMap.set(id, callIndex);
433
+ });
434
+ let j = i + 1;
435
+ const matchedCallIndices = /* @__PURE__ */ new Set();
436
+ const matchedToolIds = /* @__PURE__ */ new Set();
437
+ while (j < messages.length && messages[j].role === "tool") {
438
+ const toolMsg = messages[j];
439
+ const toolCallId = isNonEmptyString(toolMsg.tool_call_id) ? toolMsg.tool_call_id : "";
440
+ if (toolCallId && candidateCallMap.has(toolCallId) && !matchedToolIds.has(toolCallId)) {
441
+ matchedToolIds.add(toolCallId);
442
+ matchedCallIndices.add(candidateCallMap.get(toolCallId));
443
+ keptToolIndices.add(j);
444
+ }
445
+ j++;
446
+ }
447
+ keptCallIndicesPerAssistant.set(asstIdx, matchedCallIndices);
448
+ i = j;
449
+ } else {
450
+ i++;
451
+ }
452
+ }
453
+ const out = [];
454
+ let k = 0;
455
+ while (k < messages.length) {
456
+ const m = messages[k];
457
+ if (m.role === "assistant" && Array.isArray(m.tool_calls) && m.tool_calls.length > 0) {
458
+ const asstIdx = k;
459
+ const keptIndices = keptCallIndicesPerAssistant.get(asstIdx) ?? /* @__PURE__ */ new Set();
460
+ const keptToolCalls = [];
461
+ const downgradedCallLines = [];
462
+ m.tool_calls.forEach((call, callIndex) => {
463
+ const name = call?.function?.name;
464
+ const declaredAllows = !declared || isString(name) && declared.has(name);
465
+ const keep = keptIndices.has(callIndex) && declaredAllows && hasParsableObjectArguments(call?.function?.arguments);
466
+ if (keep) {
467
+ const normalized = normalizeToolCall(call, asstIdx, callIndex);
468
+ if (normalized) {
469
+ keptToolCalls.push(normalized);
470
+ } else {
471
+ downgradedCallLines.push(renderToolCallAsText(call));
472
+ }
473
+ } else {
474
+ downgradedCallLines.push(renderToolCallAsText(call));
475
+ }
476
+ });
477
+ if (keptToolCalls.length === 0) {
478
+ const downgradedText = joinLines(...downgradedCallLines);
479
+ const contentWithDowngrade = downgradedText.length > 0 ? combineContentWithText(m.content, downgradedText) : m.content;
480
+ const sanitizedAssistant2 = transferDowngradedToolTurnOrigin(m, {
481
+ ...m,
482
+ content: contentWithDowngrade
483
+ });
484
+ delete sanitizedAssistant2.tool_calls;
485
+ markDowngradedToolTurnOrigin(sanitizedAssistant2);
486
+ out.push(sanitizedAssistant2);
487
+ let nextIdx2 = k + 1;
488
+ while (nextIdx2 < messages.length && messages[nextIdx2].role === "tool") {
489
+ const downgradedToolMsg = messages[nextIdx2];
490
+ out.push(
491
+ transferDowngradedToolTurnOrigin(downgradedToolMsg, {
492
+ role: "assistant",
493
+ content: renderToolResultAsText(downgradedToolMsg)
494
+ })
495
+ );
496
+ nextIdx2++;
497
+ }
498
+ k = nextIdx2;
499
+ continue;
500
+ }
501
+ const sanitizedAssistant = transferDowngradedToolTurnOrigin(m, {
502
+ ...m,
503
+ tool_calls: keptToolCalls
504
+ });
505
+ out.push(sanitizedAssistant);
506
+ let nextIdx = k + 1;
507
+ const deferredResultLines = [];
508
+ while (nextIdx < messages.length && messages[nextIdx].role === "tool") {
509
+ if (keptToolIndices.has(nextIdx)) {
510
+ const toolMsg = messages[nextIdx];
511
+ out.push({
512
+ ...toolMsg,
513
+ content: toolMsg.content ?? "",
514
+ tool_call_id: toolMsg.tool_call_id
515
+ });
516
+ } else {
517
+ deferredResultLines.push(renderToolResultAsText(messages[nextIdx]));
518
+ }
519
+ nextIdx++;
520
+ }
521
+ const deferredLines = [...downgradedCallLines, ...deferredResultLines];
522
+ if (deferredLines.length > 0) {
523
+ out.push({
524
+ role: "assistant",
525
+ content: joinLines(...deferredLines)
526
+ });
527
+ }
528
+ k = nextIdx;
529
+ continue;
530
+ }
531
+ if (m.role === "tool") {
532
+ out.push(
533
+ transferDowngradedToolTurnOrigin(m, {
534
+ role: "assistant",
535
+ content: renderToolResultAsText(m)
536
+ })
537
+ );
538
+ k++;
539
+ continue;
540
+ }
541
+ out.push(transferDowngradedToolTurnOrigin(m, { ...m }));
542
+ k++;
543
+ }
544
+ return out;
545
+ }
546
+ function combineContentWithText(base, extra) {
547
+ if (typeof base === "string") {
548
+ return base ? `${base}
549
+ ${extra}` : extra;
550
+ }
551
+ if (Array.isArray(base)) {
552
+ return [...base, { type: "text", text: extra }];
553
+ }
554
+ return extra;
555
+ }
556
+ function hasParsableObjectArguments(raw) {
557
+ if (raw === void 0) return true;
558
+ if (raw === null || typeof raw === "number" || typeof raw === "boolean") {
559
+ return false;
560
+ }
561
+ if (typeof raw !== "string") return true;
562
+ if (raw.trim() === "") return true;
563
+ try {
564
+ const parsed = JSON.parse(raw);
565
+ return parsed !== null && typeof parsed === "object";
566
+ } catch {
567
+ return false;
568
+ }
569
+ }
570
+ var STRICT_JSON_STRING_TOKEN = /^"(?:[^"\\\u0000-\u001F]|\\["\\/bfnrt]|\\u[0-9A-Fa-f]{4})*"$/;
571
+ function isStrictJsonStringToken(value) {
572
+ if (!STRICT_JSON_STRING_TOKEN.test(value)) return false;
573
+ try {
574
+ return typeof JSON.parse(value) === "string";
575
+ } catch {
576
+ return false;
577
+ }
578
+ }
579
+ function closersOf(openStack) {
580
+ return openStack.slice().reverse().map((ch) => ch === "{" ? "}" : "]").join("");
581
+ }
582
+ function scanJsonForTailRepair(input) {
583
+ const stack = [];
584
+ let inString = false;
585
+ let escaped = false;
586
+ let lastCommaOutsideString = null;
587
+ for (let i = 0; i < input.length; i += 1) {
588
+ const ch = input[i];
589
+ if (inString) {
590
+ if (escaped) escaped = false;
591
+ else if (ch === "\\") escaped = true;
592
+ else if (ch === '"') inString = false;
593
+ continue;
594
+ }
595
+ if (ch === '"') {
596
+ inString = true;
597
+ continue;
598
+ }
599
+ if (ch === "{" || ch === "[") {
600
+ stack.push(ch);
601
+ continue;
602
+ }
603
+ if (ch === "}" || ch === "]") {
604
+ const open = stack.pop();
605
+ if (open !== (ch === "}" ? "{" : "[")) return null;
606
+ continue;
607
+ }
608
+ if (ch === ",") {
609
+ lastCommaOutsideString = { index: i, closers: closersOf(stack) };
610
+ continue;
611
+ }
612
+ }
613
+ return { inString, closers: closersOf(stack), lastCommaOutsideString };
614
+ }
615
+ function repairTruncatedToolArguments(raw) {
616
+ if (typeof raw !== "string") return null;
617
+ const withoutTrailingSpace = raw.replace(/\s+$/, "");
618
+ const endsWithComma = withoutTrailingSpace.endsWith(",");
619
+ const trimmed = endsWithComma ? withoutTrailingSpace.slice(0, -1).replace(/\s+$/, "") : withoutTrailingSpace;
620
+ if (trimmed === "" || trimmed.endsWith(",")) return null;
621
+ const scan = scanJsonForTailRepair(trimmed);
622
+ if (!scan || scan.inString) return null;
623
+ const lastChar = trimmed[trimmed.length - 1];
624
+ const tailIsCompleteToken = endsWithComma || lastChar === '"' || lastChar === "}" || lastChar === "]";
625
+ if (!tailIsCompleteToken) return null;
626
+ const candidates = [trimmed + scan.closers];
627
+ const lastComma = scan.lastCommaOutsideString;
628
+ if (lastComma && lastComma.index > 0) {
629
+ const tailAfterComma = trimmed.slice(lastComma.index + 1).trim();
630
+ if (isStrictJsonStringToken(tailAfterComma)) {
631
+ const head = trimmed.slice(0, lastComma.index);
632
+ candidates.push(head + lastComma.closers);
633
+ }
634
+ }
635
+ for (const candidate of candidates) {
636
+ try {
637
+ const parsed = JSON.parse(candidate);
638
+ if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) && Object.keys(parsed).length > 0) {
639
+ return candidate;
640
+ }
641
+ } catch {
642
+ }
643
+ }
644
+ return null;
645
+ }
646
+ function downgradeUnparsableToolCalls(messages) {
647
+ if (!Array.isArray(messages) || messages.length === 0) {
648
+ return { messages, downgraded: 0, stats: emptyToolArgsProjectionStats() };
649
+ }
650
+ let hasAnyPoison = false;
651
+ for (const m of messages) {
652
+ if (m.role === "assistant" && Array.isArray(m.tool_calls)) {
653
+ for (const call of m.tool_calls) {
654
+ if (!hasParsableObjectArguments(call?.function?.arguments)) {
655
+ hasAnyPoison = true;
656
+ break;
657
+ }
658
+ }
659
+ }
660
+ if (hasAnyPoison) break;
661
+ }
662
+ if (!hasAnyPoison) return { messages, downgraded: 0, stats: emptyToolArgsProjectionStats() };
663
+ const poisonedCallsPerAssistant = /* @__PURE__ */ new Map();
664
+ const poisonedToolIndices = /* @__PURE__ */ new Set();
665
+ const badArguments = {
666
+ truncated: 0,
667
+ malformed: 0
668
+ };
669
+ let i = 0;
670
+ while (i < messages.length) {
671
+ const m = messages[i];
672
+ if (m.role === "assistant" && Array.isArray(m.tool_calls) && m.tool_calls.length > 0) {
673
+ const asstIdx = i;
674
+ const { unparsableIds, unparsableIndices } = classifyAssistantCalls(m.tool_calls, asstIdx);
675
+ for (const badIndex of unparsableIndices) {
676
+ const badCall = m.tool_calls[badIndex];
677
+ badArguments[classifyUnparsableToolArgs(badCall?.function?.arguments)] += 1;
678
+ }
679
+ let j = i + 1;
680
+ while (j < messages.length && messages[j].role === "tool") {
681
+ const toolMsg = messages[j];
682
+ const toolCallId = isNonEmptyString(toolMsg.tool_call_id) ? toolMsg.tool_call_id : "";
683
+ if (toolCallId && unparsableIds.has(toolCallId)) {
684
+ poisonedToolIndices.add(j);
685
+ }
686
+ j++;
687
+ }
688
+ if (unparsableIds.size > 0) {
689
+ poisonedCallsPerAssistant.set(asstIdx, unparsableIds);
690
+ }
691
+ i = j;
692
+ } else {
693
+ i++;
694
+ }
695
+ }
696
+ let downgraded = 0;
697
+ let rewrittenAssistantMessages = 0;
698
+ let rewrittenToolMessages = 0;
699
+ const out = [];
700
+ let k = 0;
701
+ while (k < messages.length) {
702
+ const m = messages[k];
703
+ if (m.role === "assistant" && Array.isArray(m.tool_calls) && m.tool_calls.length > 0) {
704
+ const badIds = poisonedCallsPerAssistant.get(k);
705
+ if (!badIds || badIds.size === 0) {
706
+ out.push(m);
707
+ k++;
708
+ continue;
709
+ }
710
+ const kept = [];
711
+ const lines = [];
712
+ const { callIds } = classifyAssistantCalls(m.tool_calls, k);
713
+ rewrittenAssistantMessages += 1;
714
+ m.tool_calls.forEach((call, callIndex) => {
715
+ const id = callIds[callIndex];
716
+ if (badIds.has(id)) {
717
+ lines.push(renderToolCallAsText(call));
718
+ downgraded++;
719
+ } else {
720
+ kept.push(call);
721
+ }
722
+ });
723
+ if (kept.length === 0) {
724
+ const sanitized2 = transferDowngradedToolTurnOrigin(m, {
725
+ ...m,
726
+ content: combineContentWithText(m.content, joinLines(...lines))
727
+ });
728
+ delete sanitized2.tool_calls;
729
+ markDowngradedToolTurnOrigin(sanitized2);
730
+ out.push(sanitized2);
731
+ let nextIdx2 = k + 1;
732
+ while (nextIdx2 < messages.length && messages[nextIdx2].role === "tool") {
733
+ if (poisonedToolIndices.has(nextIdx2)) {
734
+ const poisonedToolMsg = messages[nextIdx2];
735
+ out.push(
736
+ transferDowngradedToolTurnOrigin(poisonedToolMsg, {
737
+ role: "assistant",
738
+ content: renderToolResultAsText(poisonedToolMsg)
739
+ })
740
+ );
741
+ rewrittenToolMessages += 1;
742
+ } else {
743
+ out.push(messages[nextIdx2]);
744
+ }
745
+ nextIdx2++;
746
+ }
747
+ k = nextIdx2;
748
+ continue;
749
+ }
750
+ const sanitized = transferDowngradedToolTurnOrigin(m, {
751
+ ...m,
752
+ content: lines.length > 0 ? combineContentWithText(m.content, joinLines(...lines)) : m.content,
753
+ tool_calls: kept
754
+ });
755
+ out.push(sanitized);
756
+ let nextIdx = k + 1;
757
+ const deferredResultLines = [];
758
+ while (nextIdx < messages.length && messages[nextIdx].role === "tool") {
759
+ if (poisonedToolIndices.has(nextIdx)) {
760
+ deferredResultLines.push(renderToolResultAsText(messages[nextIdx]));
761
+ rewrittenToolMessages += 1;
762
+ } else {
763
+ out.push(messages[nextIdx]);
764
+ }
765
+ nextIdx++;
766
+ }
767
+ if (deferredResultLines.length > 0) {
768
+ out.push({
769
+ role: "assistant",
770
+ content: joinLines(...deferredResultLines)
771
+ });
772
+ }
773
+ k = nextIdx;
774
+ continue;
775
+ }
776
+ if (m.role === "tool") {
777
+ if (poisonedToolIndices.has(k)) {
778
+ out.push(
779
+ transferDowngradedToolTurnOrigin(m, {
780
+ role: "assistant",
781
+ content: renderToolResultAsText(m)
782
+ })
783
+ );
784
+ rewrittenToolMessages += 1;
785
+ } else {
786
+ out.push(m);
787
+ }
788
+ k++;
789
+ continue;
790
+ }
791
+ out.push(m);
792
+ k++;
793
+ }
794
+ return {
795
+ messages: out,
796
+ downgraded,
797
+ stats: {
798
+ badArguments,
799
+ // 投影改写数与坏参数数是两套口径:rewrittenToolCalls 含同 ID 连带降级的
800
+ // 调用,二者允许不相等(同 ID 一坏一好 → 坏参数 1、改写调用 2)。
801
+ rewrittenToolCalls: downgraded,
802
+ rewrittenAssistantMessages,
803
+ rewrittenToolMessages
804
+ }
805
+ };
806
+ }
807
+
808
+ // packages/core/ollamaEndpoint.ts
809
+ function isOllamaEndpoint(endpoint) {
810
+ if (!endpoint || typeof endpoint !== "string") return false;
811
+ try {
812
+ const url = new URL(endpoint.includes("://") ? endpoint : `http://${endpoint}`);
813
+ if (url.port === "11434") return true;
814
+ const host = url.hostname.toLowerCase();
815
+ return host === "ollama.com" || host.endsWith(".ollama.com") || host === "ollama.ai" || host.endsWith(".ollama.ai");
816
+ } catch {
817
+ return false;
818
+ }
819
+ }
820
+
821
+ // packages/ai/llm/usageRequestOptions.ts
822
+ var STREAM_USAGE_PROVIDERS = /* @__PURE__ */ new Set([
823
+ "google",
824
+ "openrouter",
825
+ "xai",
826
+ "openai",
827
+ "fireworks",
828
+ "mistral",
829
+ "cloudflare",
830
+ "gmi",
831
+ // OpenAI-compatible hosted providers expose the terminal usage chunk when
832
+ // requested, including DeepInfra and Vultr. Keep this capability decision
833
+ // in the shared seam so proxy and local runtimes cannot drift.
834
+ "deepinfra",
835
+ "vultr",
836
+ // Explicit local-runtime providers with OpenAI-compatible streaming: both
837
+ // DeepSeek official and Ollama honor stream_options.include_usage on their
838
+ // chat.completions endpoints. Without them, locally-configured agents lose
839
+ // token statistics / local billing (the whitelist replaced the previous
840
+ // always-on include_usage). ollama-cloud is the Ollama Cloud subscription
841
+ // endpoint (https://ollama.com/v1), an OpenAI-compatible API that likewise
842
+ // honors stream_options.include_usage.
843
+ "deepseek",
844
+ "ollama",
845
+ "ollama-cloud",
846
+ // RunInfra hosted fallback channel: OpenAI-compatible chat.completions
847
+ // endpoint, supports stream_options.include_usage (measured to return
848
+ // prompt_tokens_details.cached_tokens).
849
+ "runinfra",
850
+ "baseten",
851
+ // Kimi For Coding subscription (api.kimi.com/coding/v1): OpenAI-compatible
852
+ // chat.completions streaming that only emits the terminal usage frame when
853
+ // stream_options.include_usage is requested (measured; the official
854
+ // kimi-code CLI also sends include_usage). Custom agents pointing at the
855
+ // same endpoint are covered by the endpoint check below, not here.
856
+ "kimi-code",
857
+ // OpenDesign (open-design.ai) and OpenCode Go (opencode.ai): OpenAI-compatible
858
+ // aggregation / subscription endpoints. Verified to emit terminal usage with
859
+ // prompt_tokens_details.cached_tokens.
860
+ "opendesign",
861
+ "opencode",
862
+ "opencode-go"
863
+ ]);
864
+ var KIMI_CODE_ENDPOINT_MARKER = "api.kimi.com";
865
+ var isSupportedCustomEndpoint = (endpoint) => {
866
+ if (typeof endpoint !== "string") return false;
867
+ const ep = endpoint.toLowerCase();
868
+ return ep.includes(KIMI_CODE_ENDPOINT_MARKER) || ep.includes("open-design.ai") || ep.includes("opencode.ai") || isOllamaEndpoint(endpoint);
869
+ };
870
+ var EXTRA_USAGE_FIELD_PROVIDERS = /* @__PURE__ */ new Set(["openrouter"]);
871
+ var normalizeProviderName = (providerName) => asTrimmedLowercaseString(providerName);
872
+ var getUsageRequestOptions = (providerName, options) => {
873
+ const normalizedProvider = normalizeProviderName(providerName);
874
+ const api = options?.api ?? "chat-completions";
875
+ const shouldRequestStreamUsage = STREAM_USAGE_PROVIDERS.has(normalizedProvider) || normalizedProvider === "custom" && isSupportedCustomEndpoint(options?.endpoint);
876
+ if (api === "responses") {
877
+ return EXTRA_USAGE_FIELD_PROVIDERS.has(normalizedProvider) ? {
878
+ usage: {
879
+ include: true
880
+ }
881
+ } : {};
882
+ }
883
+ return {
884
+ ...shouldRequestStreamUsage ? {
885
+ stream_options: {
886
+ include_usage: true
887
+ }
888
+ } : {},
889
+ ...EXTRA_USAGE_FIELD_PROVIDERS.has(normalizedProvider) ? {
890
+ usage: {
891
+ include: true
892
+ }
893
+ } : {}
894
+ };
895
+ };
896
+
897
+ // packages/core/chat/imageParts.ts
898
+ function isImageUrlPart(part) {
899
+ return isRecord(part) && part.type === "image_url";
900
+ }
901
+ function hasImageParts(messages) {
902
+ return messages.some(
903
+ (message) => Array.isArray(message.content) && message.content.some(isImageUrlPart)
904
+ );
905
+ }
906
+
907
+ // packages/core/chat/bareImageUrlShape.ts
908
+ function requiresBareImageUrl(args) {
909
+ const model = asTrimmedLowercaseString(args.model);
910
+ if (!model.startsWith("gpt-")) return false;
911
+ const provider = asTrimmedLowercaseString(args.provider);
912
+ if (provider === "opencode-go") return true;
913
+ return asTrimmedLowercaseString(args.endpoint).includes("opencode.ai/zen/go");
914
+ }
915
+ function toBareImageUrlContent(content) {
916
+ if (!Array.isArray(content)) return content;
917
+ let changed = false;
918
+ const parts = content.map((part) => {
919
+ if (!isImageUrlPart(part)) return part;
920
+ const imageUrl = part.image_url;
921
+ if (!imageUrl || typeof imageUrl !== "object") return part;
922
+ const url = imageUrl.url;
923
+ if (typeof url !== "string" || !url) return part;
924
+ changed = true;
925
+ return { ...part, image_url: url };
926
+ });
927
+ return changed ? parts : content;
928
+ }
929
+ function toBareImageUrlMessages(messages) {
930
+ return messages.map((message) => {
931
+ const content = toBareImageUrlContent(message.content);
932
+ return content === message.content ? message : { ...message, content };
933
+ });
934
+ }
935
+
936
+ // packages/agent-runtime/openAiCompatibleMessages.ts
937
+ function isGeminiCompatibleTarget(provider, model) {
938
+ const p = (provider ?? "").trim().toLowerCase();
939
+ const m = (model ?? "").trim().toLowerCase();
940
+ return p === "google" || p === "google-antigravity" || p.startsWith("google-") || p.includes("gemini") || m.includes("gemini");
941
+ }
942
+ function preserveAgentStateFields(source, target, options) {
943
+ const mutableTarget = target;
944
+ if (source.role === "assistant") {
945
+ const shapingCounts = options?.shapingCounts;
946
+ if (!options?.stripReasoningContent && typeof source.reasoning_content === "string") {
947
+ mutableTarget.reasoning_content = source.reasoning_content;
948
+ }
949
+ if (Array.isArray(source.tool_calls)) {
950
+ if (shapingCounts && source.tool_calls.length > 0) {
951
+ shapingCounts.assistantToolTurns += 1;
952
+ const hadUsableReasoning = typeof source.reasoning_content === "string" && source.reasoning_content.length > 0;
953
+ if (options?.stripReasoningContent) {
954
+ if (hadUsableReasoning) shapingCounts.reasoningStrippedTurns += 1;
955
+ else shapingCounts.missingReasoningTurns += 1;
956
+ } else if (!hadUsableReasoning) {
957
+ shapingCounts.missingReasoningTurns += 1;
958
+ }
959
+ }
960
+ const isExplicitTarget = Boolean(options?.targetProvider || options?.targetModel);
961
+ const allowSignature = options?.allowThoughtSignature ?? (isExplicitTarget ? isGeminiCompatibleTarget(options?.targetProvider, options?.targetModel) : true);
962
+ mutableTarget.tool_calls = source.tool_calls.map((call) => {
963
+ if (!call || typeof call !== "object") return call;
964
+ const cleaned = {
965
+ id: call.id,
966
+ type: call.type ?? "function",
967
+ function: call.function
968
+ };
969
+ if (allowSignature) {
970
+ if (call.extra_content !== void 0) cleaned.extra_content = call.extra_content;
971
+ if (call.thought_signature !== void 0) cleaned.thought_signature = call.thought_signature;
972
+ }
973
+ return cleaned;
974
+ });
975
+ }
976
+ const hasReplayableToolCalls = Array.isArray(mutableTarget.tool_calls) && mutableTarget.tool_calls.length > 0;
977
+ const replayPlaceholder = options?.replayReasoningPlaceholder;
978
+ if (typeof replayPlaceholder === "string" && replayPlaceholder.length > 0 && // strip 优先:拒 string reasoning_content 的 provider 也会拒这个占位。
979
+ !options?.stripReasoningContent && (hasReplayableToolCalls || hasDowngradedToolTurnOrigin(source)) && !// 真实 reasoning_content 优先,永不被占位覆盖。
980
+ (typeof mutableTarget.reasoning_content === "string" && mutableTarget.reasoning_content.length > 0)) {
981
+ mutableTarget.reasoning_content = replayPlaceholder;
982
+ if (shapingCounts) shapingCounts.placeholderInjectedTurns += 1;
983
+ }
984
+ }
985
+ if (source.role === "tool") {
986
+ const toolCallId = typeof source.tool_call_id === "string" ? source.tool_call_id.trim() : typeof source.toolCallId === "string" ? source.toolCallId.trim() : "";
987
+ if (toolCallId) mutableTarget.tool_call_id = toolCallId;
988
+ }
989
+ return target;
990
+ }
991
+ function findAgentStatePairingIssues(messages) {
992
+ const issues = [];
993
+ const callIds = /* @__PURE__ */ new Set();
994
+ const resultIds = /* @__PURE__ */ new Set();
995
+ for (const message of messages) {
996
+ if (message.role === "assistant" && Array.isArray(message.tool_calls)) {
997
+ for (const call of message.tool_calls) {
998
+ const id = typeof call?.id === "string" ? call.id.trim() : "";
999
+ if (!id) {
1000
+ issues.push("assistant tool call is missing id");
1001
+ } else if (callIds.has(id)) {
1002
+ issues.push(`duplicate assistant tool call id: ${id}`);
1003
+ } else {
1004
+ callIds.add(id);
1005
+ }
1006
+ }
1007
+ }
1008
+ if (message.role === "tool") {
1009
+ const id = typeof message.tool_call_id === "string" ? message.tool_call_id.trim() : typeof message.toolCallId === "string" ? message.toolCallId.trim() : "";
1010
+ if (!id) {
1011
+ issues.push("tool result is missing tool_call_id");
1012
+ } else if (resultIds.has(id)) {
1013
+ issues.push(`duplicate tool result id: ${id}`);
1014
+ } else {
1015
+ resultIds.add(id);
1016
+ if (!callIds.has(id)) issues.push(`orphan tool result id: ${id}`);
1017
+ }
1018
+ }
1019
+ }
1020
+ for (const id of callIds) {
1021
+ if (!resultIds.has(id)) issues.push(`missing tool result id: ${id}`);
1022
+ }
1023
+ return issues;
1024
+ }
1025
+ function toOpenAiCompatibleMessages(messages, options) {
1026
+ return messages.map(
1027
+ (message) => preserveAgentStateFields(message, {
1028
+ role: message.role,
1029
+ content: message.content ?? ""
1030
+ }, options)
1031
+ );
1032
+ }
1033
+ function shouldStripReasoningContentForOutbound(provider, model) {
1034
+ const p = provider?.trim().toLowerCase();
1035
+ const m = model?.trim().toLowerCase();
1036
+ if (!p || !m) return false;
1037
+ if (p === "deepseek" || p === "nolo") {
1038
+ return m === "deepseek-flash" || m === "deepseek-v4-flash" || m === "deepseek-v4-flash-vision-exp" || m === "deepseek-v4-pro";
1039
+ }
1040
+ return false;
1041
+ }
1042
+ var REASONING_REPLAY_PLACEHOLDER = "(reasoning not captured for this turn)";
1043
+ function shouldReplayReasoningContentForOutbound(provider, model) {
1044
+ const p = provider?.trim().toLowerCase();
1045
+ const m = model?.trim().toLowerCase();
1046
+ if (!p || !m) return false;
1047
+ return (p === "opencode-go" || p === "opencode") && m.includes("deepseek");
1048
+ }
1049
+ function resolveReasoningReplayOptions(provider, model, stripReasoningContent) {
1050
+ if (stripReasoningContent) return {};
1051
+ return shouldReplayReasoningContentForOutbound(provider, model) ? { replayReasoningPlaceholder: REASONING_REPLAY_PLACEHOLDER } : {};
1052
+ }
1053
+
1054
+ // packages/agent-runtime/promptCacheKey.ts
1055
+ function collectStablePromptPrefix(messages, fallbackPrompt) {
1056
+ const systemTexts = [];
1057
+ if (fallbackPrompt?.trim()) systemTexts.push(fallbackPrompt.trim());
1058
+ for (const raw of messages) {
1059
+ if (!raw || typeof raw !== "object") continue;
1060
+ const message = raw;
1061
+ const role = String(message.role ?? "");
1062
+ if (role !== "system" && role !== "developer") continue;
1063
+ if (typeof message.content === "string") {
1064
+ const boundary = Number(message.stable_prefix_chars);
1065
+ const text = Number.isFinite(boundary) && boundary > 0 ? message.content.slice(0, boundary) : message.content;
1066
+ if (text.trim()) systemTexts.push(text.trim());
1067
+ }
1068
+ }
1069
+ return systemTexts.join("\n\n");
1070
+ }
1071
+ function stablePromptCacheKey(parts, namespace) {
1072
+ const value = JSON.stringify(parts);
1073
+ let hash = 2166136261;
1074
+ for (let index = 0; index < value.length; index += 1) {
1075
+ hash ^= value.charCodeAt(index);
1076
+ hash = Math.imul(hash, 16777619) >>> 0;
1077
+ }
1078
+ return `${namespace}-${hash.toString(16).padStart(8, "0")}`;
1079
+ }
1080
+
1081
+ // packages/integrations/openai/providerBodyCompatibility.ts
1082
+ var MOONSHOT_KIMI_K3_MODEL = "kimi-k3";
1083
+ var isKimiK3ProviderModel = (provider, model) => {
1084
+ const normalizedModel = asTrimmedLowercaseString(model);
1085
+ if (asTrimmedLowercaseString(provider) === "moonshot") {
1086
+ return normalizedModel === MOONSHOT_KIMI_K3_MODEL;
1087
+ }
1088
+ return isNoloHostedProvider(provider) && normalizedModel === PLATFORM_HOSTED_KIMI_K3_MODEL;
1089
+ };
1090
+ var isOllamaProviderOrEndpoint = (provider, endpoint) => {
1091
+ const p = asTrimmedLowercaseString(provider);
1092
+ if (p === "ollama" || p === "ollama-cloud") return true;
1093
+ return isOllamaEndpoint(endpoint);
1094
+ };
1095
+ var applyFunctionToolReasoningCompatibility = (body, model) => {
1096
+ const effectiveModel = model ?? body?.model;
1097
+ const isLuna = typeof effectiveModel === "string" && /(?:^|\/)gpt-6-luna(?:$|[-._].*)/i.test(asTrimmedLowercaseString(effectiveModel));
1098
+ if (isLuna && Array.isArray(body?.tools) && body.tools.some((tool) => tool?.type === "function")) {
1099
+ return {
1100
+ ...body,
1101
+ reasoning_effort: "none"
1102
+ };
1103
+ }
1104
+ return body;
1105
+ };
1106
+ var normalizeChatCompletionsBodyForProvider = ({
1107
+ body,
1108
+ provider,
1109
+ model,
1110
+ endpoint
1111
+ }) => {
1112
+ let nextBody = { ...body, model };
1113
+ const normalizedProvider = asTrimmedLowercaseString(provider);
1114
+ nextBody = applyFunctionToolReasoningCompatibility(nextBody, model);
1115
+ if (Array.isArray(nextBody.messages)) {
1116
+ const isGemini = normalizedProvider === "google" || normalizedProvider === "google-antigravity" || normalizedProvider.startsWith("google-") || normalizedProvider.includes("gemini") || asTrimmedLowercaseString(model).includes("gemini") || typeof endpoint === "string" && endpoint.includes("googleapis.com");
1117
+ if (!isGemini) {
1118
+ nextBody.messages = nextBody.messages.map((msg) => {
1119
+ if (msg?.role === "assistant" && Array.isArray(msg.tool_calls)) {
1120
+ return {
1121
+ ...msg,
1122
+ tool_calls: msg.tool_calls.map((tc) => {
1123
+ if (!tc || typeof tc !== "object") return tc;
1124
+ const { id, type = "function", function: fn } = tc;
1125
+ return { id, type, function: fn };
1126
+ })
1127
+ };
1128
+ }
1129
+ return msg;
1130
+ });
1131
+ }
1132
+ }
1133
+ if (normalizedProvider === "fireworks" && isFireworksKimiModel(model)) {
1134
+ delete nextBody.reasoning;
1135
+ delete nextBody.reasoning_effort;
1136
+ }
1137
+ if (isKimiK3ProviderModel(provider, model)) {
1138
+ delete nextBody.temperature;
1139
+ delete nextBody.top_p;
1140
+ delete nextBody.frequency_penalty;
1141
+ delete nextBody.presence_penalty;
1142
+ if (typeof nextBody.max_tokens === "number") {
1143
+ nextBody.max_completion_tokens = nextBody.max_tokens;
1144
+ delete nextBody.max_tokens;
1145
+ }
1146
+ }
1147
+ if (isOllamaProviderOrEndpoint(provider, endpoint)) {
1148
+ const existingNumCtx = nextBody.options?.num_ctx ?? nextBody.num_ctx;
1149
+ if (existingNumCtx === void 0) {
1150
+ const cw = getModelContextWindow(model);
1151
+ const safeNumCtx = typeof cw === "number" && cw > 0 ? cw === 256e3 ? 32768 : Math.min(cw, 131072) : 32768;
1152
+ nextBody.options = {
1153
+ ...nextBody.options,
1154
+ num_ctx: safeNumCtx
1155
+ };
1156
+ }
1157
+ }
1158
+ if (Array.isArray(nextBody.messages) && requiresBareImageUrl({ provider, model })) {
1159
+ nextBody.messages = toBareImageUrlMessages(nextBody.messages);
1160
+ }
1161
+ return nextBody;
1162
+ };
1163
+
1164
+ export {
1165
+ scanTruncation,
1166
+ classifyUnparsableToolArgs,
1167
+ markDowngradedToolTurnOrigin,
1168
+ transferDowngradedToolTurnOrigin,
1169
+ sanitizeForOutbound,
1170
+ hasParsableObjectArguments,
1171
+ repairTruncatedToolArguments,
1172
+ downgradeUnparsableToolCalls,
1173
+ getUsageRequestOptions,
1174
+ hasImageParts,
1175
+ requiresBareImageUrl,
1176
+ toBareImageUrlMessages,
1177
+ preserveAgentStateFields,
1178
+ findAgentStatePairingIssues,
1179
+ toOpenAiCompatibleMessages,
1180
+ shouldStripReasoningContentForOutbound,
1181
+ resolveReasoningReplayOptions,
1182
+ collectStablePromptPrefix,
1183
+ stablePromptCacheKey,
1184
+ toResponsesTools,
1185
+ convertMessagesToResponsesInput,
1186
+ extractTextFromResponseOutput,
1187
+ extractReasoningFromResponseOutput,
1188
+ extractImagePartsFromResponseOutput,
1189
+ extractToolCallsFromResponseOutput,
1190
+ applyFunctionToolReasoningCompatibility,
1191
+ normalizeChatCompletionsBodyForProvider
1192
+ };