@qwen-code/qwen-code 0.20.0 → 0.20.1-nightly.20260724.7d17c44a3

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 (388) hide show
  1. package/bundled/qc-helper/docs/configuration/settings.md +1 -1
  2. package/bundled/qc-helper/docs/features/auto-mode.md +19 -16
  3. package/bundled/qc-helper/docs/features/commands.md +54 -0
  4. package/bundled/qc-helper/docs/features/sub-agents.md +16 -7
  5. package/bundled/qc-helper/docs/integration-github-action.md +1 -1
  6. package/bundled/qc-helper/docs/qwen-serve.md +2 -1
  7. package/bundled/review/DESIGN.md +2 -2
  8. package/bundled/review/SKILL.md +7 -5
  9. package/chunks/MaxSizedBox-LGRTXB47.js +84 -0
  10. package/chunks/{StandaloneSessionPicker-CEGO2AZX.js → StandaloneSessionPicker-H3TBU3C3.js} +68 -56
  11. package/chunks/{acp-startup-profiler-N3RHHXJ3.js → acp-startup-profiler-RV3IV562.js} +2 -2
  12. package/chunks/{acpAgent-YUR43TLG.js → acpAgent-5D7P4BB5.js} +2061 -556
  13. package/chunks/agent-W7UAHCCI.js +80 -0
  14. package/chunks/agent-headless-KTBMPRSC.js +74 -0
  15. package/chunks/{anthropicContentGenerator-HVKLXOOU.js → anthropicContentGenerator-ZLQ3X2HI.js} +112 -45
  16. package/chunks/{artifact-tool-WBCAMD3O.js → artifact-tool-OKMWONT6.js} +3 -3
  17. package/chunks/{askUserQuestion-6DZC4UV5.js → askUserQuestion-V6FUS23G.js} +3 -3
  18. package/chunks/bridge-FFC4C6VD.js +89 -0
  19. package/chunks/{build-SSCNEHZZ.js → build-RV63TIRH.js} +2 -3
  20. package/chunks/{ca-2SL2BXTK.js → ca-GKRQZ7AM.js} +612 -201
  21. package/chunks/{channel-worker-group-53CMOPFT.js → channel-worker-group-MA3WXWYX.js} +7 -6
  22. package/chunks/{channel-worker-manager-UTXILKC2.js → channel-worker-manager-TIYYYBCT.js} +189 -29
  23. package/chunks/{channel-worker-supervisor-ZGO2W2MD.js → channel-worker-supervisor-CXRCDA4Y.js} +6 -5
  24. package/chunks/{chunk-TYQMGACW.js → chunk-22C7BQ6D.js} +508 -10967
  25. package/chunks/{chunk-4EP2PYYL.js → chunk-2G6QIHYL.js} +5 -5
  26. package/chunks/{chunk-H2XVO6NE.js → chunk-2MIN6GRR.js} +1 -1
  27. package/chunks/chunk-2RFKHEXL.js +74 -0
  28. package/chunks/{chunk-7SXZC7ID.js → chunk-2WTVWAKT.js} +7 -6
  29. package/chunks/{chunk-TIH2ZTOC.js → chunk-32A4PI3E.js} +2 -2
  30. package/chunks/chunk-36HSVBBU.js +469 -0
  31. package/chunks/{chunk-IR46U7RB.js → chunk-3FB2Y2OE.js} +3 -3
  32. package/chunks/{chunk-QR6U5QPP.js → chunk-3SJ43L4W.js} +4 -0
  33. package/chunks/chunk-3Z43GZUQ.js +32 -0
  34. package/chunks/chunk-43T5WDQ7.js +127 -0
  35. package/chunks/chunk-46UV252V.js +128 -0
  36. package/chunks/{chunk-JD3MKVKL.js → chunk-4K56OJFJ.js} +1 -1
  37. package/chunks/{chunk-KTUQMDEP.js → chunk-4K7VDKAD.js} +1 -1
  38. package/chunks/{chunk-QKYTTBYW.js → chunk-4LVZNIDO.js} +1 -1
  39. package/chunks/{chunk-OWCALFEG.js → chunk-54R2CV2G.js} +1 -1
  40. package/chunks/{chunk-ZEOZL37W.js → chunk-57FIIFJN.js} +1 -1
  41. package/chunks/chunk-5BS3KLRP.js +6194 -0
  42. package/chunks/{chunk-NEEB7UEN.js → chunk-6GMVPFB2.js} +153 -72
  43. package/chunks/{chunk-GMGDLUC7.js → chunk-6IL7KRLE.js} +1 -1
  44. package/chunks/chunk-6PVPNMXU.js +29 -0
  45. package/chunks/chunk-6QHAUJUE.js +293 -0
  46. package/chunks/chunk-6VK3IRTX.js +10017 -0
  47. package/chunks/{chunk-BDBMYST4.js → chunk-6X4GWOPW.js} +1 -1
  48. package/chunks/{chunk-AYCDXHZB.js → chunk-7Z6JQEL6.js} +1 -1
  49. package/chunks/{chunk-FSL5W5TI.js → chunk-AFFGGOF6.js} +4 -4
  50. package/chunks/chunk-AMDSOFFV.js +10860 -0
  51. package/chunks/chunk-AXUW635Q.js +934 -0
  52. package/chunks/{chunk-A5LYNIW7.js → chunk-BJBUDCM3.js} +8 -8
  53. package/chunks/chunk-BK2UNYWD.js +29 -0
  54. package/chunks/{chunk-6RLROE6G.js → chunk-BLFVGB7D.js} +30 -4
  55. package/chunks/chunk-BPJSQIJX.js +100 -0
  56. package/chunks/{chunk-FLSVD6BS.js → chunk-BRTR7S7O.js} +3 -3
  57. package/chunks/{chunk-KG3XV6FH.js → chunk-BSNWBC33.js} +32 -2
  58. package/chunks/chunk-BULDBTYC.js +153 -0
  59. package/chunks/{chunk-PBWEWI4N.js → chunk-BW5Z5NOG.js} +83 -74
  60. package/chunks/{chunk-EIAK6Q2B.js → chunk-C3VHAXP2.js} +20 -3
  61. package/chunks/{chunk-6AFUCL3D.js → chunk-CEZB3XFD.js} +1 -1
  62. package/chunks/chunk-CHMENNJV.js +1832 -0
  63. package/chunks/{chunk-TMQ6XQCX.js → chunk-CK3IEEHR.js} +416 -291
  64. package/chunks/{chunk-OYZWQNWG.js → chunk-CK6UABV2.js} +2 -2
  65. package/chunks/{chunk-VZQUV7VK.js → chunk-CKTMY3EP.js} +1 -1
  66. package/chunks/{chunk-VDWBQ5AW.js → chunk-CUPAVLRY.js} +5 -2
  67. package/chunks/{chunk-I2PYAYFM.js → chunk-CXUFILV3.js} +3 -3
  68. package/chunks/chunk-DP3IHZGG.js +1498 -0
  69. package/chunks/{chunk-BMWMT5Y2.js → chunk-DP5GT2MW.js} +7 -375
  70. package/chunks/{chunk-D22SX43D.js → chunk-DWNZ6PVQ.js} +1 -1
  71. package/chunks/{chunk-5SCI6E3E.js → chunk-E4IMU4Y5.js} +1 -1
  72. package/chunks/{chunk-DP5GXXNZ.js → chunk-EL2IQ2S5.js} +5 -1
  73. package/chunks/{chunk-EZVDJFZ7.js → chunk-ERLGR7GI.js} +1 -1
  74. package/chunks/{chunk-IVPSS6EL.js → chunk-F5MBYZSU.js} +4 -4
  75. package/chunks/{chunk-AQIEINAY.js → chunk-F6IYL66A.js} +28 -1766
  76. package/chunks/{chunk-FEOZBUMT.js → chunk-FODK6UMO.js} +0 -27
  77. package/chunks/{chunk-PGEPSDJI.js → chunk-FWNZ7CVN.js} +24 -20
  78. package/chunks/{chunk-5JBR5XIK.js → chunk-G7EFBBVF.js} +220 -141
  79. package/chunks/chunk-GLNBDYUX.js +38 -0
  80. package/chunks/{chunk-ANPINBOF.js → chunk-H4YKEV2X.js} +5 -5
  81. package/chunks/{chunk-TDKQP3M6.js → chunk-HIJQF5B5.js} +1 -1
  82. package/chunks/{chunk-FQD7GFSV.js → chunk-HJJDKFL5.js} +3 -3
  83. package/chunks/{chunk-4N3KMAIL.js → chunk-HPWHDJID.js} +152 -35
  84. package/chunks/{chunk-KQNM4EO7.js → chunk-HQCSRJ3P.js} +138 -6
  85. package/chunks/chunk-HTR4WV6U.js +327 -0
  86. package/chunks/{chunk-YWEW33JY.js → chunk-HVO55LUD.js} +7 -7
  87. package/chunks/{chunk-MJ6S23WZ.js → chunk-HZEWYOVI.js} +5 -5
  88. package/chunks/chunk-IFG6TYJ2.js +16577 -0
  89. package/chunks/{chunk-B3KGZCQN.js → chunk-IJTOWOD7.js} +322 -202
  90. package/chunks/{chunk-RS7MT2QG.js → chunk-IPUUTYMV.js} +2 -4
  91. package/chunks/{chunk-4ILMYHEI.js → chunk-IRDZJSCL.js} +3 -3
  92. package/chunks/{chunk-XU457J4V.js → chunk-IRH27ZC2.js} +2 -2
  93. package/chunks/{chunk-33XUAINQ.js → chunk-J5UKQEFG.js} +69 -9
  94. package/chunks/{chunk-G45X5TRN.js → chunk-JCW2R7WC.js} +1 -72
  95. package/chunks/{chunk-S2XVRHDN.js → chunk-JDFBBGRD.js} +1 -1
  96. package/chunks/{chunk-4XNLIGVA.js → chunk-JKCALGYN.js} +1023 -383
  97. package/chunks/{chunk-TJTKSVIV.js → chunk-JLU636DO.js} +5 -1
  98. package/chunks/{chunk-VEXFOTEO.js → chunk-JYUSL2V4.js} +3 -3
  99. package/chunks/{chunk-S2PD3EZD.js → chunk-KJEMJWNH.js} +1 -1
  100. package/chunks/{chunk-E2UVIFI2.js → chunk-KRXPRVGL.js} +0 -1
  101. package/chunks/{chunk-CZF3E5GF.js → chunk-LA5H3LM5.js} +1 -1
  102. package/chunks/{chunk-NDMQLV4Y.js → chunk-LBAO2XRA.js} +4 -4
  103. package/chunks/{chunk-7RMOXZTC.js → chunk-LDPP5VTZ.js} +4 -4
  104. package/chunks/{chunk-KDC6GNQR.js → chunk-LEEWLFHW.js} +4 -4
  105. package/chunks/{chunk-KX6UK4VJ.js → chunk-LI4I37W4.js} +22152 -18007
  106. package/chunks/{chunk-OOCI5VVU.js → chunk-LIZRAKPB.js} +1 -1
  107. package/chunks/{chunk-AJSJ5TTU.js → chunk-LP2E4MQG.js} +1 -1
  108. package/chunks/chunk-LS77BEZP.js +405 -0
  109. package/chunks/{chunk-BRRF37CO.js → chunk-LYTBLSSW.js} +5 -5
  110. package/chunks/{chunk-DBE4QFZS.js → chunk-MB7ENXPR.js} +39 -37
  111. package/chunks/{chunk-GKY2OJ7R.js → chunk-MOHAWVLH.js} +4 -4
  112. package/chunks/chunk-NABLFI57.js +82 -0
  113. package/chunks/chunk-NBQDBANR.js +411 -0
  114. package/chunks/{chunk-EAUYY7SS.js → chunk-NOAAFNTJ.js} +43 -10
  115. package/chunks/chunk-NXS53EA7.js +1462 -0
  116. package/chunks/{chunk-C27BYUX6.js → chunk-OQB4EXO4.js} +14 -11
  117. package/chunks/{chunk-NHDKSOEY.js → chunk-P3QQPMQA.js} +5 -5
  118. package/chunks/{chunk-OP4MOGXF.js → chunk-P5RRUHL7.js} +23 -1
  119. package/chunks/{chunk-KOR3XKCA.js → chunk-PBII2NFX.js} +12 -6
  120. package/chunks/{chunk-O3OCNYY5.js → chunk-PDYB7HG2.js} +2 -2
  121. package/chunks/{chunk-2HOVDT7W.js → chunk-PFSUKTZH.js} +1 -1
  122. package/chunks/chunk-PKL3HGNZ.js +2299 -0
  123. package/chunks/{chunk-5DTTYNB7.js → chunk-PQNHRFJC.js} +16 -3
  124. package/chunks/{chunk-OLMETXLX.js → chunk-PXHK5ONM.js} +41 -9
  125. package/chunks/{chunk-PF4CHQOJ.js → chunk-Q6GU6TKM.js} +11 -10
  126. package/chunks/{chunk-4ODB7WIB.js → chunk-QAFKR7WR.js} +1 -1
  127. package/chunks/{chunk-PBATSWUQ.js → chunk-QBUDF33N.js} +1 -1
  128. package/chunks/{chunk-BVLROR2T.js → chunk-QLJUC7TG.js} +1 -1
  129. package/chunks/{chunk-UEY4AYUL.js → chunk-QNLNLENL.js} +2 -2
  130. package/chunks/{chunk-333CXMNJ.js → chunk-QXZTZJLX.js} +5 -5
  131. package/chunks/chunk-R6D2CTQR.js +289 -0
  132. package/chunks/{chunk-7PZ2ATFZ.js → chunk-R6SKHK3T.js} +54 -29
  133. package/chunks/{chunk-OONJNQ42.js → chunk-RGG6M2WF.js} +4 -4
  134. package/chunks/{chunk-RFIAR4YL.js → chunk-RV4C2ZFG.js} +1 -1
  135. package/chunks/{chunk-O3Z73NBP.js → chunk-RW2NEXYJ.js} +15 -11
  136. package/chunks/{chunk-HZPN55E5.js → chunk-SJEDL7DI.js} +1 -1
  137. package/chunks/{chunk-AKX4WPPP.js → chunk-SWBJRDYC.js} +866 -183
  138. package/chunks/{chunk-NBMIC7DR.js → chunk-SX4PK3FC.js} +145 -5
  139. package/chunks/chunk-T3452DP5.js +246 -0
  140. package/chunks/{chunk-TB6UDU4T.js → chunk-THJNPLI4.js} +16 -16
  141. package/chunks/{chunk-T4TZQJ7W.js → chunk-TWPJO254.js} +5 -16
  142. package/chunks/chunk-U7ZFW55U.js +2098 -0
  143. package/chunks/{chunk-JNWZQ27S.js → chunk-UCOJC6EB.js} +72 -23
  144. package/chunks/{chunk-W7H223ZZ.js → chunk-UGYMA4EI.js} +1 -1
  145. package/chunks/{chunk-X6YQWCIJ.js → chunk-UH3WSE5L.js} +13 -1
  146. package/chunks/{chunk-2LL7TXB4.js → chunk-UH7242DI.js} +3 -3
  147. package/chunks/{chunk-CB2HFGRV.js → chunk-UJV643E2.js} +31 -6
  148. package/chunks/chunk-UO7DCGEV.js +121 -0
  149. package/chunks/{chunk-Y2ENGUD6.js → chunk-UPF7PTBI.js} +79 -2
  150. package/chunks/chunk-UW5EOVUN.js +249 -0
  151. package/chunks/{chunk-SJMV7ZBK.js → chunk-VLVO52KC.js} +8 -8
  152. package/chunks/{chunk-R3VWUU2E.js → chunk-VYPFXUCB.js} +1 -1
  153. package/chunks/{chunk-S2W2LVDU.js → chunk-WHFK6G6U.js} +8 -9
  154. package/chunks/chunk-WI3KCKZ5.js +391 -0
  155. package/chunks/{chunk-NGFEPAE6.js → chunk-WLEFWSSC.js} +8 -6
  156. package/chunks/{chunk-XVVH63JG.js → chunk-WUJXJ34P.js} +3 -3
  157. package/chunks/{chunk-MAQQGNQ5.js → chunk-WYLPWQHJ.js} +56 -717
  158. package/chunks/{chunk-D2VIDMVM.js → chunk-X6N25LXS.js} +2 -2
  159. package/chunks/chunk-XAWJ2526.js +1049 -0
  160. package/chunks/{chunk-CV63PP6U.js → chunk-YCIM6O3I.js} +1 -1
  161. package/chunks/{chunk-OEO2ERWK.js → chunk-Z44CVEUF.js} +54 -33
  162. package/chunks/{chunk-TKLLK6XQ.js → chunk-ZT4POVWC.js} +11 -11
  163. package/chunks/{chunk-NIJEXGV6.js → chunk-ZXYUQXY5.js} +148 -10
  164. package/chunks/{computer-use-NIWQNUZF.js → computer-use-UJ5T34TE.js} +50 -37
  165. package/chunks/{config-utils-AHQ6YZ66.js → config-utils-XQRXHAN3.js} +3 -3
  166. package/chunks/contextCommand-CSCB4E5M.js +79 -0
  167. package/chunks/{create-sub-session-MGNX52P3.js → create-sub-session-55F3GOLK.js} +46 -33
  168. package/chunks/{create-sub-session-P26FE5GG.js → create-sub-session-JPCSYZAJ.js} +3 -3
  169. package/chunks/{cron-create-JWFHBDRQ.js → cron-create-CUMELMPL.js} +6 -6
  170. package/chunks/{cron-delete-GDX4E26G.js → cron-delete-QZFV6U3P.js} +5 -5
  171. package/chunks/{cron-list-USMAIWPT.js → cron-list-IDKO7ZO2.js} +5 -5
  172. package/chunks/{daemon-RG2MAI6T.js → daemon-7LP7R6IU.js} +500 -133
  173. package/chunks/daemon-status-provider-6YNZ3UAE.js +88 -0
  174. package/chunks/{de-I7ZIYXZC.js → de-4IBXM7CN.js} +5 -1
  175. package/chunks/{dist-WGTQO7F2.js → dist-376652EZ.js} +114 -28
  176. package/chunks/{dist-53PZYC5B.js → dist-3YCTE6HD.js} +2 -2
  177. package/chunks/{dist-2BHAYBKP.js → dist-D7Z3HOO7.js} +14 -2
  178. package/chunks/{dist-FUTEXY6A.js → dist-MEGJFGAI.js} +40 -9
  179. package/chunks/{dist-2MIU4UUH.js → dist-NQ436QEX.js} +1 -1
  180. package/chunks/{dist-AU7NQQRP.js → dist-NQNTOIEN.js} +26 -2
  181. package/chunks/earlyInputCapture-HPUVJ2KH.js +81 -0
  182. package/chunks/{edit-3QV3JZJL.js → edit-7CMAN3F4.js} +50 -39
  183. package/chunks/{en-XE34GKAA.js → en-SALLIJS7.js} +6 -1
  184. package/chunks/{enter-worktree-4GMMF7EG.js → enter-worktree-3PH4YTY2.js} +49 -36
  185. package/chunks/{enterPlanMode-L5UWBAUC.js → enterPlanMode-MSXLSWLI.js} +55 -37
  186. package/chunks/{environment-3OV7UQOT.js → environment-KS36ZHBE.js} +48 -35
  187. package/chunks/errors-LCPFS62A.js +87 -0
  188. package/chunks/{exit-worktree-DDP57JLV.js → exit-worktree-ARA4C3CK.js} +49 -36
  189. package/chunks/{exitPlanMode-CJBLGPIP.js → exitPlanMode-GCDIQPB7.js} +49 -36
  190. package/chunks/{fast-path-M6RP2ING.js → fast-path-IDHBVIT6.js} +3 -2
  191. package/chunks/{fr-X7KDVZIY.js → fr-WVHEBDDB.js} +5 -1
  192. package/chunks/{gemini-H4PHBJTL.js → gemini-2AFQJMX5.js} +141 -105
  193. package/chunks/{geminiContentGenerator-VURJYPWP.js → geminiContentGenerator-UDIH3YI6.js} +9 -8
  194. package/chunks/{getMachineId-bsd-EXV7SWPA.js → getMachineId-bsd-QFVLPUPT.js} +1 -1
  195. package/chunks/{getMachineId-darwin-IUOMFXU3.js → getMachineId-darwin-DGMQQE2E.js} +1 -1
  196. package/chunks/{getMachineId-linux-K7XJYFHL.js → getMachineId-linux-R4Z6CSWC.js} +1 -1
  197. package/chunks/{getMachineId-unsupported-EA5FDRJ6.js → getMachineId-unsupported-Z3SBVBUV.js} +1 -1
  198. package/chunks/{getMachineId-win-KBA6RAI5.js → getMachineId-win-SCK5UFDT.js} +1 -1
  199. package/chunks/{glob-2KUSRAVQ.js → glob-HCL7HZ67.js} +49 -36
  200. package/chunks/{grep-B5RXVESV.js → grep-CJLBSCTV.js} +49 -36
  201. package/chunks/handleAutoUpdate-Q572P3FL.js +80 -0
  202. package/chunks/i18n-OBB4R7SR.js +96 -0
  203. package/chunks/initializer-LXEY6V3C.js +85 -0
  204. package/chunks/installationInfo-XUAOVMEE.js +79 -0
  205. package/chunks/{ja-2ICT3KXF.js → ja-KY4ROZTE.js} +5 -1
  206. package/chunks/{keychain-token-storage-DWRJMNH3.js → keychain-token-storage-6ACJDYIB.js} +3 -3
  207. package/chunks/{kittyProtocolDetector-HCNNKJTI.js → kittyProtocolDetector-MBRTDRBK.js} +5 -3
  208. package/chunks/list-WAXY7QOU.js +88 -0
  209. package/chunks/list-agents-AH3P5NB7.js +80 -0
  210. package/chunks/loadedSettingsAdapter-OZFNBRHE.js +82 -0
  211. package/chunks/loggingContentGenerator-7WDTTE6G.js +1068 -0
  212. package/chunks/{loop-wakeup-5GLTUBHA.js → loop-wakeup-IHRW6TNB.js} +7 -7
  213. package/chunks/{ls-FHBY3Y7I.js → ls-ZAXZ2G2W.js} +5 -5
  214. package/chunks/{lsp-B6VMEW6Y.js → lsp-R4ZG3UGQ.js} +3 -3
  215. package/chunks/managed-npm-update-N42DO5QW.js +339 -0
  216. package/chunks/mcp-6SOORKTY.js +82 -0
  217. package/chunks/{monitor-GLJZDNPS.js → monitor-4PSVNVU4.js} +51 -37
  218. package/chunks/node-UUDY34IG.js +305 -0
  219. package/chunks/nonInteractiveCli-FBR5S7IZ.js +140 -0
  220. package/chunks/{notebook-edit-AVCIWS4F.js → notebook-edit-QK26632S.js} +50 -39
  221. package/chunks/{openaiContentGenerator-B7W24G3D.js → openaiContentGenerator-IXJS6C2U.js} +33 -20
  222. package/chunks/pidfile-UCFCJOAP.js +85 -0
  223. package/chunks/{processUtils-XZPY2PBB.js → processUtils-YL2LXON2.js} +2 -2
  224. package/chunks/{pt-JJ4XPIBP.js → pt-OK455PLH.js} +5 -1
  225. package/chunks/{qwenContentGenerator-6GUTWJIC.js → qwenContentGenerator-H6WZPJKC.js} +56 -36
  226. package/chunks/{qwenOAuth2-GASEEWGU.js → qwenOAuth2-HTROHKXO.js} +10 -23
  227. package/chunks/read-file-FOYTMUNL.js +31 -0
  228. package/chunks/{read-mcp-resource-AKCL7I43.js → read-mcp-resource-65BWNF3F.js} +3 -3
  229. package/chunks/{record-artifact-PEUB7727.js → record-artifact-2RLSOP6U.js} +3 -3
  230. package/chunks/resumeHistoryUtils-ZNHTWBXS.js +90 -0
  231. package/chunks/ripGrep-K4K4QLNJ.js +72 -0
  232. package/chunks/{ru-STR4KTW7.js → ru-7SPDGMGD.js} +5 -1
  233. package/chunks/{run-qwen-serve-OZGR3FQA.js → run-qwen-serve-XI4MCAFV.js} +343 -88
  234. package/chunks/runtime-4CTBU5WX.js +115 -0
  235. package/chunks/{scheduler-Z7QLMUWA.js → scheduler-TTEITHBF.js} +46 -33
  236. package/chunks/sdk-exporters-grpc-N3OLDF63.js +23214 -0
  237. package/chunks/sdk-exporters-http-AOHAEOMC.js +563 -0
  238. package/chunks/sdk-impl-TLQOC7P4.js +9193 -0
  239. package/chunks/{send-message-3RHE7HSM.js → send-message-GEY4CNPS.js} +47 -8
  240. package/chunks/serve-W7UKJTQT.js +88 -0
  241. package/chunks/{server-SO64U3X5.js → server-JD5PIE7A.js} +3069 -517
  242. package/chunks/{session-2KL2WQAH.js → session-R4BDHLYR.js} +112 -177
  243. package/chunks/{settings-KITVOUSV.js → settings-BXZHA6TZ.js} +50 -37
  244. package/chunks/shell-XYMFCGN5.js +82 -0
  245. package/chunks/{skill-SOQHY455.js → skill-YKXYEPOF.js} +25 -20
  246. package/chunks/spawnChannel-IO4HQLFS.js +81 -0
  247. package/chunks/{src-43LM7JLB.js → src-LKKTJ4NG.js} +382 -235
  248. package/chunks/standalone-update-76JG7DVN.js +91 -0
  249. package/chunks/{startInteractiveUI-3RGTGEX5.js → startInteractiveUI-BXWQUXAS.js} +1314 -958
  250. package/chunks/{syntheticOutput-FG5PQKIR.js → syntheticOutput-2WNMXEU5.js} +4 -4
  251. package/chunks/task-create-R5H74Y76.js +25 -0
  252. package/chunks/{task-list-QWSY4ZIU.js → task-list-WXAFDSRY.js} +7 -7
  253. package/chunks/{task-stop-GWC6UWAL.js → task-stop-CHFZP23W.js} +4 -4
  254. package/chunks/{task-update-NCTAB73Q.js → task-update-Z44A4GAR.js} +11 -9
  255. package/chunks/{team-create-FXN3PEBP.js → team-create-5Y3MCAIM.js} +49 -36
  256. package/chunks/{team-delete-KK37HTOG.js → team-delete-YDCMRSI4.js} +7 -7
  257. package/chunks/{team-plan-approval-GEIZ356Q.js → team-plan-approval-HYJJZ76T.js} +49 -36
  258. package/chunks/theme-manager-3YF2SUZL.js +76 -0
  259. package/chunks/{todoWrite-ERCAMLFS.js → todoWrite-ED2IVZJL.js} +5 -5
  260. package/chunks/{tool-search-XKK7DNOK.js → tool-search-3ZO2XMEP.js} +21 -17
  261. package/chunks/total-session-admission-NDF7EVG7.js +83 -0
  262. package/chunks/trustedFolders-Q7RALK4T.js +92 -0
  263. package/chunks/{chunk-6EFTQYW7.js → undici-3FJYTMOF.js} +24 -399
  264. package/chunks/{chunk-L573Z2QZ.js → undici-PYHBDDPN.js} +1 -5
  265. package/chunks/{update-relaunch-FMVZK6XF.js → update-relaunch-BTW5XGVT.js} +17 -17
  266. package/chunks/updateCheck-MXIU6DWQ.js +91 -0
  267. package/chunks/useAutoAcceptIndicator-BJXHJW77.js +92 -0
  268. package/chunks/{validateNonInterActiveAuth-PRVEB6GG.js → validateNonInterActiveAuth-FLEPF3QQ.js} +90 -76
  269. package/chunks/{version-AZMG6KWL.js → version-75VRONIL.js} +1 -1
  270. package/chunks/{web-fetch-EPGJ5OQQ.js → web-fetch-5X27LYHB.js} +101 -41
  271. package/chunks/web-search-IDMTBJUP.js +718 -0
  272. package/chunks/{workflow-UTNVPW22.js → workflow-JOD2OPFQ.js} +54 -40
  273. package/chunks/workspace-providers-status-WDLBDLPG.js +85 -0
  274. package/chunks/{workspace-registration-store-F3ZX3YHT.js → workspace-registration-store-26Z6J6P5.js} +9 -3
  275. package/chunks/workspace-registry-IABDATX3.js +87 -0
  276. package/chunks/workspace-service-BI4KDYPD.js +97 -0
  277. package/chunks/workspace-skills-status-OVB4LPHA.js +84 -0
  278. package/chunks/write-file-276AJ7KE.js +72 -0
  279. package/chunks/{zh-6ANG2HTL.js → zh-Q54GA5SV.js} +6 -1
  280. package/chunks/{zh-TW-4RR3YHNN.js → zh-TW-VOBNFOPU.js} +6 -1
  281. package/cli-entry.js +164 -12
  282. package/cli.js +19 -12
  283. package/locales/ca.js +773 -203
  284. package/locales/de.js +8 -2
  285. package/locales/en.js +9 -2
  286. package/locales/fr.js +8 -2
  287. package/locales/ja.js +8 -2
  288. package/locales/pt.js +8 -2
  289. package/locales/ru.js +8 -2
  290. package/locales/zh-TW.js +9 -2
  291. package/locales/zh.js +9 -2
  292. package/package.json +3 -3
  293. package/web-shell/assets/{arc-Buk1besA.js → arc-CMb7lr2P.js} +1 -1
  294. package/web-shell/assets/{architectureDiagram-3BPJPVTR-B1aUKYDC.js → architectureDiagram-3BPJPVTR-D6KQ5Kwm.js} +1 -1
  295. package/web-shell/assets/{blockDiagram-GPEHLZMM-CRTdg3Zx.js → blockDiagram-GPEHLZMM-Ce7YYSf8.js} +1 -1
  296. package/web-shell/assets/{c4Diagram-AAUBKEIU-DFdRMp5g.js → c4Diagram-AAUBKEIU-DaStHfor.js} +1 -1
  297. package/web-shell/assets/channel-Dg4f-Kry.js +1 -0
  298. package/web-shell/assets/{chunk-2J33WTMH-4rYQdkEI.js → chunk-2J33WTMH-CPaqadg9.js} +1 -1
  299. package/web-shell/assets/{chunk-4BX2VUAB-Coi-pQJy.js → chunk-4BX2VUAB-Veh9ZGKg.js} +1 -1
  300. package/web-shell/assets/{chunk-55IACEB6-BtBjz02t.js → chunk-55IACEB6-BPTX5n4q.js} +1 -1
  301. package/web-shell/assets/{chunk-727SXJPM-CGYOWorl.js → chunk-727SXJPM-CtXsE_ca.js} +1 -1
  302. package/web-shell/assets/{chunk-AQP2D5EJ-CH5AKhqx.js → chunk-AQP2D5EJ-D8DDCJ8h.js} +1 -1
  303. package/web-shell/assets/{chunk-FMBD7UC4-Cd50-w85.js → chunk-FMBD7UC4-cjMDGzHz.js} +1 -1
  304. package/web-shell/assets/{chunk-ND2GUHAM-C2wF3KCK.js → chunk-ND2GUHAM-BaZ1hNhV.js} +1 -1
  305. package/web-shell/assets/{chunk-QZHKN3VN-pCeRTaWi.js → chunk-QZHKN3VN-C7w-9w5-.js} +1 -1
  306. package/web-shell/assets/classDiagram-4FO5ZUOK-CT7Fo2aW.js +1 -0
  307. package/web-shell/assets/classDiagram-v2-Q7XG4LA2-CT7Fo2aW.js +1 -0
  308. package/web-shell/assets/{cose-bilkent-S5V4N54A-B-_fAB6D.js → cose-bilkent-S5V4N54A-DqvBEEIe.js} +1 -1
  309. package/web-shell/assets/{dagre-BM42HDAG-ChSPNHpL.js → dagre-BM42HDAG-RkPyoMAk.js} +1 -1
  310. package/web-shell/assets/{diagram-2AECGRRQ-BX7cFOF3.js → diagram-2AECGRRQ-D9b6nNyg.js} +1 -1
  311. package/web-shell/assets/{diagram-5GNKFQAL-BQUTW92n.js → diagram-5GNKFQAL-CiiNKUIy.js} +1 -1
  312. package/web-shell/assets/{diagram-KO2AKTUF-BkYPh3e4.js → diagram-KO2AKTUF-CP1qizXd.js} +1 -1
  313. package/web-shell/assets/{diagram-LMA3HP47-Cl6jsNyx.js → diagram-LMA3HP47-BGe30TWx.js} +1 -1
  314. package/web-shell/assets/{diagram-OG6HWLK6-DRWoHz8n.js → diagram-OG6HWLK6-CvoEPARH.js} +1 -1
  315. package/web-shell/assets/{erDiagram-TEJ5UH35-CGvFcZco.js → erDiagram-TEJ5UH35-DWfLzVkV.js} +1 -1
  316. package/web-shell/assets/{flowDiagram-I6XJVG4X-vms6oVdv.js → flowDiagram-I6XJVG4X-D-dTQmo6.js} +1 -1
  317. package/web-shell/assets/{ganttDiagram-6RSMTGT7-ukT_sfmi.js → ganttDiagram-6RSMTGT7-CYPHKaGY.js} +1 -1
  318. package/web-shell/assets/{gitGraphDiagram-PVQCEYII-Bn2ZE2Ut.js → gitGraphDiagram-PVQCEYII-DA7_aQYD.js} +1 -1
  319. package/web-shell/assets/index-B0i-TOYM.css +5 -0
  320. package/web-shell/assets/index-CgCHD46L.js +1225 -0
  321. package/web-shell/assets/{index-wFXp7W68.js → index-DqHNAB8C.js} +1 -1
  322. package/web-shell/assets/{infoDiagram-5YYISTIA-DHJdSi7x.js → infoDiagram-5YYISTIA-B87ljDPa.js} +1 -1
  323. package/web-shell/assets/{ishikawaDiagram-YF4QCWOH-DOvd2Wph.js → ishikawaDiagram-YF4QCWOH-CYSpyjaN.js} +1 -1
  324. package/web-shell/assets/{journeyDiagram-JHISSGLW-CH_urMCT.js → journeyDiagram-JHISSGLW-DAL6Js6f.js} +1 -1
  325. package/web-shell/assets/{kanban-definition-UN3LZRKU-FKiBdgbH.js → kanban-definition-UN3LZRKU-_zufKGJv.js} +1 -1
  326. package/web-shell/assets/{linear-0ZVQFVKf.js → linear-DidhMgku.js} +1 -1
  327. package/web-shell/assets/{mermaid.core-DJ05ZZIK.js → mermaid.core-DAkX3h3a.js} +5 -5
  328. package/web-shell/assets/{mindmap-definition-RKZ34NQL-BPuUhkUm.js → mindmap-definition-RKZ34NQL-DbZxUBEH.js} +1 -1
  329. package/web-shell/assets/{pieDiagram-4H26LBE5-yLFKcXyG.js → pieDiagram-4H26LBE5-Du9uoqrf.js} +1 -1
  330. package/web-shell/assets/{quadrantDiagram-W4KKPZXB-irWqc1pE.js → quadrantDiagram-W4KKPZXB-DwjELuKm.js} +1 -1
  331. package/web-shell/assets/{requirementDiagram-4Y6WPE33-B_4uMoIV.js → requirementDiagram-4Y6WPE33-BAqfVtBL.js} +1 -1
  332. package/web-shell/assets/{sankeyDiagram-5OEKKPKP-ciA4GPwk.js → sankeyDiagram-5OEKKPKP--hm2VpmK.js} +1 -1
  333. package/web-shell/assets/{sequenceDiagram-3UESZ5HK-CRdZvy0U.js → sequenceDiagram-3UESZ5HK-R5MUQaIt.js} +1 -1
  334. package/web-shell/assets/{stateDiagram-AJRCARHV-DaYIkCCn.js → stateDiagram-AJRCARHV-VsX032xQ.js} +1 -1
  335. package/web-shell/assets/stateDiagram-v2-BHNVJYJU-uPWLcSfy.js +1 -0
  336. package/web-shell/assets/{timeline-definition-PNZ67QCA-oBUKv6iH.js → timeline-definition-PNZ67QCA-BqjVRXzg.js} +1 -1
  337. package/web-shell/assets/{vennDiagram-CIIHVFJN-CGW9Sdmb.js → vennDiagram-CIIHVFJN-i2tkvlkg.js} +1 -1
  338. package/web-shell/assets/{wardley-L42UT6IY-CvwKJOCm.js → wardley-L42UT6IY-Ch8G49EM.js} +1 -1
  339. package/web-shell/assets/{wardleyDiagram-YWT4CUSO-Ipc260sN.js → wardleyDiagram-YWT4CUSO-bYpWeQNy.js} +1 -1
  340. package/web-shell/assets/{xychartDiagram-2RQKCTM6-D6-CM7pK.js → xychartDiagram-2RQKCTM6-C9NhuBqB.js} +1 -1
  341. package/web-shell/index.html +17 -13
  342. package/chunks/MaxSizedBox-B5YGZSYE.js +0 -72
  343. package/chunks/agent-H4JIDL7S.js +0 -67
  344. package/chunks/agent-headless-TTBEREQV.js +0 -61
  345. package/chunks/bridge-VL7ITBU5.js +0 -75
  346. package/chunks/chunk-542SK7KV.js +0 -8293
  347. package/chunks/chunk-CPCVCKKF.js +0 -358
  348. package/chunks/chunk-SEKHYHMS.js +0 -45
  349. package/chunks/chunk-W7FJ3N32.js +0 -49
  350. package/chunks/chunk-ZFKNWQGQ.js +0 -74639
  351. package/chunks/contextCommand-L2COEUHS.js +0 -66
  352. package/chunks/daemon-status-provider-NL4IAG7B.js +0 -74
  353. package/chunks/earlyInputCapture-L6I2A22T.js +0 -68
  354. package/chunks/errors-LEOF5QG4.js +0 -74
  355. package/chunks/handleAutoUpdate-QQVIWXKT.js +0 -67
  356. package/chunks/i18n-N6OBDORT.js +0 -83
  357. package/chunks/initializer-6WCFNDLL.js +0 -72
  358. package/chunks/installationInfo-6J3WPXNS.js +0 -64
  359. package/chunks/list-HOWQSWP6.js +0 -75
  360. package/chunks/loadedSettingsAdapter-AO4YBRXZ.js +0 -69
  361. package/chunks/mcp-QH7QNXOH.js +0 -69
  362. package/chunks/nonInteractiveCli-TI7EMPXD.js +0 -126
  363. package/chunks/pidfile-UEHAT6DH.js +0 -72
  364. package/chunks/read-file-SQJONF6A.js +0 -29
  365. package/chunks/resumeHistoryUtils-PFQ2A23X.js +0 -78
  366. package/chunks/ripGrep-QCK22GDU.js +0 -59
  367. package/chunks/runtime-SNVAP6EH.js +0 -100
  368. package/chunks/serve-BT7KS6SC.js +0 -75
  369. package/chunks/shell-BITUVH2R.js +0 -69
  370. package/chunks/spawnChannel-2BU3AULL.js +0 -68
  371. package/chunks/standalone-update-YG5JUYCM.js +0 -78
  372. package/chunks/task-create-HX32YXO7.js +0 -23
  373. package/chunks/theme-manager-IAETOI25.js +0 -63
  374. package/chunks/total-session-admission-BJLDHKJN.js +0 -69
  375. package/chunks/trustedFolders-5XCVNEUU.js +0 -79
  376. package/chunks/updateCheck-YZZB7YBU.js +0 -70
  377. package/chunks/useAutoAcceptIndicator-ZSQX4I2H.js +0 -80
  378. package/chunks/workspace-providers-status-EADV364W.js +0 -72
  379. package/chunks/workspace-registry-W6VMFYZU.js +0 -73
  380. package/chunks/workspace-service-F3KIN2UN.js +0 -84
  381. package/chunks/workspace-skills-status-YVICUR5Y.js +0 -71
  382. package/chunks/write-file-CVGF2OKV.js +0 -596
  383. package/web-shell/assets/channel-04R0vLbG.js +0 -1
  384. package/web-shell/assets/classDiagram-4FO5ZUOK-Bw9SOwAV.js +0 -1
  385. package/web-shell/assets/classDiagram-v2-Q7XG4LA2-Bw9SOwAV.js +0 -1
  386. package/web-shell/assets/index-DgkKrjw3.js +0 -1187
  387. package/web-shell/assets/index-Rv6mOAN9.css +0 -5
  388. package/web-shell/assets/stateDiagram-v2-BHNVJYJU-DWBoO4UY.js +0 -1
@@ -0,0 +1,1832 @@
1
+ // Force strict mode and setup for ESM
2
+ "use strict";
3
+ import {
4
+ DashScopeOpenAICompatibleProvider,
5
+ DefaultOpenAICompatibleProvider
6
+ } from "./chunk-F6IYL66A.js";
7
+ import {
8
+ RequestTokenizer
9
+ } from "./chunk-BRTR7S7O.js";
10
+ import {
11
+ DEFAULT_STREAM_IDLE_TIMEOUT_MS,
12
+ MAX_STREAM_IDLE_TIMEOUT_MS,
13
+ QWEN_STREAM_IDLE_TIMEOUT_MS_ENV
14
+ } from "./chunk-GLNBDYUX.js";
15
+ import {
16
+ createChildAbortController
17
+ } from "./chunk-DJ2GSRLV.js";
18
+ import {
19
+ OpenAIContentConverter,
20
+ TaggedThinkingParser,
21
+ openaiRequestCaptureContext
22
+ } from "./chunk-NXS53EA7.js";
23
+ import {
24
+ InvalidStreamError
25
+ } from "./chunk-BPJSQIJX.js";
26
+ import {
27
+ getRateLimitErrorDetails
28
+ } from "./chunk-6QHAUJUE.js";
29
+ import {
30
+ safeJsonParse
31
+ } from "./chunk-WYLPWQHJ.js";
32
+ import {
33
+ getToolCallPreparations,
34
+ runtimeDiagnostics
35
+ } from "./chunk-LS77BEZP.js";
36
+ import {
37
+ ProtocolTagSanitizedEvent,
38
+ logProtocolTagSanitized
39
+ } from "./chunk-IFG6TYJ2.js";
40
+ import {
41
+ reconcileMaxTokens
42
+ } from "./chunk-UW5EOVUN.js";
43
+ import {
44
+ redactProxyError
45
+ } from "./chunk-NBQDBANR.js";
46
+ import {
47
+ createDebugLogger,
48
+ getErrorMessage,
49
+ getErrorStatus,
50
+ getErrorType,
51
+ isAbortError
52
+ } from "./chunk-OQB4EXO4.js";
53
+ import {
54
+ GenerateContentResponse
55
+ } from "./chunk-22C7BQ6D.js";
56
+ import {
57
+ init_esbuild_shims
58
+ } from "./chunk-5O2XNYP6.js";
59
+ import {
60
+ __name
61
+ } from "./chunk-J2S4EL5Y.js";
62
+
63
+ // packages/core/src/core/openaiContentGenerator/index.ts
64
+ init_esbuild_shims();
65
+
66
+ // packages/core/src/core/openaiContentGenerator/openaiContentGenerator.ts
67
+ init_esbuild_shims();
68
+
69
+ // packages/core/src/core/openaiContentGenerator/provider/index.ts
70
+ init_esbuild_shims();
71
+
72
+ // packages/core/src/core/openaiContentGenerator/provider/modelscope.ts
73
+ init_esbuild_shims();
74
+ var ModelScopeOpenAICompatibleProvider = class extends DefaultOpenAICompatibleProvider {
75
+ static {
76
+ __name(this, "ModelScopeOpenAICompatibleProvider");
77
+ }
78
+ /**
79
+ * Checks if the configuration is for ModelScope.
80
+ */
81
+ static isModelScopeProvider(config) {
82
+ const baseUrl = config.baseUrl ?? "";
83
+ if (!baseUrl) return false;
84
+ try {
85
+ const hostname = new URL(baseUrl).hostname.toLowerCase();
86
+ return hostname === "modelscope.cn" || hostname.endsWith(".modelscope.cn");
87
+ } catch {
88
+ return false;
89
+ }
90
+ }
91
+ /**
92
+ * ModelScope does not support `stream_options` when `stream` is false.
93
+ * This method removes `stream_options` if `stream` is not true.
94
+ */
95
+ buildRequest(request, userPromptId) {
96
+ const newRequest = super.buildRequest(request, userPromptId);
97
+ if (!newRequest.stream) {
98
+ delete newRequest.stream_options;
99
+ }
100
+ return newRequest;
101
+ }
102
+ };
103
+
104
+ // packages/core/src/core/openaiContentGenerator/provider/deepseek.ts
105
+ init_esbuild_shims();
106
+
107
+ // packages/core/src/core/openaiContentGenerator/provider/utils.ts
108
+ init_esbuild_shims();
109
+ function ensureReasoningContentOnAssistantMessage(message) {
110
+ if (message.role !== "assistant") {
111
+ return message;
112
+ }
113
+ const assistant = message;
114
+ if (typeof assistant.reasoning_content === "string") {
115
+ return message;
116
+ }
117
+ return {
118
+ ...assistant,
119
+ reasoning_content: ""
120
+ };
121
+ }
122
+ __name(ensureReasoningContentOnAssistantMessage, "ensureReasoningContentOnAssistantMessage");
123
+
124
+ // packages/core/src/core/openaiContentGenerator/provider/deepseek.ts
125
+ function isDeepSeekHostname(contentGeneratorConfig) {
126
+ const baseUrl = contentGeneratorConfig.baseUrl ?? "";
127
+ if (!baseUrl) return false;
128
+ try {
129
+ const hostname = new URL(baseUrl).hostname.toLowerCase();
130
+ return hostname === "api.deepseek.com" || hostname.endsWith(".api.deepseek.com");
131
+ } catch {
132
+ return false;
133
+ }
134
+ }
135
+ __name(isDeepSeekHostname, "isDeepSeekHostname");
136
+ function isDeepSeekProvider(contentGeneratorConfig) {
137
+ if (isDeepSeekHostname(contentGeneratorConfig)) return true;
138
+ const model = contentGeneratorConfig.model ?? "";
139
+ return model.toLowerCase().includes("deepseek");
140
+ }
141
+ __name(isDeepSeekProvider, "isDeepSeekProvider");
142
+ var DeepSeekOpenAICompatibleProvider = class extends DefaultOpenAICompatibleProvider {
143
+ static {
144
+ __name(this, "DeepSeekOpenAICompatibleProvider");
145
+ }
146
+ constructor(contentGeneratorConfig, cliConfig) {
147
+ super(contentGeneratorConfig, cliConfig);
148
+ }
149
+ /**
150
+ * Backward-compatible static delegates for the free `isDeepSeek*`
151
+ * helpers. New call sites should import the free functions directly to
152
+ * avoid coupling to this class.
153
+ */
154
+ static isDeepSeekProvider = isDeepSeekProvider;
155
+ static isDeepSeekHostname = isDeepSeekHostname;
156
+ /**
157
+ * DeepSeek's API requires message content to be a plain string, not an
158
+ * array of content parts. Flatten any text-part arrays into joined
159
+ * strings; non-text parts (image_url, audio, …) are replaced with a
160
+ * `[Unsupported content type: <type>]` placeholder so the request still
161
+ * goes through with a textual breadcrumb rather than silently dropping
162
+ * the part or raising mid-conversation. Also translate the standard
163
+ * `reasoning.effort` config into DeepSeek's flat `reasoning_effort`
164
+ * body parameter — but only on actual DeepSeek hostnames, since the
165
+ * model-name fallback above can match self-hosted/strict OpenAI-compat
166
+ * backends that don't accept the DeepSeek extension.
167
+ */
168
+ buildRequest(request, userPromptId) {
169
+ const baseRequest = super.buildRequest(request, userPromptId);
170
+ const reshaped = isDeepSeekHostname(this.contentGeneratorConfig) ? translateReasoningEffort(baseRequest) : baseRequest;
171
+ if (!reshaped.messages?.length) {
172
+ return reshaped;
173
+ }
174
+ const messages = reshaped.messages.map((message) => {
175
+ const flattened = flattenContentParts(message);
176
+ return ensureReasoningContentOnAssistantMessage(flattened);
177
+ });
178
+ return {
179
+ ...reshaped,
180
+ messages
181
+ };
182
+ }
183
+ getDefaultGenerationConfig() {
184
+ return {
185
+ temperature: 0
186
+ };
187
+ }
188
+ };
189
+ function flattenContentParts(message) {
190
+ if (!("content" in message)) {
191
+ return message;
192
+ }
193
+ const { content } = message;
194
+ if (typeof content === "string" || content === null || content === void 0) {
195
+ return message;
196
+ }
197
+ if (!Array.isArray(content)) {
198
+ return message;
199
+ }
200
+ const text = content.map((part) => {
201
+ if (typeof part === "string") {
202
+ return part;
203
+ }
204
+ if (part.type === "text") {
205
+ return part.text ?? "";
206
+ }
207
+ return `[Unsupported content type: ${part.type}]`;
208
+ }).join("\n\n");
209
+ return {
210
+ ...message,
211
+ content: text
212
+ };
213
+ }
214
+ __name(flattenContentParts, "flattenContentParts");
215
+ function translateReasoningEffort(request) {
216
+ const r = request;
217
+ const nested = r["reasoning"];
218
+ const nestedEffort = nested?.effort;
219
+ if (typeof nestedEffort !== "string" || !nestedEffort) {
220
+ return request;
221
+ }
222
+ const next = { ...r };
223
+ if (typeof next["reasoning_effort"] !== "string" || !next["reasoning_effort"]) {
224
+ let normalized = nestedEffort;
225
+ if (normalized === "low" || normalized === "medium") normalized = "high";
226
+ else if (normalized === "xhigh") normalized = "max";
227
+ next["reasoning_effort"] = normalized;
228
+ }
229
+ if (nested && Object.keys(nested).length === 1) {
230
+ delete next["reasoning"];
231
+ } else if (nested) {
232
+ const { effort: _drop, ...rest } = nested;
233
+ next["reasoning"] = rest;
234
+ }
235
+ return next;
236
+ }
237
+ __name(translateReasoningEffort, "translateReasoningEffort");
238
+
239
+ // packages/core/src/core/openaiContentGenerator/provider/zai.ts
240
+ init_esbuild_shims();
241
+ var debugLogger = createDebugLogger("ZAI");
242
+ function isZaiHostname(contentGeneratorConfig) {
243
+ const baseUrl = contentGeneratorConfig.baseUrl;
244
+ if (!baseUrl) {
245
+ return false;
246
+ }
247
+ try {
248
+ const hostname = new URL(baseUrl).hostname.toLowerCase();
249
+ return hostname === "z.ai" || hostname.endsWith(".z.ai") || hostname === "bigmodel.cn" || hostname.endsWith(".bigmodel.cn");
250
+ } catch {
251
+ return false;
252
+ }
253
+ }
254
+ __name(isZaiHostname, "isZaiHostname");
255
+ function isZaiProvider(contentGeneratorConfig) {
256
+ if (isZaiHostname(contentGeneratorConfig)) {
257
+ return true;
258
+ }
259
+ const model = contentGeneratorConfig.model ?? "";
260
+ return model.toLowerCase().startsWith("glm-");
261
+ }
262
+ __name(isZaiProvider, "isZaiProvider");
263
+ var ZaiOpenAICompatibleProvider = class extends DefaultOpenAICompatibleProvider {
264
+ static {
265
+ __name(this, "ZaiOpenAICompatibleProvider");
266
+ }
267
+ static isZaiProvider = isZaiProvider;
268
+ static isZaiHostname = isZaiHostname;
269
+ // Latch so the skipped-flatten warning fires once per provider lifetime.
270
+ nonZaiHostnameFlattenWarned = false;
271
+ buildRequest(request, userPromptId) {
272
+ const baseRequest = super.buildRequest(request, userPromptId);
273
+ if (isZaiHostname(this.contentGeneratorConfig)) {
274
+ return flattenReasoningEffort(baseRequest);
275
+ }
276
+ const reasoning = baseRequest["reasoning"];
277
+ if (reasoning?.effort && !baseRequest["reasoning_effort"] && !this.nonZaiHostnameFlattenWarned) {
278
+ debugLogger.warn(
279
+ `GLM model '${this.contentGeneratorConfig.model ?? "unknown"}' on a non-Z.ai hostname; leaving nested reasoning.effort='${String(
280
+ reasoning.effort
281
+ )}' unflattened (reasoning_effort reshape is hostname-gated).`
282
+ );
283
+ this.nonZaiHostnameFlattenWarned = true;
284
+ }
285
+ return baseRequest;
286
+ }
287
+ };
288
+ function flattenReasoningEffort(request) {
289
+ const r = request;
290
+ const nested = r["reasoning"];
291
+ const effort = nested?.effort;
292
+ if (typeof effort !== "string" || !effort) {
293
+ return request;
294
+ }
295
+ const next = { ...r };
296
+ if (typeof next["reasoning_effort"] !== "string" || !next["reasoning_effort"]) {
297
+ next["reasoning_effort"] = effort;
298
+ }
299
+ if (nested && Object.keys(nested).length === 1) {
300
+ delete next["reasoning"];
301
+ } else if (nested) {
302
+ const { effort: _drop, ...rest } = nested;
303
+ next["reasoning"] = rest;
304
+ }
305
+ return next;
306
+ }
307
+ __name(flattenReasoningEffort, "flattenReasoningEffort");
308
+
309
+ // packages/core/src/core/openaiContentGenerator/provider/minimax.ts
310
+ init_esbuild_shims();
311
+ var MINIMAX_KNOWN_HOSTS = ["api.minimaxi.com", "api.minimax.io"];
312
+ var MINIMAX_HOST_SUFFIXES = [".minimaxi.com", ".minimax.io"];
313
+ var MiniMaxOpenAICompatibleProvider = class extends DefaultOpenAICompatibleProvider {
314
+ static {
315
+ __name(this, "MiniMaxOpenAICompatibleProvider");
316
+ }
317
+ static isMiniMaxProvider(config) {
318
+ if (!config.baseUrl) return false;
319
+ try {
320
+ const hostname = new URL(config.baseUrl).hostname.toLowerCase();
321
+ if (MINIMAX_KNOWN_HOSTS.includes(hostname)) {
322
+ return true;
323
+ }
324
+ return MINIMAX_HOST_SUFFIXES.some((suffix) => hostname.endsWith(suffix));
325
+ } catch {
326
+ return false;
327
+ }
328
+ }
329
+ getResponseParsingOptions() {
330
+ return { taggedThinkingTags: true };
331
+ }
332
+ };
333
+
334
+ // packages/core/src/core/openaiContentGenerator/provider/mistral.ts
335
+ init_esbuild_shims();
336
+ var MISTRAL_API_HOST = "api.mistral.ai";
337
+ var MISTRAL_MODEL_MARKERS = [
338
+ "mistral",
339
+ "mixtral",
340
+ "codestral",
341
+ "ministral",
342
+ "pixtral",
343
+ "magistral",
344
+ "devstral"
345
+ ];
346
+ function isMistralHostname(config) {
347
+ const baseUrl = config.baseUrl ?? "";
348
+ if (!baseUrl) return false;
349
+ try {
350
+ const hostname = new URL(baseUrl).hostname.toLowerCase();
351
+ return hostname === MISTRAL_API_HOST || hostname.endsWith(`.${MISTRAL_API_HOST}`);
352
+ } catch {
353
+ return false;
354
+ }
355
+ }
356
+ __name(isMistralHostname, "isMistralHostname");
357
+ function isMistralProvider(config) {
358
+ if (isMistralHostname(config)) return true;
359
+ const model = config.model?.toLowerCase() ?? "";
360
+ return MISTRAL_MODEL_MARKERS.some((marker) => model.includes(marker));
361
+ }
362
+ __name(isMistralProvider, "isMistralProvider");
363
+ var MistralOpenAICompatibleProvider = class extends DefaultOpenAICompatibleProvider {
364
+ static {
365
+ __name(this, "MistralOpenAICompatibleProvider");
366
+ }
367
+ static isMistralProvider = isMistralProvider;
368
+ buildRequest(request, userPromptId) {
369
+ const baseRequest = super.buildRequest(request, userPromptId);
370
+ return {
371
+ ...baseRequest,
372
+ messages: baseRequest.messages.map(stripReasoningContent)
373
+ };
374
+ }
375
+ };
376
+ function stripReasoningContent(message) {
377
+ if (!("reasoning_content" in message)) {
378
+ return message;
379
+ }
380
+ const next = { ...message };
381
+ delete next["reasoning_content"];
382
+ return next;
383
+ }
384
+ __name(stripReasoningContent, "stripReasoningContent");
385
+
386
+ // packages/core/src/core/openaiContentGenerator/provider/mimo.ts
387
+ init_esbuild_shims();
388
+ function isMiMoProvider(contentGeneratorConfig) {
389
+ const baseUrl = contentGeneratorConfig.baseUrl ?? "";
390
+ if (baseUrl) {
391
+ try {
392
+ const hostname = new URL(baseUrl).hostname.toLowerCase();
393
+ if (hostname === "xiaomimimo.com" || hostname.endsWith(".xiaomimimo.com")) {
394
+ return true;
395
+ }
396
+ } catch {
397
+ }
398
+ }
399
+ const model = contentGeneratorConfig.model ?? "";
400
+ return model.toLowerCase().startsWith("mimo-");
401
+ }
402
+ __name(isMiMoProvider, "isMiMoProvider");
403
+ var MiMoOpenAICompatibleProvider = class extends DefaultOpenAICompatibleProvider {
404
+ static {
405
+ __name(this, "MiMoOpenAICompatibleProvider");
406
+ }
407
+ constructor(contentGeneratorConfig, cliConfig) {
408
+ super(contentGeneratorConfig, cliConfig);
409
+ }
410
+ static isMiMoProvider = isMiMoProvider;
411
+ buildRequest(request, userPromptId) {
412
+ const baseRequest = super.buildRequest(request, userPromptId);
413
+ if (!baseRequest.messages?.length) {
414
+ return baseRequest;
415
+ }
416
+ return {
417
+ ...baseRequest,
418
+ messages: baseRequest.messages.map(
419
+ ensureReasoningContentOnAssistantMessage
420
+ )
421
+ };
422
+ }
423
+ getRequestContextOverrides() {
424
+ return {
425
+ splitToolMedia: this.contentGeneratorConfig.splitToolMedia ?? true
426
+ };
427
+ }
428
+ };
429
+
430
+ // packages/core/src/core/openaiContentGenerator/pipeline.ts
431
+ init_esbuild_shims();
432
+
433
+ // packages/core/src/core/openaiContentGenerator/streamingToolCallParser.ts
434
+ init_esbuild_shims();
435
+ var debugLogger2 = createDebugLogger("STREAMING_TOOL_CALL_PARSER");
436
+ var StreamingToolCallParser = class {
437
+ static {
438
+ __name(this, "StreamingToolCallParser");
439
+ }
440
+ /** Accumulated buffer containing all received chunks for each tool call index */
441
+ buffers = /* @__PURE__ */ new Map();
442
+ /** Current nesting depth in JSON structure for each tool call index */
443
+ depths = /* @__PURE__ */ new Map();
444
+ /** Whether we're currently inside a string literal for each tool call index */
445
+ inStrings = /* @__PURE__ */ new Map();
446
+ /** Whether the next character should be treated as escaped for each tool call index */
447
+ escapes = /* @__PURE__ */ new Map();
448
+ /** Metadata for each tool call index */
449
+ toolCallMeta = /* @__PURE__ */ new Map();
450
+ namelessToolCallIndices = /* @__PURE__ */ new Set();
451
+ /** Map from tool call ID to actual index used for storage */
452
+ idToIndexMap = /* @__PURE__ */ new Map();
453
+ /** Remapped slots awaiting a stable ID from a later chunk. */
454
+ pendingIndexRemaps = /* @__PURE__ */ new Map();
455
+ /** Counter for generating new indices when collisions occur */
456
+ nextAvailableIndex = 0;
457
+ conflictingToolCallIdentity = false;
458
+ invalidToolCallIndex = false;
459
+ /**
460
+ * Processes a new chunk of tool call data and attempts to parse complete JSON objects
461
+ *
462
+ * Handles the core problems of streaming tool call parsing:
463
+ * - Resolves index collisions when the same index is reused for different tool calls
464
+ * - Routes chunks without IDs to the correct incomplete tool call
465
+ * - Tracks JSON parsing state (depth, string boundaries, escapes) per tool call
466
+ * - Attempts parsing only when JSON structure is complete (depth = 0)
467
+ * - Repairs common issues like unclosed strings
468
+ *
469
+ * @param index - Tool call index from streaming response (may collide with existing calls)
470
+ * @param chunk - String chunk that may be empty, partial JSON, or complete data
471
+ * @param id - Optional tool call ID for collision detection and chunk routing
472
+ * @param name - Optional function name stored as metadata
473
+ * @returns ToolCallParseResult with completion status, parsed value, and repair info
474
+ */
475
+ addChunk(index, chunk, id, name) {
476
+ const validName = name?.trim() || void 0;
477
+ if (!Number.isSafeInteger(index) || index < 0) {
478
+ this.conflictingToolCallIdentity = true;
479
+ this.invalidToolCallIndex = true;
480
+ return {
481
+ complete: false,
482
+ error: new Error(`Invalid tool call index: ${index}`)
483
+ };
484
+ }
485
+ if (!id && !validName && !chunk.trim()) {
486
+ const depth2 = this.depths.get(index) ?? 0;
487
+ const inString2 = this.inStrings.get(index) ?? false;
488
+ if (!this.buffers.has(index) || depth2 === 0 && !inString2) {
489
+ return { complete: false };
490
+ }
491
+ }
492
+ let actualIndex = index;
493
+ const isKnownId = Boolean(id && this.idToIndexMap.has(id));
494
+ const existingName = this.toolCallMeta.get(index)?.name;
495
+ const isNameOnlyDelta = Boolean(
496
+ validName && chunk.length === 0 && (!existingName || existingName === validName)
497
+ );
498
+ if (id) {
499
+ if (this.idToIndexMap.has(id)) {
500
+ actualIndex = this.idToIndexMap.get(id);
501
+ } else if (this.pendingIndexRemaps.has(index)) {
502
+ actualIndex = this.pendingIndexRemaps.get(index);
503
+ this.pendingIndexRemaps.delete(index);
504
+ this.idToIndexMap.set(id, actualIndex);
505
+ } else {
506
+ if (this.buffers.has(index)) {
507
+ const existingBuffer = this.buffers.get(index);
508
+ const existingDepth = this.depths.get(index);
509
+ const existingMeta = this.toolCallMeta.get(index);
510
+ if (existingMeta?.id && existingMeta.id !== id) {
511
+ let existingComplete = existingDepth === 0;
512
+ if (existingComplete && existingBuffer.trim()) {
513
+ try {
514
+ JSON.parse(existingBuffer);
515
+ } catch {
516
+ existingComplete = false;
517
+ }
518
+ }
519
+ if (existingComplete) {
520
+ actualIndex = 0;
521
+ while (this.buffers.has(actualIndex)) actualIndex += 1;
522
+ if (!existingMeta.name) {
523
+ this.conflictingToolCallIdentity = true;
524
+ }
525
+ } else {
526
+ this.conflictingToolCallIdentity = true;
527
+ }
528
+ }
529
+ }
530
+ this.idToIndexMap.set(id, actualIndex);
531
+ }
532
+ } else if (!isNameOnlyDelta) {
533
+ if (this.pendingIndexRemaps.has(index)) {
534
+ actualIndex = this.pendingIndexRemaps.get(index);
535
+ const existingBuffer = this.buffers.get(actualIndex);
536
+ const existingDepth = this.depths.get(actualIndex);
537
+ if (existingDepth === 0 && existingBuffer.trim()) {
538
+ try {
539
+ JSON.parse(existingBuffer);
540
+ actualIndex = this.findMostRecentIncompleteIndex();
541
+ } catch {
542
+ }
543
+ }
544
+ } else if (this.buffers.has(index)) {
545
+ const existingBuffer = this.buffers.get(index);
546
+ const existingDepth = this.depths.get(index);
547
+ if (existingDepth > 0 || !existingBuffer.trim()) {
548
+ actualIndex = index;
549
+ } else {
550
+ try {
551
+ JSON.parse(existingBuffer);
552
+ actualIndex = this.findMostRecentIncompleteIndex();
553
+ } catch {
554
+ actualIndex = index;
555
+ }
556
+ }
557
+ }
558
+ }
559
+ if (!this.buffers.has(actualIndex)) {
560
+ this.buffers.set(actualIndex, "");
561
+ this.depths.set(actualIndex, 0);
562
+ this.inStrings.set(actualIndex, false);
563
+ this.escapes.set(actualIndex, false);
564
+ this.toolCallMeta.set(actualIndex, {});
565
+ }
566
+ const currentBuffer = this.buffers.get(actualIndex);
567
+ const currentDepth = this.depths.get(actualIndex);
568
+ const meta = this.toolCallMeta.get(actualIndex);
569
+ if (chunk.length === 0 && (id || validName)) {
570
+ if (id) meta.id = id;
571
+ if (validName && !meta.name) meta.name = validName;
572
+ if (!meta.name && meta.id) {
573
+ this.namelessToolCallIndices.add(actualIndex);
574
+ } else {
575
+ this.namelessToolCallIndices.delete(actualIndex);
576
+ }
577
+ if (!meta.id && actualIndex !== index) {
578
+ this.pendingIndexRemaps.set(index, actualIndex);
579
+ }
580
+ return { actualIndex, complete: false };
581
+ }
582
+ if (isKnownId && currentDepth === 0) {
583
+ if (currentBuffer.trim()) {
584
+ try {
585
+ JSON.parse(currentBuffer);
586
+ debugLogger2.debug(
587
+ `Ignoring replay chunk for completed toolCall id=${id}`
588
+ );
589
+ return { actualIndex, complete: false };
590
+ } catch {
591
+ }
592
+ }
593
+ }
594
+ const identityChanged = Boolean(id && meta.id && meta.id !== id);
595
+ if (id) meta.id = id;
596
+ if (validName) {
597
+ if (!identityChanged && meta.name && meta.name !== validName) {
598
+ this.conflictingToolCallIdentity = true;
599
+ } else {
600
+ meta.name = validName;
601
+ }
602
+ }
603
+ if (!meta.id && actualIndex !== index) {
604
+ this.pendingIndexRemaps.set(index, actualIndex);
605
+ }
606
+ const currentInString = this.inStrings.get(actualIndex);
607
+ const currentEscape = this.escapes.get(actualIndex);
608
+ const newBuffer = currentBuffer + chunk;
609
+ this.buffers.set(actualIndex, newBuffer);
610
+ if (!meta.name && (meta.id || /\S/.test(newBuffer))) {
611
+ this.namelessToolCallIndices.add(actualIndex);
612
+ } else {
613
+ this.namelessToolCallIndices.delete(actualIndex);
614
+ }
615
+ let depth = currentDepth;
616
+ let inString = currentInString;
617
+ let escape = currentEscape;
618
+ for (const char of chunk) {
619
+ if (!inString) {
620
+ if (char === "{" || char === "[") depth++;
621
+ else if (char === "}" || char === "]") depth--;
622
+ }
623
+ if (char === '"' && !escape) {
624
+ inString = !inString;
625
+ }
626
+ escape = char === "\\" && !escape;
627
+ }
628
+ this.depths.set(actualIndex, depth);
629
+ this.inStrings.set(actualIndex, inString);
630
+ this.escapes.set(actualIndex, escape);
631
+ if (depth === 0 && newBuffer.trim().length > 0) {
632
+ try {
633
+ const parsed = JSON.parse(newBuffer);
634
+ return { actualIndex, complete: true, value: parsed };
635
+ } catch (e) {
636
+ if (inString) {
637
+ try {
638
+ const repaired = JSON.parse(newBuffer + '"');
639
+ return {
640
+ actualIndex,
641
+ complete: true,
642
+ value: repaired,
643
+ repaired: true
644
+ };
645
+ } catch {
646
+ }
647
+ }
648
+ return {
649
+ actualIndex,
650
+ complete: false,
651
+ error: e instanceof Error ? e : new Error(String(e))
652
+ };
653
+ }
654
+ }
655
+ return { actualIndex, complete: false };
656
+ }
657
+ /**
658
+ * Gets the current tool call metadata for a specific index
659
+ *
660
+ * @param index - The tool call index
661
+ * @returns Object containing id and name if available
662
+ */
663
+ getToolCallMeta(index) {
664
+ return this.toolCallMeta.get(index) || {};
665
+ }
666
+ hasNamelessToolCall() {
667
+ return this.namelessToolCallIndices.size > 0;
668
+ }
669
+ hasConflictingToolCallIdentity() {
670
+ return this.conflictingToolCallIdentity;
671
+ }
672
+ hasInvalidToolCallIndex() {
673
+ return this.invalidToolCallIndex;
674
+ }
675
+ hasInvalidToolCallArguments() {
676
+ for (const [index, buffer] of this.buffers.entries()) {
677
+ if (!this.toolCallMeta.get(index)?.name || buffer.length === 0) continue;
678
+ try {
679
+ const args = JSON.parse(buffer);
680
+ if (typeof args !== "object" || args === null || Array.isArray(args)) {
681
+ return true;
682
+ }
683
+ } catch {
684
+ return true;
685
+ }
686
+ }
687
+ return false;
688
+ }
689
+ /**
690
+ * Gets all completed tool calls that are ready to be emitted
691
+ *
692
+ * Attempts to parse accumulated buffers using multiple strategies:
693
+ * 1. Standard JSON.parse()
694
+ * 2. Auto-close unclosed strings and retry
695
+ * 3. Fallback to safeJsonParse for malformed data
696
+ *
697
+ * Only returns tool calls with name metadata. An empty buffer yields
698
+ * empty arguments ({}), matching the non-streaming path for no-argument
699
+ * tools. Should be called when streaming is complete (finish_reason is
700
+ * present).
701
+ *
702
+ * @returns Array of completed tool calls with their metadata and parsed arguments
703
+ */
704
+ getCompletedToolCalls() {
705
+ const completed = [];
706
+ const emittedIds = /* @__PURE__ */ new Set();
707
+ for (const [index, buffer] of this.buffers.entries()) {
708
+ const meta = this.toolCallMeta.get(index);
709
+ if (meta?.name) {
710
+ if (meta.id) {
711
+ if (emittedIds.has(meta.id)) {
712
+ continue;
713
+ }
714
+ emittedIds.add(meta.id);
715
+ }
716
+ let args = {};
717
+ if (buffer.trim()) {
718
+ try {
719
+ args = JSON.parse(buffer);
720
+ } catch {
721
+ const inString = this.inStrings.get(index);
722
+ if (inString) {
723
+ try {
724
+ args = JSON.parse(buffer + '"');
725
+ } catch {
726
+ args = safeJsonParse(buffer, {});
727
+ }
728
+ } else {
729
+ args = safeJsonParse(buffer, {});
730
+ }
731
+ }
732
+ if (typeof args !== "object" || args === null || Array.isArray(args)) {
733
+ debugLogger2.debug(
734
+ `Collapsing non-object arguments for tool call ${meta.name} (id=${meta.id}) at index ${index}; buffer likely polluted by a misrouted fragment`
735
+ );
736
+ args = {};
737
+ }
738
+ } else {
739
+ debugLogger2.debug(
740
+ `Emitting no-argument tool call ${meta.name} (id=${meta.id}) at index ${index} with empty buffer`
741
+ );
742
+ }
743
+ completed.push({
744
+ id: meta.id,
745
+ name: meta.name,
746
+ args,
747
+ index
748
+ });
749
+ }
750
+ }
751
+ return completed;
752
+ }
753
+ /**
754
+ * Finds the next available index for a new tool call
755
+ *
756
+ * Scans indices starting from nextAvailableIndex to find one that's safe to use.
757
+ * Reuses indices never claimed by a named tool call or with incomplete
758
+ * parsing states. Skips indices with complete tool call data — including
759
+ * no-argument calls with empty buffers — to prevent overwriting.
760
+ *
761
+ * @returns The next available index safe for storing a new tool call
762
+ */
763
+ findNextAvailableIndex() {
764
+ while (this.buffers.has(this.nextAvailableIndex)) {
765
+ const buffer = this.buffers.get(this.nextAvailableIndex);
766
+ const depth = this.depths.get(this.nextAvailableIndex);
767
+ const meta = this.toolCallMeta.get(this.nextAvailableIndex);
768
+ if (!meta?.name || depth > 0 || !meta?.id) {
769
+ return this.nextAvailableIndex;
770
+ }
771
+ if (buffer.trim()) {
772
+ try {
773
+ JSON.parse(buffer);
774
+ } catch {
775
+ return this.nextAvailableIndex;
776
+ }
777
+ }
778
+ this.nextAvailableIndex++;
779
+ }
780
+ return this.nextAvailableIndex++;
781
+ }
782
+ /**
783
+ * Finds the most recent incomplete tool call index
784
+ *
785
+ * Used when continuation chunks arrive without IDs. Scans existing tool calls
786
+ * to find the highest index with incomplete parsing state (depth > 0, empty
787
+ * buffer with no name metadata yet, or unparseable JSON). Falls back to
788
+ * creating a new index if none found.
789
+ *
790
+ * @returns The index of the most recent incomplete tool call, or a new available index
791
+ */
792
+ findMostRecentIncompleteIndex() {
793
+ let maxIndex = -1;
794
+ for (const [index, buffer] of this.buffers.entries()) {
795
+ const depth = this.depths.get(index);
796
+ const meta = this.toolCallMeta.get(index);
797
+ if (meta?.id && (depth > 0 || !buffer.trim() && !meta?.name)) {
798
+ maxIndex = Math.max(maxIndex, index);
799
+ } else if (buffer.trim()) {
800
+ try {
801
+ JSON.parse(buffer);
802
+ } catch {
803
+ maxIndex = Math.max(maxIndex, index);
804
+ }
805
+ }
806
+ }
807
+ return maxIndex >= 0 ? maxIndex : this.findNextAvailableIndex();
808
+ }
809
+ /**
810
+ * Resets the parser state for a specific tool call index
811
+ *
812
+ * @param index - The tool call index to reset
813
+ */
814
+ resetIndex(index) {
815
+ this.buffers.set(index, "");
816
+ this.depths.set(index, 0);
817
+ this.inStrings.set(index, false);
818
+ this.escapes.set(index, false);
819
+ this.toolCallMeta.set(index, {});
820
+ this.namelessToolCallIndices.delete(index);
821
+ for (const [providerIndex, actualIndex] of this.pendingIndexRemaps) {
822
+ if (providerIndex === index || actualIndex === index) {
823
+ this.pendingIndexRemaps.delete(providerIndex);
824
+ }
825
+ }
826
+ }
827
+ /**
828
+ * Resets the entire parser state for processing a new stream
829
+ *
830
+ * Clears all accumulated buffers, parsing states, metadata, and counters.
831
+ * Allows the parser to be reused for multiple independent streams without
832
+ * data leakage between sessions.
833
+ */
834
+ reset() {
835
+ this.buffers.clear();
836
+ this.depths.clear();
837
+ this.inStrings.clear();
838
+ this.escapes.clear();
839
+ this.toolCallMeta.clear();
840
+ this.namelessToolCallIndices.clear();
841
+ this.idToIndexMap.clear();
842
+ this.pendingIndexRemaps.clear();
843
+ this.nextAvailableIndex = 0;
844
+ this.conflictingToolCallIdentity = false;
845
+ this.invalidToolCallIndex = false;
846
+ }
847
+ /**
848
+ * Gets the current accumulated buffer content for a specific index
849
+ *
850
+ * @param index - The tool call index to retrieve buffer for
851
+ * @returns The current buffer content for the specified index (empty string if not found)
852
+ */
853
+ getBuffer(index) {
854
+ return this.buffers.get(index) || "";
855
+ }
856
+ /**
857
+ * Gets the current parsing state information for a specific index
858
+ *
859
+ * @param index - The tool call index to get state information for
860
+ * @returns Object containing current parsing state (depth, inString, escape)
861
+ */
862
+ getState(index) {
863
+ return {
864
+ depth: this.depths.get(index) || 0,
865
+ inString: this.inStrings.get(index) || false,
866
+ escape: this.escapes.get(index) || false
867
+ };
868
+ }
869
+ /**
870
+ * Checks whether any buffered tool call has incomplete JSON at stream end.
871
+ *
872
+ * A tool call is considered incomplete when its JSON parsing state indicates
873
+ * the buffer was truncated mid-stream:
874
+ * - depth > 0: unclosed braces/brackets remain
875
+ * - inString === true: still inside a string literal
876
+ *
877
+ * This is critical for detecting output truncation that the LLM provider
878
+ * may not report correctly via finish_reason (e.g. reporting "stop" or
879
+ * "tool_calls" instead of "length" when output was actually cut off).
880
+ *
881
+ * @returns true if at least one tool call buffer has incomplete JSON
882
+ */
883
+ hasIncompleteToolCalls() {
884
+ for (const [index] of this.buffers.entries()) {
885
+ const meta = this.toolCallMeta.get(index);
886
+ if (!meta?.name) continue;
887
+ const depth = this.depths.get(index) || 0;
888
+ const inString = this.inStrings.get(index) || false;
889
+ if (depth > 0 || inString) {
890
+ return true;
891
+ }
892
+ }
893
+ return false;
894
+ }
895
+ };
896
+
897
+ // packages/core/src/core/openaiContentGenerator/pipeline.ts
898
+ var debugLogger3 = createDebugLogger("OPENAI_PIPELINE");
899
+ function isRequiredThinkingError(error) {
900
+ if (getErrorStatus(error) !== 400) return false;
901
+ const providerMessage = getRateLimitErrorDetails(error).providerMessage;
902
+ const message = `${getErrorMessage(error)} ${providerMessage ?? ""}`;
903
+ return message.includes("enable_thinking") && /(?:restricted to|must be) true\b/i.test(message);
904
+ }
905
+ __name(isRequiredThinkingError, "isRequiredThinkingError");
906
+ var StreamContentError = class extends Error {
907
+ static {
908
+ __name(this, "StreamContentError");
909
+ }
910
+ constructor(message) {
911
+ super(message);
912
+ this.name = "StreamContentError";
913
+ }
914
+ };
915
+ var StreamInactivityTimeoutError = class extends Error {
916
+ constructor(idleMs, chunksReceived, streamLifetimeMs) {
917
+ super(
918
+ `No stream activity for ${idleMs}ms after ${chunksReceived} chunks (stream lifetime: ${streamLifetimeMs}ms). Set ${QWEN_STREAM_IDLE_TIMEOUT_MS_ENV} to increase this window (or 0 to disable it).`
919
+ );
920
+ this.idleMs = idleMs;
921
+ this.chunksReceived = chunksReceived;
922
+ this.streamLifetimeMs = streamLifetimeMs;
923
+ this.name = "StreamInactivityTimeoutError";
924
+ }
925
+ static {
926
+ __name(this, "StreamInactivityTimeoutError");
927
+ }
928
+ code = "ETIMEDOUT";
929
+ };
930
+ var NON_SSE_BODY_PREFIX_LIMIT = 512;
931
+ function isSSECompatibleContentType(contentType) {
932
+ if (!contentType) return true;
933
+ const mediaType = (contentType.split(";")[0] ?? "").trim().toLowerCase();
934
+ return mediaType === "text/event-stream" || mediaType === "application/x-ndjson" || mediaType === "application/stream+json";
935
+ }
936
+ __name(isSSECompatibleContentType, "isSSECompatibleContentType");
937
+ var NonSSEResponseError = class extends Error {
938
+ constructor(contentType, httpStatus, bodyPrefix, requestId) {
939
+ const preview = bodyPrefix.length > 0 ? ` Body prefix: ${bodyPrefix}` : "";
940
+ super(
941
+ `Streaming request received a non-SSE response (HTTP ${httpStatus}, Content-Type: ${contentType || "unknown"}).${preview}`
942
+ );
943
+ this.contentType = contentType;
944
+ this.httpStatus = httpStatus;
945
+ this.bodyPrefix = bodyPrefix;
946
+ this.requestId = requestId;
947
+ this.name = "NonSSEResponseError";
948
+ this.status = httpStatus;
949
+ this.request_id = requestId;
950
+ }
951
+ static {
952
+ __name(this, "NonSSEResponseError");
953
+ }
954
+ status;
955
+ request_id;
956
+ };
957
+ var PROVIDER_OUTPUT_BUDGET_KEYS = ["max_completion_tokens", "max_new_tokens"];
958
+ function hasProviderOutputBudgetKey(samplingParams) {
959
+ return PROVIDER_OUTPUT_BUDGET_KEYS.some(
960
+ (key) => samplingParams[key] !== void 0
961
+ );
962
+ }
963
+ __name(hasProviderOutputBudgetKey, "hasProviderOutputBudgetKey");
964
+ function clampProviderOutputBudgetKeys(samplingParams, requestMaxTokens) {
965
+ if (typeof requestMaxTokens !== "number") return samplingParams;
966
+ for (const key of PROVIDER_OUTPUT_BUDGET_KEYS) {
967
+ const value = samplingParams[key];
968
+ if (typeof value === "number" && value > requestMaxTokens) {
969
+ samplingParams[key] = requestMaxTokens;
970
+ }
971
+ }
972
+ return samplingParams;
973
+ }
974
+ __name(clampProviderOutputBudgetKeys, "clampProviderOutputBudgetKeys");
975
+ function resolveStreamIdleTimeoutMs(config) {
976
+ const fromConfig = config.streamIdleTimeoutMs;
977
+ if (typeof fromConfig === "number") {
978
+ if (Number.isInteger(fromConfig) && fromConfig <= MAX_STREAM_IDLE_TIMEOUT_MS) {
979
+ return fromConfig;
980
+ }
981
+ console.warn(
982
+ `[qwen-code] Ignoring out-of-range streamIdleTimeoutMs=${fromConfig} (expected an integer in (-\u221E, ${MAX_STREAM_IDLE_TIMEOUT_MS}]); falling back to ${QWEN_STREAM_IDLE_TIMEOUT_MS_ENV}/default.`
983
+ );
984
+ }
985
+ const raw = process.env[QWEN_STREAM_IDLE_TIMEOUT_MS_ENV];
986
+ const trimmed = raw?.trim();
987
+ if (trimmed) {
988
+ if (/^\d+$/.test(trimmed)) {
989
+ const parsed = Number(trimmed);
990
+ if (parsed <= MAX_STREAM_IDLE_TIMEOUT_MS) {
991
+ return parsed;
992
+ }
993
+ }
994
+ console.warn(
995
+ `[qwen-code] Ignoring invalid ${QWEN_STREAM_IDLE_TIMEOUT_MS_ENV}="${raw}" (expected an integer of milliseconds in [0, ${MAX_STREAM_IDLE_TIMEOUT_MS}]); using default ${DEFAULT_STREAM_IDLE_TIMEOUT_MS}ms.`
996
+ );
997
+ }
998
+ return DEFAULT_STREAM_IDLE_TIMEOUT_MS;
999
+ }
1000
+ __name(resolveStreamIdleTimeoutMs, "resolveStreamIdleTimeoutMs");
1001
+ async function* withStreamInactivityTimeout(source, idleMs, abortRequest, parentSignal) {
1002
+ const it = source[Symbol.asyncIterator]();
1003
+ const streamStartedAt = Date.now();
1004
+ let chunksReceived = 0;
1005
+ try {
1006
+ while (true) {
1007
+ const nextPromise = it.next();
1008
+ let timer;
1009
+ const timeout = new Promise((_resolve, reject) => {
1010
+ timer = setTimeout(() => {
1011
+ if (parentSignal?.aborted) {
1012
+ const abortErr = new Error("Aborted");
1013
+ abortErr.name = "AbortError";
1014
+ reject(abortErr);
1015
+ } else {
1016
+ abortRequest();
1017
+ reject(
1018
+ new StreamInactivityTimeoutError(
1019
+ idleMs,
1020
+ chunksReceived,
1021
+ Date.now() - streamStartedAt
1022
+ )
1023
+ );
1024
+ }
1025
+ }, idleMs);
1026
+ timer.unref?.();
1027
+ });
1028
+ let result;
1029
+ try {
1030
+ result = await Promise.race([nextPromise, timeout]);
1031
+ } catch (err) {
1032
+ void Promise.resolve(nextPromise).catch(() => {
1033
+ });
1034
+ throw err;
1035
+ } finally {
1036
+ if (timer !== void 0) clearTimeout(timer);
1037
+ }
1038
+ if (result.done) return;
1039
+ chunksReceived += 1;
1040
+ yield result.value;
1041
+ }
1042
+ } finally {
1043
+ abortRequest();
1044
+ try {
1045
+ await it.return?.();
1046
+ } catch {
1047
+ }
1048
+ }
1049
+ }
1050
+ __name(withStreamInactivityTimeout, "withStreamInactivityTimeout");
1051
+ var ContentGenerationPipeline = class {
1052
+ constructor(config) {
1053
+ this.config = config;
1054
+ this.contentGeneratorConfig = config.contentGeneratorConfig;
1055
+ this.client = this.config.provider.buildClient();
1056
+ this.streamIdleTimeoutMs = resolveStreamIdleTimeoutMs(
1057
+ this.contentGeneratorConfig
1058
+ );
1059
+ }
1060
+ static {
1061
+ __name(this, "ContentGenerationPipeline");
1062
+ }
1063
+ client;
1064
+ contentGeneratorConfig;
1065
+ requiredThinkingModels = /* @__PURE__ */ new Set();
1066
+ // Resolved once (config field > env > default) so the env read + any
1067
+ // invalid-value warning happen per pipeline, not per streaming request.
1068
+ streamIdleTimeoutMs;
1069
+ async execute(request, userPromptId) {
1070
+ return this.executeWithErrorHandling(
1071
+ request,
1072
+ userPromptId,
1073
+ false,
1074
+ async (openaiRequest, context) => {
1075
+ const parentSignal = request.config?.abortSignal;
1076
+ const perRequestAc = parentSignal ? createChildAbortController(parentSignal) : void 0;
1077
+ try {
1078
+ const openaiResponse = await this.client.chat.completions.create(
1079
+ openaiRequest,
1080
+ {
1081
+ signal: perRequestAc?.signal
1082
+ }
1083
+ );
1084
+ const geminiResponse = OpenAIContentConverter.convertOpenAIResponseToGemini(
1085
+ openaiResponse,
1086
+ context
1087
+ );
1088
+ return geminiResponse;
1089
+ } finally {
1090
+ perRequestAc?.abort();
1091
+ }
1092
+ }
1093
+ );
1094
+ }
1095
+ async executeStream(request, userPromptId) {
1096
+ return this.executeWithErrorHandling(
1097
+ request,
1098
+ userPromptId,
1099
+ true,
1100
+ async (openaiRequest, context) => {
1101
+ const parentSignal = request.config?.abortSignal;
1102
+ const perRequestAc = createChildAbortController(parentSignal);
1103
+ let stream;
1104
+ try {
1105
+ const createPromise = this.client.chat.completions.create(
1106
+ openaiRequest,
1107
+ { signal: perRequestAc.signal }
1108
+ );
1109
+ if (typeof createPromise.withResponse === "function") {
1110
+ const {
1111
+ data,
1112
+ response: httpResponse,
1113
+ request_id
1114
+ } = await createPromise.withResponse();
1115
+ stream = data;
1116
+ const contentType = httpResponse.headers.get("content-type") ?? null;
1117
+ if (!isSSECompatibleContentType(contentType)) {
1118
+ let bodyPrefix = "";
1119
+ try {
1120
+ if (httpResponse.body) {
1121
+ const reader = httpResponse.body.getReader();
1122
+ const { value } = await reader.read();
1123
+ reader.releaseLock();
1124
+ if (value) {
1125
+ bodyPrefix = new TextDecoder().decode(value).slice(0, NON_SSE_BODY_PREFIX_LIMIT);
1126
+ }
1127
+ }
1128
+ } catch {
1129
+ }
1130
+ throw new NonSSEResponseError(
1131
+ contentType,
1132
+ httpResponse.status,
1133
+ bodyPrefix,
1134
+ request_id
1135
+ );
1136
+ }
1137
+ } else {
1138
+ stream = await createPromise;
1139
+ }
1140
+ } catch (e) {
1141
+ perRequestAc.abort();
1142
+ throw e;
1143
+ }
1144
+ const idleMs = this.streamIdleTimeoutMs;
1145
+ const guarded = idleMs > 0 ? withStreamInactivityTimeout(
1146
+ stream,
1147
+ idleMs,
1148
+ () => perRequestAc.abort(),
1149
+ parentSignal
1150
+ ) : stream;
1151
+ const innerStream = this.processStreamWithLogging(
1152
+ guarded,
1153
+ context,
1154
+ request,
1155
+ userPromptId
1156
+ );
1157
+ async function* drainThenCleanup() {
1158
+ try {
1159
+ yield* innerStream;
1160
+ } finally {
1161
+ perRequestAc.abort();
1162
+ }
1163
+ }
1164
+ __name(drainThenCleanup, "drainThenCleanup");
1165
+ return drainThenCleanup();
1166
+ }
1167
+ );
1168
+ }
1169
+ /**
1170
+ * Stage 2: Process OpenAI stream with conversion and logging
1171
+ * This method handles the complete stream processing pipeline:
1172
+ * 1. Convert OpenAI chunks to Gemini format while preserving original chunks
1173
+ * 2. Filter empty responses
1174
+ * 3. Handle chunk merging for providers that send finishReason and usageMetadata separately
1175
+ * 4. Handle success/error logging
1176
+ */
1177
+ async *processStreamWithLogging(stream, context, request, userPromptId) {
1178
+ let pendingFinishResponse = null;
1179
+ let finishYielded = false;
1180
+ let pendingFinishProtocolTagSanitized;
1181
+ const logPendingProtocolTagSanitized = /* @__PURE__ */ __name((response, sanitization) => {
1182
+ if (!sanitization) return;
1183
+ const event = new ProtocolTagSanitizedEvent({
1184
+ model: context.model,
1185
+ promptId: userPromptId,
1186
+ responseId: response.responseId,
1187
+ tagName: sanitization.tagName,
1188
+ toolCallCount: sanitization.toolCallCount
1189
+ });
1190
+ debugLogger3.warn("Sanitized a model protocol tag", {
1191
+ model: event.model,
1192
+ promptId: event.prompt_id,
1193
+ responseId: event.response_id,
1194
+ tagName: event.tag_name,
1195
+ toolCallCount: event.tool_call_count
1196
+ });
1197
+ logProtocolTagSanitized(this.config.cliConfig, event);
1198
+ }, "logPendingProtocolTagSanitized");
1199
+ try {
1200
+ for await (const chunk of stream) {
1201
+ if (chunk.choices?.[0]?.finish_reason === "error_finish") {
1202
+ const errorContent = chunk.choices?.[0]?.delta?.content?.trim() || "Unknown stream error";
1203
+ throw new StreamContentError(errorContent);
1204
+ }
1205
+ const response = OpenAIContentConverter.convertOpenAIChunkToGemini(
1206
+ chunk,
1207
+ context
1208
+ );
1209
+ const sanitization = context.protocolTagSanitized;
1210
+ if (sanitization) {
1211
+ context.protocolTagSanitized = void 0;
1212
+ }
1213
+ if (response.candidates?.[0]?.content?.parts?.length === 0 && !response.candidates?.[0]?.finishReason && !response.usageMetadata && // Preparation-only responses must reach ACP before arguments complete.
1214
+ getToolCallPreparations(response).length === 0) {
1215
+ continue;
1216
+ }
1217
+ if (pendingFinishProtocolTagSanitized && pendingFinishResponse && !response.candidates?.[0]?.finishReason && response.candidates?.some(
1218
+ (candidate) => (candidate.content?.parts?.length ?? 0) > 0
1219
+ )) {
1220
+ throw new InvalidStreamError(
1221
+ "Model response continued after a finish reason.",
1222
+ "PROTOCOL_TAG_LEAK"
1223
+ );
1224
+ }
1225
+ if (finishYielded) {
1226
+ if (response.usageMetadata) {
1227
+ const pending = pendingFinishResponse;
1228
+ if (pending) {
1229
+ pending.usageMetadata = response.usageMetadata;
1230
+ }
1231
+ }
1232
+ continue;
1233
+ }
1234
+ if (!pendingFinishResponse && response.candidates?.[0]?.finishReason && sanitization) {
1235
+ pendingFinishProtocolTagSanitized = sanitization;
1236
+ }
1237
+ const shouldYield = this.handleChunkMerging(
1238
+ response,
1239
+ pendingFinishResponse,
1240
+ (mergedResponse) => {
1241
+ pendingFinishResponse = mergedResponse;
1242
+ }
1243
+ );
1244
+ if (shouldYield) {
1245
+ if (pendingFinishResponse) {
1246
+ logPendingProtocolTagSanitized(
1247
+ pendingFinishResponse,
1248
+ pendingFinishProtocolTagSanitized
1249
+ );
1250
+ yield pendingFinishResponse;
1251
+ finishYielded = true;
1252
+ } else {
1253
+ logPendingProtocolTagSanitized(response, sanitization);
1254
+ yield response;
1255
+ }
1256
+ }
1257
+ }
1258
+ if (context.pendingThinkingTagCandidate && !context.pendingThinkingTagCandidate.closingTagName && !/\S/.test(context.pendingThinkingTagCandidate.text)) {
1259
+ const pendingParts = context.pendingUntrustedResponseParts;
1260
+ context.pendingThinkingTagCandidate = void 0;
1261
+ context.pendingUntrustedResponseParts = void 0;
1262
+ if (pendingParts?.length) {
1263
+ const response = new GenerateContentResponse();
1264
+ response.candidates = [
1265
+ {
1266
+ content: { parts: pendingParts, role: "model" },
1267
+ index: 0
1268
+ }
1269
+ ];
1270
+ yield response;
1271
+ }
1272
+ } else if (context.pendingThinkingTagCandidate) {
1273
+ throw new InvalidStreamError(
1274
+ "Model response leaked thinking tags.",
1275
+ "PROTOCOL_TAG_LEAK"
1276
+ );
1277
+ }
1278
+ if (pendingFinishResponse && !finishYielded) {
1279
+ logPendingProtocolTagSanitized(
1280
+ pendingFinishResponse,
1281
+ pendingFinishProtocolTagSanitized
1282
+ );
1283
+ yield pendingFinishResponse;
1284
+ }
1285
+ } catch (error) {
1286
+ if (error instanceof InvalidStreamError) {
1287
+ throw error;
1288
+ }
1289
+ if (error instanceof StreamContentError) {
1290
+ throw redactProxyError(error);
1291
+ }
1292
+ if (context.pendingThinkingTagCandidate?.closingTagName && request.config?.abortSignal?.aborted !== true) {
1293
+ context.pendingThinkingTagCandidate = void 0;
1294
+ context.pendingUntrustedResponseParts = void 0;
1295
+ throw new InvalidStreamError(
1296
+ "Model response leaked thinking tags.",
1297
+ "PROTOCOL_TAG_LEAK"
1298
+ );
1299
+ }
1300
+ if (error instanceof StreamInactivityTimeoutError) {
1301
+ debugLogger3.warn("OpenAI stream inactivity timeout", {
1302
+ idleMs: error.idleMs,
1303
+ chunksReceived: error.chunksReceived,
1304
+ streamLifetimeMs: error.streamLifetimeMs
1305
+ });
1306
+ throw redactProxyError(error);
1307
+ }
1308
+ await this.handleError(error, context, request);
1309
+ }
1310
+ }
1311
+ /**
1312
+ * Handle chunk merging for providers that send finishReason and usageMetadata separately.
1313
+ *
1314
+ * Strategy: When we encounter a finishReason chunk, we hold it and merge all subsequent
1315
+ * chunks into it until the stream ends. This ensures the final chunk contains both
1316
+ * finishReason and the most up-to-date usage information from any provider pattern.
1317
+ *
1318
+ * @param response Current Gemini response
1319
+ * @param pendingFinishResponse Finish response currently held for merging
1320
+ * @param setPendingFinish Callback to set pending finish response
1321
+ * @returns true if the response should be yielded, false if it should be held for merging
1322
+ */
1323
+ handleChunkMerging(response, pendingFinishResponse, setPendingFinish) {
1324
+ const isFinishChunk = response.candidates?.[0]?.finishReason;
1325
+ if (isFinishChunk) {
1326
+ if (pendingFinishResponse) {
1327
+ if (response.usageMetadata) {
1328
+ pendingFinishResponse.usageMetadata = response.usageMetadata;
1329
+ }
1330
+ if (response.modelVersion) {
1331
+ pendingFinishResponse.modelVersion = response.modelVersion;
1332
+ }
1333
+ setPendingFinish(pendingFinishResponse);
1334
+ } else {
1335
+ setPendingFinish(response);
1336
+ }
1337
+ return false;
1338
+ } else if (pendingFinishResponse) {
1339
+ const mergedResponse = new GenerateContentResponse();
1340
+ mergedResponse.candidates = pendingFinishResponse.candidates;
1341
+ if (response.usageMetadata) {
1342
+ mergedResponse.usageMetadata = response.usageMetadata;
1343
+ } else {
1344
+ mergedResponse.usageMetadata = pendingFinishResponse.usageMetadata;
1345
+ }
1346
+ mergedResponse.responseId = response.responseId || pendingFinishResponse.responseId;
1347
+ mergedResponse.createTime = response.createTime || pendingFinishResponse.createTime;
1348
+ mergedResponse.modelVersion = response.modelVersion || pendingFinishResponse.modelVersion;
1349
+ mergedResponse.promptFeedback = response.promptFeedback || pendingFinishResponse.promptFeedback;
1350
+ setPendingFinish(mergedResponse);
1351
+ return true;
1352
+ }
1353
+ return true;
1354
+ }
1355
+ async buildRequest(request, userPromptId, context, isStreaming) {
1356
+ const messages = OpenAIContentConverter.convertGeminiRequestToOpenAI(
1357
+ request,
1358
+ context
1359
+ );
1360
+ const baseRequest = {
1361
+ model: context.model,
1362
+ messages,
1363
+ ...this.buildGenerateContentConfig(request)
1364
+ };
1365
+ if (isStreaming) {
1366
+ baseRequest.stream = true;
1367
+ baseRequest.stream_options = { include_usage: true };
1368
+ } else {
1369
+ baseRequest.stream = false;
1370
+ }
1371
+ if (request.config?.tools && request.config.tools.length > 0) {
1372
+ baseRequest.tools = await OpenAIContentConverter.convertGeminiToolsToOpenAI(
1373
+ request.config.tools,
1374
+ this.contentGeneratorConfig.schemaCompliance ?? "auto"
1375
+ );
1376
+ const fcMode = request.config?.toolConfig?.functionCallingConfig?.mode;
1377
+ if (fcMode === "ANY") {
1378
+ baseRequest["tool_choice"] = "required";
1379
+ } else if (fcMode === "NONE") {
1380
+ baseRequest["tool_choice"] = "none";
1381
+ }
1382
+ }
1383
+ const providerRequest = this.config.provider.buildRequest(
1384
+ baseRequest,
1385
+ userPromptId
1386
+ );
1387
+ const model = (context.model ?? "").toLowerCase();
1388
+ const isDashScope = DashScopeOpenAICompatibleProvider.isDashScopeProvider(
1389
+ this.contentGeneratorConfig
1390
+ );
1391
+ const thinkingMandatory = this.requiresThinking(model);
1392
+ const reasoningDisabled = request.config?.thinkingConfig?.includeThoughts === false || this.contentGeneratorConfig.reasoning === false;
1393
+ if (reasoningDisabled) {
1394
+ const typed = providerRequest;
1395
+ if (!thinkingMandatory && (model.startsWith("qwen") || model === "coder-model")) {
1396
+ if (isDashScope) {
1397
+ typed["enable_thinking"] = false;
1398
+ } else {
1399
+ delete typed["enable_thinking"];
1400
+ const existing = typed["chat_template_kwargs"] ?? {};
1401
+ typed["chat_template_kwargs"] = {
1402
+ ...existing,
1403
+ enable_thinking: false
1404
+ };
1405
+ }
1406
+ }
1407
+ if ("reasoning" in typed) {
1408
+ delete typed["reasoning"];
1409
+ }
1410
+ if ("reasoning_effort" in typed && typed["reasoning_effort"] !== "none") {
1411
+ delete typed["reasoning_effort"];
1412
+ }
1413
+ if (isDeepSeekHostname(this.contentGeneratorConfig)) {
1414
+ typed["thinking"] = { type: "disabled" };
1415
+ }
1416
+ }
1417
+ if (thinkingMandatory) {
1418
+ const typed = providerRequest;
1419
+ if (typed["enable_thinking"] === false) {
1420
+ delete typed["enable_thinking"];
1421
+ }
1422
+ const chatTemplateKwargs = typed["chat_template_kwargs"];
1423
+ if (chatTemplateKwargs?.["enable_thinking"] === false) {
1424
+ const remaining = { ...chatTemplateKwargs };
1425
+ delete remaining["enable_thinking"];
1426
+ if (Object.keys(remaining).length > 0) {
1427
+ typed["chat_template_kwargs"] = remaining;
1428
+ } else {
1429
+ delete typed["chat_template_kwargs"];
1430
+ }
1431
+ }
1432
+ if (isDashScope && typed["tool_choice"] === "required") {
1433
+ delete typed["tool_choice"];
1434
+ }
1435
+ }
1436
+ return providerRequest;
1437
+ }
1438
+ requiresThinking(model) {
1439
+ const normalizedModel = model.toLowerCase();
1440
+ return this.requiredThinkingModels.has(normalizedModel) || this.contentGeneratorConfig.thinkingMandatory === true && normalizedModel === (this.contentGeneratorConfig.model ?? "").toLowerCase();
1441
+ }
1442
+ buildGenerateContentConfig(request) {
1443
+ const defaultSamplingParams = this.config.provider.getDefaultGenerationConfig();
1444
+ const configSamplingParams = this.contentGeneratorConfig.samplingParams;
1445
+ const getParameterValue = /* @__PURE__ */ __name((configKey, requestKey) => {
1446
+ const configValue = configSamplingParams?.[configKey];
1447
+ const requestValue = requestKey ? request.config?.[requestKey] : void 0;
1448
+ const defaultValue = requestKey ? defaultSamplingParams[requestKey] : void 0;
1449
+ if (configValue !== void 0) return configValue;
1450
+ if (requestValue !== void 0) return requestValue;
1451
+ return defaultValue;
1452
+ }, "getParameterValue");
1453
+ const addParameterIfDefined = /* @__PURE__ */ __name((key, configKey, requestKey) => {
1454
+ const value = getParameterValue(configKey, requestKey);
1455
+ return value !== void 0 ? { [key]: value } : {};
1456
+ }, "addParameterIfDefined");
1457
+ if (configSamplingParams !== void 0) {
1458
+ const requestMaxTokens = request.config?.maxOutputTokens;
1459
+ const maxTokens = reconcileMaxTokens(configSamplingParams.max_tokens, requestMaxTokens) ?? configSamplingParams.max_tokens ?? (hasProviderOutputBudgetKey(configSamplingParams) ? void 0 : requestMaxTokens);
1460
+ return clampProviderOutputBudgetKeys(
1461
+ maxTokens !== void 0 ? { ...configSamplingParams, max_tokens: maxTokens } : { ...configSamplingParams },
1462
+ requestMaxTokens
1463
+ );
1464
+ }
1465
+ const params = {
1466
+ // Parameters with request fallback but no defaults
1467
+ ...addParameterIfDefined("temperature", "temperature", "temperature"),
1468
+ ...addParameterIfDefined("top_p", "top_p", "topP"),
1469
+ // Max tokens (special case: different property names)
1470
+ ...addParameterIfDefined("max_tokens", "max_tokens", "maxOutputTokens"),
1471
+ // Config-only parameters (no request fallback)
1472
+ ...addParameterIfDefined("top_k", "top_k", "topK"),
1473
+ ...addParameterIfDefined("repetition_penalty", "repetition_penalty"),
1474
+ ...addParameterIfDefined(
1475
+ "presence_penalty",
1476
+ "presence_penalty",
1477
+ "presencePenalty"
1478
+ ),
1479
+ ...addParameterIfDefined(
1480
+ "frequency_penalty",
1481
+ "frequency_penalty",
1482
+ "frequencyPenalty"
1483
+ ),
1484
+ ...this.buildReasoningConfig(request)
1485
+ };
1486
+ return params;
1487
+ }
1488
+ buildReasoningConfig(request) {
1489
+ if (request.config?.thinkingConfig?.includeThoughts === false) {
1490
+ return {};
1491
+ }
1492
+ const reasoning = this.contentGeneratorConfig.reasoning;
1493
+ if (reasoning === false || reasoning === void 0) {
1494
+ return {};
1495
+ }
1496
+ return { reasoning };
1497
+ }
1498
+ /**
1499
+ * Common error handling wrapper for execute methods
1500
+ */
1501
+ async executeWithErrorHandling(request, userPromptId, isStreaming, executor) {
1502
+ const context = this.createRequestContext(request, isStreaming);
1503
+ let openaiRequest;
1504
+ const executeAttempt = /* @__PURE__ */ __name(async () => {
1505
+ openaiRequest = await this.buildRequest(
1506
+ request,
1507
+ userPromptId,
1508
+ context,
1509
+ isStreaming
1510
+ );
1511
+ openaiRequestCaptureContext.getStore()?.(openaiRequest);
1512
+ runtimeDiagnostics.recordOpenAIWireRequest(openaiRequest);
1513
+ return executor(openaiRequest, context);
1514
+ }, "executeAttempt");
1515
+ try {
1516
+ return await executeAttempt();
1517
+ } catch (error) {
1518
+ const model = context.model.toLowerCase();
1519
+ const wireRequest = openaiRequest;
1520
+ const chatTemplateKwargs = wireRequest?.["chat_template_kwargs"];
1521
+ if ((wireRequest?.["enable_thinking"] === false || chatTemplateKwargs?.["enable_thinking"] === false) && request.config?.abortSignal?.aborted !== true && isRequiredThinkingError(error)) {
1522
+ this.requiredThinkingModels.add(model);
1523
+ debugLogger3.warn("Retrying with required thinking enabled", {
1524
+ model,
1525
+ originalError: getErrorMessage(error)
1526
+ });
1527
+ try {
1528
+ return await executeAttempt();
1529
+ } catch (retryError) {
1530
+ return await this.handleError(retryError, context, request);
1531
+ }
1532
+ }
1533
+ return await this.handleError(error, context, request);
1534
+ }
1535
+ }
1536
+ /**
1537
+ * Shared error handling logic for both executeWithErrorHandling and processStreamWithLogging
1538
+ * This centralizes the common error processing steps to avoid duplication
1539
+ */
1540
+ async handleError(error, context, request) {
1541
+ this.config.errorHandler.handle(redactProxyError(error), context, request);
1542
+ }
1543
+ /**
1544
+ * Create request context with common properties
1545
+ */
1546
+ createRequestContext(request, isStreaming) {
1547
+ const effectiveModel = request.model || this.contentGeneratorConfig.model;
1548
+ const providerOverrides = this.config.provider.getRequestContextOverrides?.() ?? {};
1549
+ const toolCallParser = isStreaming ? new StreamingToolCallParser() : void 0;
1550
+ const responseParsingOptions = this.config.provider.getResponseParsingOptions?.();
1551
+ const taggedThinkingParser = isStreaming && responseParsingOptions?.taggedThinkingTags ? new TaggedThinkingParser() : void 0;
1552
+ return {
1553
+ model: effectiveModel,
1554
+ modalities: this.contentGeneratorConfig.modalities ?? {},
1555
+ startTime: Date.now(),
1556
+ splitToolMedia: providerOverrides.splitToolMedia ?? this.contentGeneratorConfig.splitToolMedia ?? // Default true: the OpenAI Chat Completions spec only permits text on
1557
+ // `role: "tool"` messages, so tool-returned media (e.g. an image read
1558
+ // by read_file) embedded there is silently dropped or rejected by
1559
+ // strict providers (doubao / new-api / LM Studio) and the model never
1560
+ // sees it (QwenLM/qwen-code#4876). Splitting it into a follow-up user
1561
+ // message is spec-compliant and safe for permissive providers too.
1562
+ // Opt out via generationConfig.splitToolMedia = false.
1563
+ true,
1564
+ toolResultContentFormat: providerOverrides.toolResultContentFormat ?? this.contentGeneratorConfig.toolResultContentFormat ?? "parts",
1565
+ ...toolCallParser ? { toolCallParser } : {},
1566
+ ...responseParsingOptions ? { responseParsingOptions } : {},
1567
+ ...taggedThinkingParser ? { taggedThinkingParser } : {}
1568
+ };
1569
+ }
1570
+ };
1571
+
1572
+ // packages/core/src/core/openaiContentGenerator/errorHandler.ts
1573
+ init_esbuild_shims();
1574
+ var debugLogger4 = createDebugLogger("OPENAI_ERROR");
1575
+ var EnhancedErrorHandler = class {
1576
+ constructor(shouldSuppressLogging = () => false) {
1577
+ this.shouldSuppressLogging = shouldSuppressLogging;
1578
+ }
1579
+ static {
1580
+ __name(this, "EnhancedErrorHandler");
1581
+ }
1582
+ handle(error, context, request) {
1583
+ const redactedError = redactProxyError(error);
1584
+ const isTimeoutError = this.isTimeoutError(redactedError);
1585
+ const errorMessage = this.buildErrorMessage(
1586
+ redactedError,
1587
+ context,
1588
+ isTimeoutError
1589
+ );
1590
+ if (!this.shouldSuppressErrorLogging(redactedError, request)) {
1591
+ debugLogger4.error(
1592
+ "OpenAI API Error:",
1593
+ errorMessage,
1594
+ this.buildDiagnostics(redactedError, context)
1595
+ );
1596
+ }
1597
+ if (isTimeoutError) {
1598
+ throw new Error(
1599
+ `${errorMessage}
1600
+
1601
+ ${this.getTimeoutTroubleshootingTips()}`
1602
+ );
1603
+ }
1604
+ throw redactedError;
1605
+ }
1606
+ shouldSuppressErrorLogging(error, request) {
1607
+ return this.shouldSuppressLogging(error, request);
1608
+ }
1609
+ isTimeoutError(error) {
1610
+ if (!error) return false;
1611
+ const errorMessage = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
1612
+ const errorCode = error?.code;
1613
+ const errorType = error?.type;
1614
+ return errorMessage.includes("timeout") || errorMessage.includes("timed out") || errorMessage.includes("connection timeout") || errorMessage.includes("request timeout") || errorMessage.includes("read timeout") || errorMessage.includes("etimedout") || errorMessage.includes("esockettimedout") || errorCode === "ETIMEDOUT" || errorCode === "ESOCKETTIMEDOUT" || errorType === "timeout" || errorMessage.includes("request timed out") || errorMessage.includes("deadline exceeded");
1615
+ }
1616
+ buildErrorMessage(error, context, isTimeoutError) {
1617
+ const durationSeconds = Math.round((Date.now() - context.startTime) / 1e3);
1618
+ if (isTimeoutError) {
1619
+ return `Request timeout after ${durationSeconds}s. Try reducing input length or increasing timeout in config.`;
1620
+ }
1621
+ return error instanceof Error ? getErrorMessage(error) : String(error);
1622
+ }
1623
+ buildDiagnostics(error, context) {
1624
+ const details = getRateLimitErrorDetails(error);
1625
+ const requestId = this.getRequestId(error) ?? details.requestId;
1626
+ const statusCode = getErrorStatus(error);
1627
+ return {
1628
+ model: context.model,
1629
+ durationMs: Date.now() - context.startTime,
1630
+ errorType: getErrorType(error),
1631
+ ...statusCode !== void 0 ? { statusCode } : {},
1632
+ ...details.providerCode !== void 0 ? { providerCode: details.providerCode } : {},
1633
+ ...details.providerMessage !== void 0 ? { providerMessage: details.providerMessage } : {},
1634
+ ...requestId !== void 0 ? { requestId } : {},
1635
+ ...details.transport !== "unknown" ? { transport: details.transport } : {}
1636
+ };
1637
+ }
1638
+ getRequestId(error) {
1639
+ if (!error || typeof error !== "object") return void 0;
1640
+ const source = error;
1641
+ for (const value of [
1642
+ source.requestID,
1643
+ source.request_id,
1644
+ source.response_id
1645
+ ]) {
1646
+ if (typeof value === "string" && value) {
1647
+ return value;
1648
+ }
1649
+ }
1650
+ return void 0;
1651
+ }
1652
+ getTimeoutTroubleshootingTips() {
1653
+ const tips = [
1654
+ "- Reduce input length or complexity",
1655
+ "- Increase timeout in config: contentGenerator.timeout",
1656
+ "- Check network connectivity"
1657
+ ];
1658
+ return `Troubleshooting tips:
1659
+ ${tips.join("\n")}`;
1660
+ }
1661
+ };
1662
+
1663
+ // packages/core/src/core/openaiContentGenerator/openaiContentGenerator.ts
1664
+ var debugLogger5 = createDebugLogger("OPENAI");
1665
+ var OpenAIContentGenerator = class {
1666
+ static {
1667
+ __name(this, "OpenAIContentGenerator");
1668
+ }
1669
+ pipeline;
1670
+ constructor(contentGeneratorConfig, cliConfig, provider) {
1671
+ const pipelineConfig = {
1672
+ cliConfig,
1673
+ provider,
1674
+ contentGeneratorConfig,
1675
+ errorHandler: new EnhancedErrorHandler(
1676
+ (error, request) => this.shouldSuppressErrorLogging(error, request)
1677
+ )
1678
+ };
1679
+ this.pipeline = new ContentGenerationPipeline(pipelineConfig);
1680
+ }
1681
+ /**
1682
+ * Hook for subclasses to customize error handling behavior
1683
+ * @param error The error that occurred
1684
+ * @param request The original request
1685
+ * @returns true if error logging should be suppressed, false otherwise
1686
+ */
1687
+ shouldSuppressErrorLogging(error, request) {
1688
+ if (isAbortError(error) && request.config?.abortSignal?.aborted) {
1689
+ return true;
1690
+ }
1691
+ return false;
1692
+ }
1693
+ async generateContent(request, userPromptId) {
1694
+ return this.pipeline.execute(request, userPromptId);
1695
+ }
1696
+ async generateContentStream(request, userPromptId) {
1697
+ return this.pipeline.executeStream(request, userPromptId);
1698
+ }
1699
+ async countTokens(request) {
1700
+ try {
1701
+ const estimator = new RequestTokenizer();
1702
+ const result = await estimator.calculateTokens(request);
1703
+ return {
1704
+ totalTokens: result.totalTokens
1705
+ };
1706
+ } catch (error) {
1707
+ debugLogger5.warn(
1708
+ "Failed to calculate tokens with new tokenizer, falling back to simple method:",
1709
+ error
1710
+ );
1711
+ const content = JSON.stringify(request.contents);
1712
+ const totalTokens = Math.ceil(content.length / 4);
1713
+ return {
1714
+ totalTokens
1715
+ };
1716
+ }
1717
+ }
1718
+ async embedContent(request) {
1719
+ let text = "";
1720
+ if (Array.isArray(request.contents)) {
1721
+ text = request.contents.map((content) => {
1722
+ if (typeof content === "string") return content;
1723
+ if ("parts" in content && content.parts) {
1724
+ return content.parts.map(
1725
+ (part) => typeof part === "string" ? part : "text" in part ? part.text || "" : ""
1726
+ ).join(" ");
1727
+ }
1728
+ return "";
1729
+ }).join(" ");
1730
+ } else if (request.contents) {
1731
+ if (typeof request.contents === "string") {
1732
+ text = request.contents;
1733
+ } else if ("parts" in request.contents && request.contents.parts) {
1734
+ text = request.contents.parts.map(
1735
+ (part) => typeof part === "string" ? part : "text" in part ? part.text : ""
1736
+ ).join(" ");
1737
+ }
1738
+ }
1739
+ try {
1740
+ const embedding = await this.pipeline.client.embeddings.create({
1741
+ model: "text-embedding-ada-002",
1742
+ // Default embedding model
1743
+ input: text
1744
+ });
1745
+ return {
1746
+ embeddings: [
1747
+ {
1748
+ values: embedding.data[0].embedding
1749
+ }
1750
+ ]
1751
+ };
1752
+ } catch (error) {
1753
+ const redactedError = redactProxyError(error);
1754
+ debugLogger5.error("OpenAI API Embedding Error:", redactedError);
1755
+ throw new Error(
1756
+ `OpenAI API error: ${redactedError instanceof Error ? redactedError.message : String(redactedError)}`
1757
+ );
1758
+ }
1759
+ }
1760
+ useSummarizedThinking() {
1761
+ return false;
1762
+ }
1763
+ };
1764
+
1765
+ // packages/core/src/core/openaiContentGenerator/index.ts
1766
+ function createOpenAIContentGenerator(contentGeneratorConfig, cliConfig) {
1767
+ const provider = determineProvider(contentGeneratorConfig, cliConfig);
1768
+ return new OpenAIContentGenerator(
1769
+ contentGeneratorConfig,
1770
+ cliConfig,
1771
+ provider
1772
+ );
1773
+ }
1774
+ __name(createOpenAIContentGenerator, "createOpenAIContentGenerator");
1775
+ function determineProvider(contentGeneratorConfig, cliConfig) {
1776
+ const config = contentGeneratorConfig || cliConfig.getContentGeneratorConfig();
1777
+ if (DashScopeOpenAICompatibleProvider.isDashScopeProvider(config)) {
1778
+ return new DashScopeOpenAICompatibleProvider(
1779
+ contentGeneratorConfig,
1780
+ cliConfig
1781
+ );
1782
+ }
1783
+ if (DeepSeekOpenAICompatibleProvider.isDeepSeekProvider(config)) {
1784
+ return new DeepSeekOpenAICompatibleProvider(
1785
+ contentGeneratorConfig,
1786
+ cliConfig
1787
+ );
1788
+ }
1789
+ if (ZaiOpenAICompatibleProvider.isZaiProvider(config)) {
1790
+ return new ZaiOpenAICompatibleProvider(contentGeneratorConfig, cliConfig);
1791
+ }
1792
+ if (MiMoOpenAICompatibleProvider.isMiMoProvider(config)) {
1793
+ return new MiMoOpenAICompatibleProvider(contentGeneratorConfig, cliConfig);
1794
+ }
1795
+ if (ModelScopeOpenAICompatibleProvider.isModelScopeProvider(config)) {
1796
+ return new ModelScopeOpenAICompatibleProvider(
1797
+ contentGeneratorConfig,
1798
+ cliConfig
1799
+ );
1800
+ }
1801
+ if (MiniMaxOpenAICompatibleProvider.isMiniMaxProvider(config)) {
1802
+ return new MiniMaxOpenAICompatibleProvider(
1803
+ contentGeneratorConfig,
1804
+ cliConfig
1805
+ );
1806
+ }
1807
+ if (MistralOpenAICompatibleProvider.isMistralProvider(config)) {
1808
+ return new MistralOpenAICompatibleProvider(
1809
+ contentGeneratorConfig,
1810
+ cliConfig
1811
+ );
1812
+ }
1813
+ return new DefaultOpenAICompatibleProvider(contentGeneratorConfig, cliConfig);
1814
+ }
1815
+ __name(determineProvider, "determineProvider");
1816
+
1817
+ export {
1818
+ DeepSeekOpenAICompatibleProvider,
1819
+ MiniMaxOpenAICompatibleProvider,
1820
+ MistralOpenAICompatibleProvider,
1821
+ MiMoOpenAICompatibleProvider,
1822
+ ContentGenerationPipeline,
1823
+ EnhancedErrorHandler,
1824
+ OpenAIContentGenerator,
1825
+ createOpenAIContentGenerator,
1826
+ determineProvider
1827
+ };
1828
+ /**
1829
+ * @license
1830
+ * Copyright 2025 Qwen
1831
+ * SPDX-License-Identifier: Apache-2.0
1832
+ */