@qwen-code/qwen-code 0.23.2 → 0.23.3

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 (373) hide show
  1. package/README.md +35 -15
  2. package/bundled/computer-use/SKILL.md +1 -1
  3. package/bundled/qc-helper/docs/configuration/model-providers.md +66 -28
  4. package/bundled/qc-helper/docs/configuration/settings.md +5 -3
  5. package/bundled/qc-helper/docs/features/_meta.ts +1 -0
  6. package/bundled/qc-helper/docs/features/channels/dws.md +7 -1
  7. package/bundled/qc-helper/docs/features/commands.md +57 -9
  8. package/bundled/qc-helper/docs/features/computer-use.md +1 -1
  9. package/bundled/qc-helper/docs/features/cross-session-protocol.md +320 -0
  10. package/bundled/qc-helper/docs/features/goals.md +1 -1
  11. package/bundled/qc-helper/docs/qwen-serve.md +16 -3
  12. package/bundled/review/SKILL.md +82 -79
  13. package/bundled/review/references/posting.md +31 -14
  14. package/chunks/{MaxSizedBox-4C3BKKKY.js → MaxSizedBox-D4LW7RZZ.js} +58 -51
  15. package/chunks/{StandaloneSessionPicker-TXVF65YW.js → StandaloneSessionPicker-ALTTRWUP.js} +80 -73
  16. package/chunks/acp-subagent-executor-LEUN3N7N.js +919 -0
  17. package/chunks/{acpAgent-H5XBKGB4.js → acpAgent-BBSW7XZG.js} +509 -201
  18. package/chunks/{agent-T5LEFJIU.js → agent-SQ6OY3QD.js} +42 -36
  19. package/chunks/{agent-headless-VZKSRH36.js → agent-headless-RI2THRQ7.js} +42 -36
  20. package/chunks/{anthropicContentGenerator-PRJWWVYJ.js → anthropicContentGenerator-JSKMKS6V.js} +66 -34
  21. package/chunks/{artifact-tool-G5LHNECG.js → artifact-tool-PMYZCYNH.js} +2 -2
  22. package/chunks/{askUserQuestion-I5W5S3D6.js → askUserQuestion-4M4YYIB4.js} +2 -2
  23. package/chunks/{bridge-AOX5IY44.js → bridge-DAFMI72L.js} +62 -55
  24. package/chunks/{channel-management-service-MWQGHPAS.js → channel-management-service-OWDXVL7R.js} +8 -8
  25. package/chunks/{channel-settings-store-XZCGDGHW.js → channel-settings-store-4I6JONT7.js} +69 -62
  26. package/chunks/{channel-worker-group-SQ5FRWOH.js → channel-worker-group-F2ZZMLNS.js} +8 -8
  27. package/chunks/{channel-worker-manager-TU4ZNWOE.js → channel-worker-manager-2SZLJJSJ.js} +18 -9
  28. package/chunks/{channel-worker-supervisor-EMITFMCP.js → channel-worker-supervisor-ZFNWMG6D.js} +6 -6
  29. package/chunks/{chunk-GNY7B3CA.js → chunk-2ALXPGB4.js} +1 -1
  30. package/chunks/{chunk-LUNC5KCL.js → chunk-2PJRI3EH.js} +7 -7
  31. package/chunks/{chunk-CLKE4IY3.js → chunk-2SZH22YO.js} +1 -1
  32. package/chunks/{chunk-RNAJVXUG.js → chunk-2ZN3O5FT.js} +6 -6
  33. package/chunks/{chunk-HIXUUCGY.js → chunk-36HCNKDS.js} +1 -1
  34. package/chunks/{chunk-FGHPZGOP.js → chunk-3BTSSIJO.js} +38 -54
  35. package/chunks/{chunk-VBLAI2HA.js → chunk-3FPYT6QC.js} +0 -31
  36. package/chunks/{chunk-QB3KS3N3.js → chunk-3I7W2POO.js} +1 -1
  37. package/chunks/{chunk-QTB4VP4K.js → chunk-3KQBQ6FM.js} +136 -11
  38. package/chunks/{chunk-JO77FGNZ.js → chunk-3UXUOFO6.js} +19 -7
  39. package/chunks/{chunk-WDN64MVT.js → chunk-3XLK2QMY.js} +82 -16
  40. package/chunks/chunk-532WHF4F.js +127 -0
  41. package/chunks/{chunk-NX7ZTXFF.js → chunk-53GWJOLP.js} +1 -1
  42. package/chunks/{chunk-QQK4L3UU.js → chunk-5GLDOLNQ.js} +131 -26
  43. package/chunks/{chunk-WK7P62DV.js → chunk-5KI7ZDTB.js} +6 -6
  44. package/chunks/{chunk-ERXNTINK.js → chunk-6JACAGYH.js} +1 -1
  45. package/chunks/{chunk-CMWU6P4D.js → chunk-6W4HBUA2.js} +1 -1
  46. package/chunks/{chunk-AUTUFD5X.js → chunk-76RGWKLS.js} +1 -1
  47. package/chunks/{chunk-PDN7FJZV.js → chunk-7APZIRH3.js} +2 -2
  48. package/chunks/{chunk-WBU2PIZ5.js → chunk-7BXXIQG4.js} +16 -16
  49. package/chunks/{chunk-APXIW2TF.js → chunk-7ICHPMBQ.js} +4 -4
  50. package/chunks/{chunk-CWVZBIZJ.js → chunk-7Q2AXRDJ.js} +1 -1
  51. package/chunks/{chunk-WDVV3LRM.js → chunk-7QYWGTHB.js} +1 -1
  52. package/chunks/{chunk-RM244SCQ.js → chunk-AC6KDLH3.js} +1 -1
  53. package/chunks/{chunk-2WC3Y7YY.js → chunk-AEY27Z35.js} +401 -23
  54. package/chunks/{chunk-XDNFODER.js → chunk-AXTFYDXT.js} +1 -1
  55. package/chunks/chunk-AYEJOTIU.js +43 -0
  56. package/chunks/{chunk-ZN5TKAVR.js → chunk-BV6Q5HMY.js} +3 -3
  57. package/chunks/{chunk-TOOOLHVS.js → chunk-BWAMMKIS.js} +3 -3
  58. package/chunks/{chunk-IRGDIDGJ.js → chunk-BWQLXU37.js} +26 -19
  59. package/chunks/{process-registry-OAEG6WGC.js → chunk-BYUAT5OC.js} +1 -0
  60. package/chunks/{chunk-GOEVQADN.js → chunk-BZM5U74J.js} +287 -169
  61. package/chunks/chunk-CF5KXZZX.js +150 -0
  62. package/chunks/{chunk-TGNNLRC3.js → chunk-CJ3DHN5I.js} +1 -0
  63. package/chunks/{chunk-PFKGV6PO.js → chunk-CUEXOHQH.js} +9 -9
  64. package/chunks/chunk-CXTPVBFA.js +937 -0
  65. package/chunks/{chunk-LEAOJ43M.js → chunk-DAWWT2ID.js} +62 -59
  66. package/chunks/{chunk-CALTQWTZ.js → chunk-DLH7YIX6.js} +2 -2
  67. package/chunks/chunk-DT75RKNH.js +691 -0
  68. package/chunks/{chunk-TRWQQBVH.js → chunk-DTNV6UZY.js} +1 -1
  69. package/chunks/{chunk-3OAXF3UK.js → chunk-DYFOSJHU.js} +3080 -933
  70. package/chunks/{chunk-GSFV5RQW.js → chunk-E4UEO3XM.js} +3 -2
  71. package/chunks/{chunk-A7EFXK7P.js → chunk-E7LB57MB.js} +5 -5
  72. package/chunks/{chunk-KEPC5BOL.js → chunk-EDMXGXAK.js} +9 -9
  73. package/chunks/chunk-ELRMZTPF.js +374 -0
  74. package/chunks/chunk-ERU3SDXT.js +27 -0
  75. package/chunks/{chunk-O2FEO2CB.js → chunk-EUURTIV6.js} +18 -2
  76. package/chunks/{chunk-QFJZAY7W.js → chunk-EVTNACMT.js} +3 -3
  77. package/chunks/{chunk-4HOEU2OR.js → chunk-EWJTAP3Y.js} +1 -19
  78. package/chunks/{chunk-YQGW3M6Z.js → chunk-F42YYSCK.js} +8 -8
  79. package/chunks/{chunk-7PD7ZMX5.js → chunk-FCQJLMA2.js} +98 -5
  80. package/chunks/{chunk-4VY3ITHR.js → chunk-FN3JNDRU.js} +3 -3
  81. package/chunks/{chunk-R457KFV7.js → chunk-GCDXVPFK.js} +3 -3
  82. package/chunks/{chunk-IR6JKBAP.js → chunk-GOXQL4YH.js} +2 -2
  83. package/chunks/{chunk-YLOHCA6I.js → chunk-GSILBZLN.js} +2 -2
  84. package/chunks/{chunk-LNYV4GXX.js → chunk-GSKX53AN.js} +0 -139
  85. package/chunks/{chunk-4WMGYG3F.js → chunk-HBQ2NXOU.js} +2 -2
  86. package/chunks/{chunk-F2NYVASI.js → chunk-HBU7EKY4.js} +14 -12
  87. package/chunks/{chunk-6G4V7SE4.js → chunk-HG46TTAG.js} +1 -1
  88. package/chunks/{chunk-G5VOXCRX.js → chunk-HGAELO7B.js} +2 -2
  89. package/chunks/{chunk-FETY36NQ.js → chunk-HGEUHUEV.js} +1 -1
  90. package/chunks/{chunk-E6TI726I.js → chunk-HUXPEUFL.js} +1 -1
  91. package/chunks/{chunk-LYT2OU7D.js → chunk-IAEXTMED.js} +1 -1
  92. package/chunks/{chunk-IW6RQPQB.js → chunk-IJOS26LH.js} +1 -3
  93. package/chunks/{chunk-ORFIYTI2.js → chunk-IK2MWJP5.js} +1 -1
  94. package/chunks/{chunk-WXD7INFV.js → chunk-IL5M5NYD.js} +8 -8
  95. package/chunks/{chunk-KA5HR3G2.js → chunk-IUVIBDKU.js} +2 -2
  96. package/chunks/{chunk-5DQ4YTIZ.js → chunk-IV7GDNKC.js} +1 -1
  97. package/chunks/chunk-JL6APGBX.js +43 -0
  98. package/chunks/{chunk-N6S3NUYJ.js → chunk-JXNIF2O5.js} +1 -1
  99. package/chunks/{chunk-DAI65CMX.js → chunk-JYKWOREU.js} +1 -1
  100. package/chunks/chunk-K2OJUPOE.js +78 -0
  101. package/chunks/{chunk-KFECPHLV.js → chunk-KFZYGSJN.js} +3 -3
  102. package/chunks/{chunk-BK7D2JR6.js → chunk-KOKPXIAN.js} +3 -3
  103. package/chunks/{chunk-4I3WFI3U.js → chunk-LDVNJZGH.js} +12 -12
  104. package/chunks/{chunk-WXFCI3O5.js → chunk-LG5Y4OWO.js} +2 -2
  105. package/chunks/{chunk-3LPJ776W.js → chunk-LILGKQ4B.js} +10 -7
  106. package/chunks/{chunk-X7LFJF5D.js → chunk-LK2WUCDQ.js} +36 -84
  107. package/chunks/{chunk-7LTCFO6T.js → chunk-MF6E7FSA.js} +6 -5
  108. package/chunks/{chunk-ELD3OBPU.js → chunk-MHAADZOZ.js} +3 -3
  109. package/chunks/{chunk-4JNHNVAZ.js → chunk-MLQNSPRZ.js} +4 -4
  110. package/chunks/{chunk-NPKCVSXX.js → chunk-MOS5OAOG.js} +10 -8
  111. package/chunks/{chunk-IWABUX6T.js → chunk-MSNHNAQZ.js} +6 -6
  112. package/chunks/{chunk-HJ5UJQQL.js → chunk-N7VWZDWW.js} +1699 -1312
  113. package/chunks/{chunk-NB3NDQQK.js → chunk-NE624IVP.js} +1 -1
  114. package/chunks/{chunk-SOA4HKRJ.js → chunk-NFYEQRLG.js} +2 -2
  115. package/chunks/{chunk-G3ZUMSFS.js → chunk-NHCZJQE4.js} +6 -6
  116. package/chunks/{chunk-B25JYXZE.js → chunk-NHJKAR6E.js} +4 -4
  117. package/chunks/{chunk-ZP5XDLSA.js → chunk-NJQTG2G3.js} +12 -12
  118. package/chunks/{chunk-DARWOZY6.js → chunk-NLNQNBZ2.js} +1 -1
  119. package/chunks/{chunk-CCBTNJB4.js → chunk-NMCDMLHL.js} +27 -27
  120. package/chunks/{chunk-AO2VMS72.js → chunk-NMRCXKQ5.js} +3 -3
  121. package/chunks/{chunk-5BH2AIEY.js → chunk-NOAG7N22.js} +2 -2
  122. package/chunks/{chunk-VJJXG73H.js → chunk-NRXWJXJ4.js} +15 -0
  123. package/chunks/chunk-NUQ4GK5I.js +315 -0
  124. package/chunks/{chunk-J3VZF2AL.js → chunk-NUQVB25K.js} +2 -2
  125. package/chunks/{chunk-U6REWGVR.js → chunk-OLTN767L.js} +2 -2
  126. package/chunks/{chunk-R3JIDRUL.js → chunk-OX7IZ2G5.js} +4 -4
  127. package/chunks/{chunk-QAZ2MGYT.js → chunk-PLLIWEM3.js} +2 -2
  128. package/chunks/{chunk-KCF2436G.js → chunk-POC3YMHG.js} +4 -4
  129. package/chunks/{chunk-HZ2HUXX7.js → chunk-Q2LVVIKF.js} +1 -1
  130. package/chunks/{chunk-7NDZKE2M.js → chunk-Q5BD56BW.js} +3 -3
  131. package/chunks/{chunk-22GORRNY.js → chunk-QMUYLYT5.js} +1 -1
  132. package/chunks/{chunk-MV5DTLJV.js → chunk-R4Q2PEFV.js} +1 -1
  133. package/chunks/{chunk-GOKAOSCN.js → chunk-RLLRJJDR.js} +1 -1
  134. package/chunks/{chunk-5OZUKLL7.js → chunk-RWVD5RRY.js} +4 -4
  135. package/chunks/{chunk-ULZECEIP.js → chunk-RZHU3K6M.js} +2 -2
  136. package/chunks/{chunk-UYDQYDW2.js → chunk-S6Q6Q4P2.js} +1 -1
  137. package/chunks/{chunk-PQEISIKS.js → chunk-SAH4BD2J.js} +0 -67
  138. package/chunks/{chunk-LWX4WDFF.js → chunk-SBRX4BDI.js} +43 -15
  139. package/chunks/{chunk-TODNHE76.js → chunk-SODMFNAR.js} +5 -5
  140. package/chunks/{chunk-FAJPLSYF.js → chunk-SSGAAWLY.js} +89 -85
  141. package/chunks/{chunk-46MMBZHI.js → chunk-SYLECP23.js} +4 -4
  142. package/chunks/{chunk-6RZX2HIH.js → chunk-TBEXLLAO.js} +2 -2
  143. package/chunks/{chunk-MWIO7MF6.js → chunk-TP6FYVQT.js} +2 -0
  144. package/chunks/{chunk-HRPFBHW7.js → chunk-TPKQIA7G.js} +1 -0
  145. package/chunks/{chunk-QHLHE2OT.js → chunk-TWUKBNWM.js} +1 -1
  146. package/chunks/{chunk-H3Q3RSKZ.js → chunk-U7O65WKL.js} +1 -1
  147. package/chunks/{chunk-S5QR6CB5.js → chunk-UKMWZ5NS.js} +108 -887
  148. package/chunks/{chunk-OXR34GCD.js → chunk-UKZ45TJL.js} +1851 -34
  149. package/chunks/{chunk-CALNF3Z3.js → chunk-V2P3DOQR.js} +1 -1
  150. package/chunks/{chunk-FV4DM2M4.js → chunk-VG3Q2NC4.js} +7 -7
  151. package/chunks/{chunk-QTNCGZHQ.js → chunk-VX63RJXE.js} +9 -0
  152. package/chunks/{chunk-CRZBDVP2.js → chunk-VZUCTJ2P.js} +4 -4
  153. package/chunks/{chunk-2BMXHB6N.js → chunk-W5FIP7FC.js} +7 -7
  154. package/chunks/{chunk-7VEYUF3N.js → chunk-W5ZQMAEM.js} +1 -1
  155. package/chunks/{chunk-XQ4RDO5B.js → chunk-WBCPROWX.js} +1 -1
  156. package/chunks/{chunk-JYGIJA4W.js → chunk-X6K77VHC.js} +1 -1
  157. package/chunks/{chunk-7SVM3RP2.js → chunk-X7UJKOHZ.js} +3 -3
  158. package/chunks/{chunk-WXPPUPHM.js → chunk-XBZTAGB7.js} +1 -1
  159. package/chunks/{chunk-TRQNRP2H.js → chunk-XGYHNWL3.js} +45 -2
  160. package/chunks/{chunk-2EKVPSIJ.js → chunk-Y2MYW47X.js} +1 -1
  161. package/chunks/{chunk-OFVAS4AR.js → chunk-YBUMTY7B.js} +1 -1
  162. package/chunks/{chunk-67XTVRVB.js → chunk-YQHLFCPU.js} +7 -7
  163. package/chunks/{chunk-G37O7YO6.js → chunk-Z3GF56ME.js} +2 -2
  164. package/chunks/{chunk-XBVNNDPK.js → chunk-ZHKTKHMO.js} +8 -1
  165. package/chunks/{chunk-OWCFKIFQ.js → chunk-ZKYR7QS4.js} +1 -1
  166. package/chunks/{chunk-YZTGGCEE.js → chunk-ZKZHSB5W.js} +1 -1
  167. package/chunks/{chunk-565U2ANU.js → chunk-ZTTC7T4X.js} +1 -1
  168. package/chunks/{chunk-XSOXPG2L.js → chunk-ZU47FBOC.js} +36 -7
  169. package/chunks/{chunk-7OCIQNKX.js → chunk-ZW2EUO2A.js} +1 -1
  170. package/chunks/{config-utils-GPLIABL2.js → config-utils-L6KLDYIV.js} +62 -55
  171. package/chunks/{contextCommand-NCUQUDBY.js → contextCommand-UYEH7NIU.js} +59 -52
  172. package/chunks/{core-runtime-WKYKWVYU.js → core-runtime-NVHT3Z3V.js} +61 -54
  173. package/chunks/{create-sub-session-TGIX63YU.js → create-sub-session-TIGCFGCS.js} +2 -2
  174. package/chunks/{create-sub-session-PPLXB3JJ.js → create-sub-session-YWASE5VH.js} +59 -52
  175. package/chunks/{cron-create-GTPVMJCF.js → cron-create-AKWX67FO.js} +1 -1
  176. package/chunks/{cron-delete-ZBK27Z4K.js → cron-delete-XPB6IYZJ.js} +1 -1
  177. package/chunks/{cron-list-KTFKFDKC.js → cron-list-XBKO4WU5.js} +1 -1
  178. package/chunks/{daemon-2CKIAO3I.js → daemon-G5TYKZD6.js} +2 -2
  179. package/chunks/{daemon-git-worktree-guard-73ZWOLKL.js → daemon-git-worktree-guard-FOW4RQSK.js} +60 -53
  180. package/chunks/{daemon-status-provider-OK7VONJG.js → daemon-status-provider-O5KQZYMP.js} +67 -60
  181. package/chunks/{daemon-trust-policy-CAUCREG2.js → daemon-trust-policy-3ATXEON7.js} +64 -57
  182. package/chunks/{daemon-trust-policy-monitor-3Y36OOEQ.js → daemon-trust-policy-monitor-7MCNDNEC.js} +64 -57
  183. package/chunks/{deferred-core-runtime-Q7WFWYD3.js → deferred-core-runtime-JK5IXL5K.js} +57 -50
  184. package/chunks/{display-image-CTNHJRZC.js → display-image-NAH3AZ63.js} +3 -3
  185. package/chunks/{dist-NP7QKLVG.js → dist-AHJYPSJL.js} +3 -3
  186. package/chunks/{dist-6YDUH3BB.js → dist-AIKC5E5P.js} +2 -2
  187. package/chunks/{dist-Y5KC3IHW.js → dist-F2DVGTL3.js} +225 -6
  188. package/chunks/{dist-BNQVF565.js → dist-GWNQVPZT.js} +5 -5
  189. package/chunks/{dist-F6JLAJLE.js → dist-H6G3K26N.js} +3 -3
  190. package/chunks/{dist-ZDNJK74R.js → dist-KJGRVIGJ.js} +2 -2
  191. package/chunks/{dist-F34J4FZX.js → dist-KLZ7XGEQ.js} +2 -2
  192. package/chunks/{dist-UFTFGI6I.js → dist-ZA52JXAS.js} +2 -2
  193. package/chunks/{dist-XLV33CLY.js → dist-ZXTZTE54.js} +2 -2
  194. package/chunks/{edit-YJD6IETK.js → edit-SY35KYIE.js} +45 -39
  195. package/chunks/{en-YJNRUQG4.js → en-CAJHTIQT.js} +1 -0
  196. package/chunks/{enter-worktree-YFTKHXHZ.js → enter-worktree-54L5QJ3N.js} +4 -4
  197. package/chunks/{enterPlanMode-EFPVTWIH.js → enterPlanMode-HXX6KQJR.js} +42 -36
  198. package/chunks/{environment-HP3AXFTB.js → environment-DKXHG4HB.js} +60 -53
  199. package/chunks/{errors-22ON46G7.js → errors-ADY7LQJJ.js} +59 -52
  200. package/chunks/{exit-worktree-NF2XEMES.js → exit-worktree-EORJDKDS.js} +4 -4
  201. package/chunks/{exitPlanMode-MOQUNCBH.js → exitPlanMode-HSK2CQI6.js} +42 -36
  202. package/chunks/{fast-path-2X7BPMXX.js → fast-path-U636VWN2.js} +6 -6
  203. package/chunks/{fast-path-settings-SATXY3PD.js → fast-path-settings-V7MI7EZJ.js} +2 -2
  204. package/chunks/{glob-Y7ACIB3P.js → glob-GUGGTH5L.js} +45 -39
  205. package/chunks/{goal-tools-DABMICUC.js → goal-tools-PXYRSQGX.js} +42 -36
  206. package/chunks/{grep-BLHF2S5D.js → grep-3PKFKLCA.js} +2 -2
  207. package/chunks/{handleAutoUpdate-MCAMHYDI.js → handleAutoUpdate-5KHS4HIN.js} +60 -53
  208. package/chunks/{i18n-C3GDCALP.js → i18n-KSGKMUPT.js} +58 -51
  209. package/chunks/{image-gen-XP4NNIYG.js → image-gen-OCCR2WWU.js} +5 -4
  210. package/chunks/{initializer-4URDQL2G.js → initializer-YYT5XEZF.js} +64 -57
  211. package/chunks/{installationInfo-LBOL6SBV.js → installationInfo-UNSBPYW2.js} +57 -50
  212. package/chunks/{list-JOGBAC2R.js → list-YL6LDQKQ.js} +67 -60
  213. package/chunks/{list-agents-2CXPGJUE.js → list-agents-QLDXS5OD.js} +17 -7
  214. package/chunks/{llm-2KPNSAVY.js → llm-XGGLBGPH.js} +126 -119
  215. package/chunks/{llm-content-generator-GR3FOHLB.js → llm-content-generator-ZHQQT5W7.js} +5 -4
  216. package/chunks/{loadedSettingsAdapter-DVKROEJD.js → loadedSettingsAdapter-3DXLASK7.js} +64 -57
  217. package/chunks/{loggingContentGenerator-P4K6K5W4.js → loggingContentGenerator-V72OCCJO.js} +64 -57
  218. package/chunks/{loop-wakeup-HL6XOWI4.js → loop-wakeup-HHMYIC7Z.js} +2 -2
  219. package/chunks/{ls-YV7RKLKY.js → ls-N7ABR6HI.js} +4 -4
  220. package/chunks/{lsp-NO3AMRZT.js → lsp-LTOFWG5P.js} +1 -1
  221. package/chunks/{managed-npm-update-VWBKHNIN.js → managed-npm-update-HV5LPZH2.js} +57 -50
  222. package/chunks/{mcp-6YYNSYLK.js → mcp-IYVSIW6O.js} +64 -57
  223. package/chunks/{monitor-A255TNZR.js → monitor-TLBNM4MV.js} +44 -38
  224. package/chunks/{nonInteractiveCli-LXGIKQAT.js → nonInteractiveCli-LSJSQ2W4.js} +110 -103
  225. package/chunks/{notebook-edit-5UYHS2DM.js → notebook-edit-OSPOLZP6.js} +43 -37
  226. package/chunks/openai-WX26N5OJ.js +47 -0
  227. package/chunks/{openaiContentGenerator-A6MAMEO5.js → openaiContentGenerator-BE4S5TRD.js} +29 -23
  228. package/chunks/openaiResponsesContentGenerator-RTCAJ5V5.js +1658 -0
  229. package/chunks/{pidfile-B7DZC4TP.js → pidfile-H32FEPWA.js} +57 -50
  230. package/chunks/process-registry-X6ZCASEN.js +10 -0
  231. package/chunks/{processUtils-BPZ2MCZS.js → processUtils-SSLIPDEA.js} +2 -2
  232. package/chunks/{prompt-terminal-ledger-FYYTAOXS.js → prompt-terminal-ledger-I5SLL6UF.js} +58 -51
  233. package/chunks/{qwenContentGenerator-4IOJFD4S.js → qwenContentGenerator-TMQC623Z.js} +55 -47
  234. package/chunks/{qwenOAuth2-KX6LVYQ3.js → qwenOAuth2-3ZRQHHTC.js} +4 -3
  235. package/chunks/{read-file-A4H4O3VQ.js → read-file-T2QAIZE2.js} +11 -9
  236. package/chunks/{read-mcp-resource-D3N75DGF.js → read-mcp-resource-B37WANAQ.js} +1 -1
  237. package/chunks/{record-artifact-Q5CRGJTP.js → record-artifact-OAXWXZ5D.js} +2 -2
  238. package/chunks/record-source-D7R7X3GT.js +22 -0
  239. package/chunks/{report-findings-TJ34R7QK.js → report-findings-AR3VC6EQ.js} +3 -3
  240. package/chunks/{request-shutdown-LRKMTBAD.js → request-shutdown-IKNWTX5M.js} +5 -5
  241. package/chunks/{resumeHistoryUtils-YQQ43E4N.js → resumeHistoryUtils-QLKDH5GY.js} +63 -56
  242. package/chunks/{ripGrep-W32NWFTA.js → ripGrep-YGWL7KCV.js} +15 -13
  243. package/chunks/{run-qwen-serve-WBSWWIRV.js → run-qwen-serve-26KZDECC.js} +127 -102
  244. package/chunks/{runtime-VRVBX2E5.js → runtime-BMEIVDDG.js} +70 -63
  245. package/chunks/{scheduled-tasks-D65KJDA3.js → scheduled-tasks-NCFPP6VQ.js} +64 -57
  246. package/chunks/{scheduler-M2YPN7Z7.js → scheduler-47TVMUVN.js} +59 -52
  247. package/chunks/{sdk-exporters-grpc-MXTVSE3C.js → sdk-exporters-grpc-Y2ZUQDUQ.js} +2 -2
  248. package/chunks/{sdk-exporters-http-7R2ARBPV.js → sdk-exporters-http-VWTF4W6K.js} +3 -3
  249. package/chunks/{sdk-impl-YOLO7LV4.js → sdk-impl-G6FVTBQZ.js} +9 -9
  250. package/chunks/{send-message-76BKWKFZ.js → send-message-TWOGWCBG.js} +12 -9
  251. package/chunks/{serve-BE3H2P6P.js → serve-KL3G6LQQ.js} +64 -57
  252. package/chunks/{server-FLY5JERG.js → server-LBPYXZ5G.js} +2931 -518
  253. package/chunks/{session-JVN62R5K.js → session-YG6742LO.js} +118 -111
  254. package/chunks/{session-attachments-root-7ACGLHXA.js → session-attachments-root-OUBQDYC4.js} +57 -50
  255. package/chunks/{session-pr-refresh-TQS57SDK.js → session-pr-refresh-EKGMYNAW.js} +64 -57
  256. package/chunks/{settings-D44YMZFT.js → settings-DDNHJX2L.js} +69 -62
  257. package/chunks/{shell-3VE6I4V5.js → shell-KUCXWITU.js} +42 -36
  258. package/chunks/{skill-FHEGRRZU.js → skill-JQLKPNWZ.js} +33 -23
  259. package/chunks/{skill-settings-VHEJMBFL.js → skill-settings-XERQCUXZ.js} +63 -56
  260. package/chunks/{spawnChannel-T6MX2ZDN.js → spawnChannel-GQ45QFGB.js} +60 -53
  261. package/chunks/{standalone-update-QUGHFMCS.js → standalone-update-PRF3ILGZ.js} +59 -52
  262. package/chunks/{start-opentui-ui-IHIIZ2LE.js → start-opentui-ui-JDSOZE3N.js} +174 -157
  263. package/chunks/{startInteractiveUI-LR7K2ARZ.js → startInteractiveUI-RRW3JVHN.js} +533 -1119
  264. package/chunks/{syntheticOutput-D2P5V6RG.js → syntheticOutput-F6F27JMK.js} +2 -2
  265. package/chunks/{task-create-MWXJFRRM.js → task-create-Y623TBHB.js} +8 -8
  266. package/chunks/{task-list-EYO3FE57.js → task-list-FCPEEGWL.js} +1 -1
  267. package/chunks/{task-stop-BFSKRTGV.js → task-stop-QTKZXLPH.js} +1 -1
  268. package/chunks/{task-update-2JJJRHMT.js → task-update-YLSXF25N.js} +8 -8
  269. package/chunks/{team-create-GY3VFY47.js → team-create-5DRLOLOE.js} +44 -38
  270. package/chunks/{team-delete-IQZ6XGFI.js → team-delete-S7TLHZCF.js} +1 -1
  271. package/chunks/{team-plan-approval-BQPGZOT5.js → team-plan-approval-MWSGAL5T.js} +42 -36
  272. package/chunks/{terminal-image-renderer-YNYW5CQG.js → terminal-image-renderer-H7PD4FQW.js} +59 -52
  273. package/chunks/{theme-manager-U6CIK3GM.js → theme-manager-7AV73D6R.js} +57 -50
  274. package/chunks/{todoWrite-5ERKFWAK.js → todoWrite-5QI2H2FW.js} +4 -4
  275. package/chunks/{tool-search-XI3QWD5I.js → tool-search-UGYTBLUV.js} +17 -15
  276. package/chunks/{total-session-admission-3SNSJJ32.js → total-session-admission-JIHSTJ5S.js} +62 -55
  277. package/chunks/{trustedFolders-OVAQKNV5.js → trustedFolders-5VCBXFOP.js} +58 -51
  278. package/chunks/{update-relaunch-XV5O74E3.js → update-relaunch-4LF3APCV.js} +5 -5
  279. package/chunks/{updateCheck-CHUYWD6L.js → updateCheck-4T3WUE5F.js} +59 -52
  280. package/chunks/{useAutoAcceptIndicator-VKSVIXZC.js → useAutoAcceptIndicator-UMGB64Z6.js} +67 -60
  281. package/chunks/{validateNonInterActiveAuth-ZNUTD3E5.js → validateNonInterActiveAuth-GFJ72U2C.js} +107 -100
  282. package/chunks/{version-EK7VAGSI.js → version-EAAZN4T2.js} +1 -1
  283. package/chunks/{web-fetch-24KZO763.js → web-fetch-VRU3A2NI.js} +13 -11
  284. package/chunks/{web-search-CRNXKZ2X.js → web-search-NEGYQNDJ.js} +14 -10
  285. package/chunks/{web-shell-static-BFDESDD4.js → web-shell-static-CCN4JZEE.js} +1 -1
  286. package/chunks/workflow-UHPFALVZ.js +1224 -0
  287. package/chunks/{workspace-providers-status-MAM42IZS.js → workspace-providers-status-AEYISSU2.js} +68 -61
  288. package/chunks/{workspace-registration-store-HKLJEDQX.js → workspace-registration-store-A7RGKW62.js} +3 -1
  289. package/chunks/{workspace-registry-7RDDOBLN.js → workspace-registry-C2NGE6SD.js} +62 -55
  290. package/chunks/{workspace-runtime-coordinator-LEPDPXJO.js → workspace-runtime-coordinator-QKMZ24YF.js} +63 -56
  291. package/chunks/{workspace-service-5IFDCNN3.js → workspace-service-RQTTAGGC.js} +70 -63
  292. package/chunks/{workspace-skills-status-FJ3HNH4H.js → workspace-skills-status-5HWZU3HX.js} +65 -58
  293. package/chunks/{workspace-trust-reconciler-PQFHIWLR.js → workspace-trust-reconciler-KFWATZUU.js} +69 -62
  294. package/chunks/{write-file-ERG67ZFX.js → write-file-DPVB2SBQ.js} +44 -38
  295. package/chunks/{zh-VBFCRQBL.js → zh-S5V3Z5CR.js} +1 -0
  296. package/chunks/{zh-TW-N2TBF2F2.js → zh-TW-2K2WRFPY.js} +1 -0
  297. package/chunks/{zoom-image-WQYEC3SR.js → zoom-image-S7AWLAPC.js} +12 -10
  298. package/cli.js +13 -13
  299. package/export-transcript-document.css +1 -0
  300. package/export-transcript-document.js +164 -165
  301. package/locales/en.js +1 -0
  302. package/locales/zh-TW.js +1 -0
  303. package/locales/zh.js +1 -0
  304. package/package.json +5 -4
  305. package/web-shell/assets/{abnfDiagram-VCTEODGH-BRLgQbnT.js → abnfDiagram-VCTEODGH-nU24rpIE.js} +1 -1
  306. package/web-shell/assets/{arc-qAF9_XsR.js → arc-D1hTu8QI.js} +1 -1
  307. package/web-shell/assets/{architectureDiagram-5GKGNRK7-BorUttEz.js → architectureDiagram-5GKGNRK7-B_fgkKe7.js} +1 -1
  308. package/web-shell/assets/{blockDiagram-NRAW4CY4-Bj0qZVxu.js → blockDiagram-NRAW4CY4-C3pddUNg.js} +1 -1
  309. package/web-shell/assets/{c4Diagram-UCG6FXSJ-BTqJis32.js → c4Diagram-UCG6FXSJ-kEFoC1ei.js} +1 -1
  310. package/web-shell/assets/channel-Blod4z1X.js +1 -0
  311. package/web-shell/assets/{chunk-2Q5K7J3B-RrQ5X8m-.js → chunk-2Q5K7J3B-DbT9wS7j.js} +1 -1
  312. package/web-shell/assets/{chunk-5VM5RSS4-uUjDl8wO.js → chunk-5VM5RSS4-CNbULt6O.js} +1 -1
  313. package/web-shell/assets/{chunk-F27PBJKO-C3JhpyzI.js → chunk-F27PBJKO-CbQRy4Tb.js} +1 -1
  314. package/web-shell/assets/{chunk-G27WJ6UU-C8ZNFs7F.js → chunk-G27WJ6UU-CVbXTxYk.js} +1 -1
  315. package/web-shell/assets/{chunk-JWPE2WC7-DNpXtEOs.js → chunk-JWPE2WC7-D89c_BXy.js} +1 -1
  316. package/web-shell/assets/{chunk-LCL6LL3I-DagA2ZLw.js → chunk-LCL6LL3I-B7-I_9KB.js} +1 -1
  317. package/web-shell/assets/{chunk-POPQ4Y6H-R23uH7Xm.js → chunk-POPQ4Y6H-DcLQFzS4.js} +1 -1
  318. package/web-shell/assets/{chunk-SVP7TREG-Qz9RN_BR.js → chunk-SVP7TREG-DyBb2Axj.js} +1 -1
  319. package/web-shell/assets/{chunk-XXDRQBXY-jYb1_hni.js → chunk-XXDRQBXY-BIA0eb5B.js} +1 -1
  320. package/web-shell/assets/classDiagram-DTDB5LWJ-D6hFDMqb.js +1 -0
  321. package/web-shell/assets/classDiagram-v2-JRS7N3AN-D6hFDMqb.js +1 -0
  322. package/web-shell/assets/{cose-bilkent-JH36ORCC-Cv2OunpE.js → cose-bilkent-JH36ORCC-Db2FYN85.js} +1 -1
  323. package/web-shell/assets/{cynefin-OW5HDTMX-LH42KFJx.js → cynefin-OW5HDTMX-i4GwmBVy.js} +1 -1
  324. package/web-shell/assets/{cynefinDiagram-5FMLGOSQ-Dha4_OoR.js → cynefinDiagram-5FMLGOSQ-LENf_IUy.js} +1 -1
  325. package/web-shell/assets/{dagre-3AP2YEHR-Br5lnUKD.js → dagre-3AP2YEHR-CF9XVrD9.js} +1 -1
  326. package/web-shell/assets/{diagram-S7CK7UJ4-dpKq2bBX.js → diagram-S7CK7UJ4-DD5PJfSm.js} +1 -1
  327. package/web-shell/assets/{diagram-UQ7AKVKN-BAgHWpXr.js → diagram-UQ7AKVKN-CjD_sBMj.js} +1 -1
  328. package/web-shell/assets/{diagram-VSXAHHWV-GRRzpyE2.js → diagram-VSXAHHWV-U5WwMqyA.js} +1 -1
  329. package/web-shell/assets/{diagram-VX7I27RA-BNFiaYpG.js → diagram-VX7I27RA-BujpHJJf.js} +1 -1
  330. package/web-shell/assets/{diagram-Z3DM3KII-BisZzB_h.js → diagram-Z3DM3KII-3ZLtKEXo.js} +1 -1
  331. package/web-shell/assets/{ebnfDiagram-PWID7BFC-B1xbwycf.js → ebnfDiagram-PWID7BFC-BGpiquRm.js} +1 -1
  332. package/web-shell/assets/{erDiagram-SSCWMZ5O-CQMzbGE5.js → erDiagram-SSCWMZ5O-D0besu_U.js} +1 -1
  333. package/web-shell/assets/{flowDiagram-A5DVABFB-CZ_Zondl.js → flowDiagram-A5DVABFB-9DwDuIyr.js} +1 -1
  334. package/web-shell/assets/{ganttDiagram-EL5Y4UJY-BTh2ShxS.js → ganttDiagram-EL5Y4UJY-CNlsAeNr.js} +1 -1
  335. package/web-shell/assets/{gitGraphDiagram-WWUBYQGX-oHOB-Uxt.js → gitGraphDiagram-WWUBYQGX-C_pPFiTR.js} +1 -1
  336. package/web-shell/assets/{index-DWoFMu5x.js → index-BYWs4JWq.js} +1 -1
  337. package/web-shell/assets/index-D3YS6KuJ.js +2173 -0
  338. package/web-shell/assets/index-eBxK3rs2.css +36 -0
  339. package/web-shell/assets/{infoDiagram-RXCK75RN-C0QpudbG.js → infoDiagram-RXCK75RN-Bpai64Ll.js} +1 -1
  340. package/web-shell/assets/{ishikawaDiagram-5VMMS53U-a6B741uT.js → ishikawaDiagram-5VMMS53U-ktpJFq4r.js} +1 -1
  341. package/web-shell/assets/{journeyDiagram-EYS64GPL-Dbht9ICp.js → journeyDiagram-EYS64GPL-iz_DKgFX.js} +1 -1
  342. package/web-shell/assets/{kanban-definition-3QL26DDD-D4OFR8-h.js → kanban-definition-3QL26DDD-m_gG00Yt.js} +1 -1
  343. package/web-shell/assets/{layout-Dvdh5jRH.js → layout-qEvKgnvU.js} +1 -1
  344. package/web-shell/assets/{linear-Dvc6KIW2.js → linear-C6lklGdq.js} +1 -1
  345. package/web-shell/assets/{mermaid.core-CB36RfIb.js → mermaid.core-DSCYB_2P.js} +6 -6
  346. package/web-shell/assets/{mindmap-definition-FBJOCRG2-Fmqo1CjP.js → mindmap-definition-FBJOCRG2-DRQbT8w-.js} +1 -1
  347. package/web-shell/assets/{pegDiagram-XKGWAZYB-CCxYBoA4.js → pegDiagram-XKGWAZYB-BhD0q0i6.js} +1 -1
  348. package/web-shell/assets/{pieDiagram-E7YTZNPT-BVHKQFzt.js → pieDiagram-E7YTZNPT-BvIGQCSd.js} +1 -1
  349. package/web-shell/assets/{quadrantDiagram-AXDQQJYC-l95IznwR.js → quadrantDiagram-AXDQQJYC-BDQtfpU-.js} +1 -1
  350. package/web-shell/assets/{railroadDiagram-O6MQD6OU-BlLdRdXp.js → railroadDiagram-O6MQD6OU-E1g2KIFK.js} +1 -1
  351. package/web-shell/assets/{requirementDiagram-EFPCY7ZU-BkDLBR5w.js → requirementDiagram-EFPCY7ZU-CuerYJOe.js} +1 -1
  352. package/web-shell/assets/{sankeyDiagram-P5KCCOFB-jAIqRp65.js → sankeyDiagram-P5KCCOFB-CqWyCZGA.js} +1 -1
  353. package/web-shell/assets/{sequenceDiagram-WJ2MYXX4-f-soZYPr.js → sequenceDiagram-WJ2MYXX4-B-YWb8x4.js} +1 -1
  354. package/web-shell/assets/{sizeCapture-X5ZJPWSS-BzOuAfB2.js → sizeCapture-X5ZJPWSS-BB7YY4Tl.js} +1 -1
  355. package/web-shell/assets/{stateDiagram-HBIQ2CUA-BPLSs12r.js → stateDiagram-HBIQ2CUA-C8LDpNHS.js} +1 -1
  356. package/web-shell/assets/stateDiagram-v2-4QOOHH4V-C4CbdvGa.js +1 -0
  357. package/web-shell/assets/{swimlanes-XN3QIQJK-D-9E_RIR.js → swimlanes-XN3QIQJK-D94vOoxZ.js} +1 -1
  358. package/web-shell/assets/swimlanesDiagram-VK2B7HYN--QNSIOC8.js +8 -0
  359. package/web-shell/assets/{timeline-definition-24CTP7MA-CT56K-gV.js → timeline-definition-24CTP7MA-C9C8uEYm.js} +1 -1
  360. package/web-shell/assets/{vennDiagram-4TSXK5OY-B-vi4IyO.js → vennDiagram-4TSXK5OY-CYzMHbVW.js} +1 -1
  361. package/web-shell/assets/{wardleyDiagram-VM6X3IG4-C9O7Ju98.js → wardleyDiagram-VM6X3IG4-G9nhtLES.js} +1 -1
  362. package/web-shell/assets/{xychartDiagram-S5SC5T6Z-6d8w3jg2.js → xychartDiagram-S5SC5T6Z-ruD2Wjhg.js} +1 -1
  363. package/web-shell/index.html +29 -5
  364. package/chunks/chunk-V7RNNPGC.js +0 -44
  365. package/chunks/workflow-HD5NYMW5.js +0 -2907
  366. package/web-shell/assets/channel-COIuCrVH.js +0 -1
  367. package/web-shell/assets/classDiagram-DTDB5LWJ-DoX6OYqu.js +0 -1
  368. package/web-shell/assets/classDiagram-v2-JRS7N3AN-DoX6OYqu.js +0 -1
  369. package/web-shell/assets/index-CI1ysIEv.js +0 -2154
  370. package/web-shell/assets/index-CpxXGH-8.css +0 -36
  371. package/web-shell/assets/stateDiagram-v2-4QOOHH4V-IRul-LaT.js +0 -1
  372. package/web-shell/assets/swimlanesDiagram-VK2B7HYN-D6lgKepA.js +0 -8
  373. /package/chunks/{chunk-JA5CBKRP.js → chunk-7NXSVSFB.js} +0 -0
@@ -0,0 +1,1658 @@
1
+ // Force strict mode and setup for ESM
2
+ "use strict";
3
+ import {
4
+ sanitizeMimeForPlaceholder
5
+ } from "./chunk-NUQ4GK5I.js";
6
+ import {
7
+ extractTextFromContents
8
+ } from "./chunk-AYEJOTIU.js";
9
+ import {
10
+ createOpenAIReasoningThoughtPart
11
+ } from "./chunk-K2OJUPOE.js";
12
+ import {
13
+ safeJsonParse,
14
+ setGenAiUsageProvenance
15
+ } from "./chunk-GSKX53AN.js";
16
+ import {
17
+ DEFAULT_MAX_RETRIES,
18
+ DEFAULT_STREAM_IDLE_TIMEOUT_MS,
19
+ DEFAULT_STREAM_MAX_LIFETIME_MS,
20
+ DISABLED_REQUEST_TIMEOUT_MS,
21
+ MAX_STREAM_GUARD_TIMEOUT_MS,
22
+ QWEN_STREAM_IDLE_TIMEOUT_MS_ENV,
23
+ QWEN_STREAM_MAX_LIFETIME_MS_ENV,
24
+ resolveRequestTimeout
25
+ } from "./chunk-JL6APGBX.js";
26
+ import {
27
+ reconcileMaxTokens
28
+ } from "./chunk-FPGTNKCP.js";
29
+ import {
30
+ buildRuntimeFetchOptions,
31
+ redactProxyCredentials,
32
+ redactProxyError
33
+ } from "./chunk-EWJTAP3Y.js";
34
+ import {
35
+ createDebugLogger
36
+ } from "./chunk-ZAFYHRVY.js";
37
+ import "./chunk-TBWQLLFO.js";
38
+ import {
39
+ FinishReason,
40
+ GenerateContentResponse
41
+ } from "./chunk-EFT7OMDN.js";
42
+ import "./chunk-MATEIJZF.js";
43
+ import "./chunk-J5TTWBZK.js";
44
+ import "./chunk-RVIGZBIT.js";
45
+ import {
46
+ init_esbuild_shims
47
+ } from "./chunk-5O2XNYP6.js";
48
+ import {
49
+ __name
50
+ } from "./chunk-J2S4EL5Y.js";
51
+
52
+ // packages/core/src/core/openaiResponsesContentGenerator/index.ts
53
+ init_esbuild_shims();
54
+
55
+ // packages/core/src/core/openaiResponsesContentGenerator/responses-pipeline.ts
56
+ init_esbuild_shims();
57
+
58
+ // packages/core/src/core/openaiResponsesContentGenerator/responses-converter.ts
59
+ init_esbuild_shims();
60
+ var debugLogger = createDebugLogger("RESPONSES_CONVERTER");
61
+ var SUPPORTED_RESPONSE_IMAGE_MIME_TYPES = /* @__PURE__ */ new Set([
62
+ "image/jpeg",
63
+ "image/png",
64
+ "image/webp",
65
+ "image/gif"
66
+ ]);
67
+ function isSupportedResponseImageMime(mimeType) {
68
+ return mimeType !== void 0 && SUPPORTED_RESPONSE_IMAGE_MIME_TYPES.has(mimeType);
69
+ }
70
+ __name(isSupportedResponseImageMime, "isSupportedResponseImageMime");
71
+ function placeholderMimeType(mimeType) {
72
+ const sanitized = mimeType ? sanitizeMimeForPlaceholder(mimeType) : "";
73
+ return sanitized || "unknown mime type";
74
+ }
75
+ __name(placeholderMimeType, "placeholderMimeType");
76
+ var RESPONSES_ERROR_CODE_TO_STATUS = {
77
+ server_error: 500,
78
+ rate_limit_exceeded: 429
79
+ };
80
+ function makeResponsesStreamError(message, code, type) {
81
+ const err = new Error(message);
82
+ err.type = type ?? code;
83
+ if (code) {
84
+ err.code = code;
85
+ const status = RESPONSES_ERROR_CODE_TO_STATUS[code];
86
+ if (status !== void 0) err.status = status;
87
+ }
88
+ return err;
89
+ }
90
+ __name(makeResponsesStreamError, "makeResponsesStreamError");
91
+ function encodeReasoningSignature(payload) {
92
+ return JSON.stringify(payload);
93
+ }
94
+ __name(encodeReasoningSignature, "encodeReasoningSignature");
95
+ function decodeReasoningSignature(signature) {
96
+ if (!signature) return void 0;
97
+ try {
98
+ const parsed = JSON.parse(signature);
99
+ if (typeof parsed.id === "string" && typeof parsed.encrypted_content === "string") {
100
+ return { id: parsed.id, encrypted_content: parsed.encrypted_content };
101
+ }
102
+ } catch {
103
+ }
104
+ return void 0;
105
+ }
106
+ __name(decodeReasoningSignature, "decodeReasoningSignature");
107
+ var ResponsesStreamState = class {
108
+ static {
109
+ __name(this, "ResponsesStreamState");
110
+ }
111
+ responseId = null;
112
+ funcCallArgs = /* @__PURE__ */ new Map();
113
+ getFunctionCallBuffer(outputIndex) {
114
+ return this.funcCallArgs.get(outputIndex);
115
+ }
116
+ initFunctionCall(outputIndex, _id, callId, name) {
117
+ this.funcCallArgs.set(outputIndex, { id: callId, name, args: "" });
118
+ }
119
+ appendFunctionCallArgs(outputIndex, delta) {
120
+ const buf = this.funcCallArgs.get(outputIndex);
121
+ if (buf) buf.args += delta;
122
+ }
123
+ };
124
+ function convertResponsesEventToGemini(event, model, state) {
125
+ switch (event.event) {
126
+ case "response.created": {
127
+ const raw = event.data;
128
+ const envelope = raw["response"] ?? raw;
129
+ if (envelope.id) {
130
+ state.responseId = envelope.id;
131
+ }
132
+ return null;
133
+ }
134
+ case "response.in_progress":
135
+ return null;
136
+ case "response.output_item.added": {
137
+ const data = event.data;
138
+ if (data.item.type === "function_call") {
139
+ const fc = data.item;
140
+ state.initFunctionCall(data.output_index, fc.id, fc.call_id, fc.name);
141
+ }
142
+ return null;
143
+ }
144
+ case "response.output_text.delta": {
145
+ const data = event.data;
146
+ return makeChunkResponse(model, state, [{ text: data.delta }]);
147
+ }
148
+ case "response.refusal.delta": {
149
+ const data = event.data;
150
+ return makeChunkResponse(model, state, [{ text: data.delta }]);
151
+ }
152
+ case "response.refusal.done":
153
+ return null;
154
+ case "response.reasoning_text.delta": {
155
+ const data = event.data;
156
+ return makeChunkResponse(model, state, [
157
+ createOpenAIReasoningThoughtPart(data.delta)
158
+ ]);
159
+ }
160
+ case "response.reasoning_summary_text.delta": {
161
+ const data = event.data;
162
+ return makeChunkResponse(model, state, [
163
+ { text: data.delta, thought: true }
164
+ ]);
165
+ }
166
+ case "response.function_call_arguments.delta": {
167
+ const data = event.data;
168
+ state.appendFunctionCallArgs(data.output_index, data.delta);
169
+ return null;
170
+ }
171
+ case "response.output_item.done": {
172
+ const data = event.data;
173
+ if (data.item.type === "function_call") {
174
+ const fc = data.item;
175
+ const buf = state.getFunctionCallBuffer(data.output_index);
176
+ const id = buf?.id ?? fc.call_id;
177
+ const name = buf?.name ?? fc.name;
178
+ const rawArgs = buf?.args || fc.arguments;
179
+ let args = {};
180
+ try {
181
+ args = JSON.parse(rawArgs);
182
+ } catch {
183
+ const authoritative = fc.arguments && fc.arguments !== rawArgs ? fc.arguments : rawArgs;
184
+ args = safeJsonParse(authoritative, {});
185
+ }
186
+ if (typeof args !== "object" || args === null || Array.isArray(args)) {
187
+ const authoritative = fc.arguments && fc.arguments !== rawArgs ? safeJsonParse(fc.arguments, void 0) : void 0;
188
+ args = authoritative && typeof authoritative === "object" && !Array.isArray(authoritative) ? authoritative : {};
189
+ }
190
+ return makeChunkResponse(model, state, [
191
+ {
192
+ functionCall: {
193
+ id,
194
+ name,
195
+ args
196
+ }
197
+ }
198
+ ]);
199
+ }
200
+ if (data.item.type === "reasoning") {
201
+ const reasoningItem = data.item;
202
+ const encryptedContent = reasoningItem.encrypted_content;
203
+ if (!encryptedContent) return null;
204
+ return makeChunkResponse(model, state, [
205
+ {
206
+ thought: true,
207
+ thoughtSignature: encodeReasoningSignature({
208
+ id: reasoningItem.id,
209
+ encrypted_content: encryptedContent
210
+ })
211
+ }
212
+ ]);
213
+ }
214
+ return null;
215
+ }
216
+ case "response.completed": {
217
+ const raw = event.data;
218
+ const envelope = raw["response"] ?? raw;
219
+ if (envelope.id) state.responseId = envelope.id;
220
+ return makeFinalResponse(model, state, envelope.usage, "stop");
221
+ }
222
+ case "response.failed": {
223
+ const raw = event.data;
224
+ const envelope = raw["response"] ?? raw;
225
+ const errMsg = envelope.error ? `${envelope.error.code}: ${envelope.error.message}` : "Response failed";
226
+ throw makeResponsesStreamError(
227
+ `Responses API failed: ${errMsg}`,
228
+ envelope.error?.code,
229
+ envelope.error?.type
230
+ );
231
+ }
232
+ case "response.incomplete": {
233
+ const raw = event.data;
234
+ const envelope = raw["response"] ?? raw;
235
+ if (envelope.id) state.responseId = envelope.id;
236
+ return makeFinalResponse(
237
+ model,
238
+ state,
239
+ envelope.usage,
240
+ envelope.incomplete_details?.reason ?? "max_output_tokens"
241
+ );
242
+ }
243
+ case "error": {
244
+ const data = event.data;
245
+ const code = data.error?.code ?? data.code;
246
+ const message = data.error?.message ?? data.message;
247
+ const detail = [code, message].filter(Boolean).join(": ") || data.error?.type || "Unknown error";
248
+ throw makeResponsesStreamError(
249
+ `Responses API error: ${detail}`,
250
+ code,
251
+ data.error?.type
252
+ );
253
+ }
254
+ default:
255
+ return null;
256
+ }
257
+ }
258
+ __name(convertResponsesEventToGemini, "convertResponsesEventToGemini");
259
+ function makeChunkResponse(model, state, parts, finishReason) {
260
+ const candidate = {
261
+ content: { parts, role: "model" },
262
+ index: 0,
263
+ safetyRatings: []
264
+ };
265
+ if (finishReason) {
266
+ candidate.finishReason = mapFinishReason(finishReason);
267
+ }
268
+ const resp = new GenerateContentResponse();
269
+ resp.candidates = [candidate];
270
+ resp.responseId = state.responseId ?? void 0;
271
+ resp.modelVersion = model;
272
+ resp.createTime = Date.now().toString();
273
+ resp.promptFeedback = { safetyRatings: [] };
274
+ return resp;
275
+ }
276
+ __name(makeChunkResponse, "makeChunkResponse");
277
+ function makeFinalResponse(model, state, usage, finishReason) {
278
+ const resp = makeChunkResponse(model, state, [], finishReason);
279
+ if (usage) {
280
+ resp.usageMetadata = {
281
+ promptTokenCount: usage.input_tokens,
282
+ candidatesTokenCount: usage.output_tokens,
283
+ totalTokenCount: usage.total_tokens,
284
+ thoughtsTokenCount: usage.output_tokens_details?.reasoning_tokens ?? 0,
285
+ cachedContentTokenCount: usage.input_tokens_details?.cached_tokens ?? 0
286
+ };
287
+ setGenAiUsageProvenance(resp.usageMetadata, {
288
+ cachedInputTokensReported: typeof usage.input_tokens_details?.cached_tokens === "number"
289
+ });
290
+ }
291
+ return resp;
292
+ }
293
+ __name(makeFinalResponse, "makeFinalResponse");
294
+ function mapFinishReason(reason) {
295
+ const mapping = {
296
+ stop: FinishReason.STOP,
297
+ length: FinishReason.MAX_TOKENS,
298
+ content_filter: FinishReason.SAFETY,
299
+ max_output_tokens: FinishReason.MAX_TOKENS
300
+ };
301
+ return mapping[reason] ?? FinishReason.STOP;
302
+ }
303
+ __name(mapFinishReason, "mapFinishReason");
304
+ function convertGeminiContentsToResponsesInput(request) {
305
+ let instructions;
306
+ const items = [];
307
+ let callIdCounter = 0;
308
+ if (request.config?.systemInstruction) {
309
+ const si = request.config.systemInstruction;
310
+ if (typeof si === "string") {
311
+ instructions = si;
312
+ } else if (typeof si === "object" && "parts" in si && Array.isArray(si.parts)) {
313
+ instructions = si.parts.map((p) => typeof p === "string" ? p : p.text ?? "").join("\n");
314
+ }
315
+ }
316
+ const contents = request.contents;
317
+ if (!contents) return { instructions, input: items };
318
+ const contentArray = Array.isArray(contents) ? contents : typeof contents === "string" ? [{ role: "user", parts: [{ text: contents }] }] : [contents];
319
+ for (const content of contentArray) {
320
+ if (typeof content === "string") {
321
+ items.push({
322
+ type: "message",
323
+ role: "user",
324
+ content
325
+ });
326
+ continue;
327
+ }
328
+ const role = content.role === "model" ? "assistant" : "user";
329
+ const parts = content.parts ?? [];
330
+ let pendingContentParts = [];
331
+ const pendingToolMediaParts = [];
332
+ const flushPendingMessage = /* @__PURE__ */ __name(() => {
333
+ if (pendingContentParts.length === 0) return;
334
+ const content2 = pendingContentParts.length === 1 && pendingContentParts[0].type === "input_text" ? pendingContentParts[0].text : pendingContentParts;
335
+ items.push({ type: "message", role, content: content2 });
336
+ pendingContentParts = [];
337
+ }, "flushPendingMessage");
338
+ for (const part of parts) {
339
+ if (typeof part === "string") {
340
+ pendingContentParts.push({ type: "input_text", text: part });
341
+ continue;
342
+ }
343
+ if ("thought" in part && part.thought) {
344
+ flushPendingMessage();
345
+ if (role === "assistant") {
346
+ const payload = decodeReasoningSignature(part.thoughtSignature);
347
+ if (payload) {
348
+ items.push({
349
+ type: "reasoning",
350
+ id: payload.id,
351
+ encrypted_content: payload.encrypted_content,
352
+ summary: part.text ? [{ type: "summary_text", text: part.text }] : []
353
+ });
354
+ } else if (part.text) {
355
+ debugLogger.warn(
356
+ "Dropping unreplayable reasoning signature; preserving summary text as a plain message"
357
+ );
358
+ items.push({
359
+ type: "message",
360
+ role: "assistant",
361
+ content: part.text
362
+ });
363
+ }
364
+ }
365
+ continue;
366
+ }
367
+ if ("text" in part && part.text) {
368
+ pendingContentParts.push({ type: "input_text", text: part.text });
369
+ }
370
+ if ("functionCall" in part && part.functionCall) {
371
+ flushPendingMessage();
372
+ const callId = part.functionCall.id || `call_${Date.now()}_${callIdCounter++}`;
373
+ items.push({
374
+ type: "function_call",
375
+ call_id: callId,
376
+ name: part.functionCall.name ?? "",
377
+ arguments: JSON.stringify(part.functionCall.args ?? {})
378
+ });
379
+ }
380
+ if ("functionResponse" in part && part.functionResponse) {
381
+ flushPendingMessage();
382
+ const fr = part.functionResponse;
383
+ const responseRecord = fr.response;
384
+ let output;
385
+ if (typeof fr.response === "string") {
386
+ output = fr.response;
387
+ } else if (typeof responseRecord?.["output"] === "string") {
388
+ output = responseRecord["output"];
389
+ } else if (typeof responseRecord?.["error"] === "string") {
390
+ output = responseRecord["error"];
391
+ } else {
392
+ output = JSON.stringify(fr.response ?? {});
393
+ }
394
+ for (const frPart of fr.parts ?? []) {
395
+ if ("text" in frPart && typeof frPart.text === "string" && frPart.text.length > 0) {
396
+ const text = frPart.text;
397
+ output += (output ? "\n" : "") + text;
398
+ } else if (frPart.inlineData) {
399
+ const mimeType = frPart.inlineData.mimeType;
400
+ if (isSupportedResponseImageMime(mimeType)) {
401
+ pendingToolMediaParts.push({
402
+ type: "input_image",
403
+ image_url: `data:${mimeType};base64,${frPart.inlineData.data}`
404
+ });
405
+ } else {
406
+ const placeholderMime = placeholderMimeType(mimeType);
407
+ debugLogger.warn(
408
+ `Dropping unsupported tool-result inline media type: ${placeholderMime}`
409
+ );
410
+ pendingToolMediaParts.push({
411
+ type: "input_text",
412
+ text: `[Unsupported tool-result media type: ${placeholderMime}]`
413
+ });
414
+ }
415
+ } else if (frPart.fileData) {
416
+ const placeholderMime = placeholderMimeType(
417
+ frPart.fileData.mimeType
418
+ );
419
+ debugLogger.warn(
420
+ `Dropping unsupported tool-result file reference: ${placeholderMime}`
421
+ );
422
+ pendingToolMediaParts.push({
423
+ type: "input_text",
424
+ text: `[Unsupported tool-result file reference: ${placeholderMime}]`
425
+ });
426
+ }
427
+ }
428
+ items.push({
429
+ type: "function_call_output",
430
+ call_id: fr.id || `call_${Date.now()}_${callIdCounter++}`,
431
+ output
432
+ });
433
+ }
434
+ if ("inlineData" in part && part.inlineData && role === "user") {
435
+ const mimeType = part.inlineData.mimeType;
436
+ if (isSupportedResponseImageMime(mimeType)) {
437
+ pendingContentParts.push({
438
+ type: "input_image",
439
+ image_url: `data:${mimeType};base64,${part.inlineData.data}`
440
+ });
441
+ } else {
442
+ pendingContentParts.push({
443
+ type: "input_text",
444
+ text: `[Unsupported inline media type: ${placeholderMimeType(mimeType)}]`
445
+ });
446
+ }
447
+ }
448
+ if ("fileData" in part && part.fileData && role === "user") {
449
+ pendingContentParts.push({
450
+ type: "input_text",
451
+ text: `[Unsupported file reference: ${placeholderMimeType(part.fileData.mimeType)}]`
452
+ });
453
+ }
454
+ }
455
+ flushPendingMessage();
456
+ if (pendingToolMediaParts.length > 0) {
457
+ items.push({
458
+ type: "message",
459
+ role: "user",
460
+ content: [
461
+ {
462
+ type: "input_text",
463
+ text: "(attached media from previous tool call)"
464
+ },
465
+ ...pendingToolMediaParts
466
+ ]
467
+ });
468
+ }
469
+ }
470
+ return { instructions, input: items };
471
+ }
472
+ __name(convertGeminiContentsToResponsesInput, "convertGeminiContentsToResponsesInput");
473
+ function cleanOrphanedFunctionCalls(items) {
474
+ const callIds = /* @__PURE__ */ new Set();
475
+ const outputCallIds = /* @__PURE__ */ new Set();
476
+ for (const item of items) {
477
+ if (typeof item !== "object" || item === null || !("type" in item)) {
478
+ continue;
479
+ }
480
+ if (item.type === "function_call" && "call_id" in item) {
481
+ callIds.add(item.call_id);
482
+ } else if (item.type === "function_call_output" && "call_id" in item) {
483
+ outputCallIds.add(item.call_id);
484
+ }
485
+ }
486
+ return items.filter((item) => {
487
+ if (typeof item !== "object" || item === null || !("type" in item)) {
488
+ return true;
489
+ }
490
+ if (item.type === "function_call" && "call_id" in item) {
491
+ return outputCallIds.has(item.call_id);
492
+ }
493
+ if (item.type === "function_call_output" && "call_id" in item) {
494
+ return callIds.has(item.call_id);
495
+ }
496
+ return true;
497
+ });
498
+ }
499
+ __name(cleanOrphanedFunctionCalls, "cleanOrphanedFunctionCalls");
500
+ function convertGeminiToolsToResponsesTools(request) {
501
+ const tools = request.config?.tools;
502
+ if (!tools || !Array.isArray(tools)) return void 0;
503
+ const result = [];
504
+ for (const tool of tools) {
505
+ if (typeof tool !== "object" || tool === null) continue;
506
+ const funcDecls = "functionDeclarations" in tool ? tool.functionDeclarations : void 0;
507
+ if (!Array.isArray(funcDecls)) continue;
508
+ for (const func of funcDecls) {
509
+ if (!func.name) continue;
510
+ result.push({
511
+ type: "function",
512
+ name: func.name,
513
+ description: func.description,
514
+ parameters: normalizeResponsesParameters(
515
+ // Prefer parametersJsonSchema (raw JSON Schema, e.g. MCP/extension
516
+ // tools) and fall back to parameters, matching the Chat and
517
+ // Anthropic sibling wires — @google/genai allows both fields at
518
+ // once, and preferring `parameters` here would send a different,
519
+ // potentially lossier schema than the siblings for identical config.
520
+ func.parametersJsonSchema ?? func.parameters
521
+ )
522
+ });
523
+ }
524
+ }
525
+ return result.length > 0 ? result : void 0;
526
+ }
527
+ __name(convertGeminiToolsToResponsesTools, "convertGeminiToolsToResponsesTools");
528
+ function normalizeResponsesParameters(schema) {
529
+ if (schema === void 0) return void 0;
530
+ if (schema === null || typeof schema !== "object") return schema;
531
+ return normalizeResponsesSchemaNode(schema);
532
+ }
533
+ __name(normalizeResponsesParameters, "normalizeResponsesParameters");
534
+ function normalizeResponsesSchemaNode(node) {
535
+ if (Array.isArray(node)) {
536
+ return node.map((item) => normalizeResponsesSchemaNode(item));
537
+ }
538
+ if (!node || typeof node !== "object") return node;
539
+ const out = {
540
+ ...node
541
+ };
542
+ if (out["properties"] && typeof out["properties"] === "object") {
543
+ const props = out["properties"];
544
+ const nextProps = {};
545
+ for (const [k, v] of Object.entries(props)) {
546
+ nextProps[k] = normalizeResponsesSchemaNode(v);
547
+ }
548
+ out["properties"] = nextProps;
549
+ }
550
+ if (out["items"]) {
551
+ out["items"] = normalizeResponsesSchemaNode(out["items"]);
552
+ }
553
+ for (const key of ["anyOf", "oneOf", "allOf"]) {
554
+ const v = out[key];
555
+ if (Array.isArray(v)) {
556
+ out[key] = v.map((item) => normalizeResponsesSchemaNode(item));
557
+ }
558
+ }
559
+ if (out["type"] === "object" && out["properties"] === void 0) {
560
+ out["properties"] = {};
561
+ }
562
+ return out;
563
+ }
564
+ __name(normalizeResponsesSchemaNode, "normalizeResponsesSchemaNode");
565
+
566
+ // packages/core/src/core/openaiResponsesContentGenerator/responses-reasoning-rejection.ts
567
+ init_esbuild_shims();
568
+ var REJECTION_CODE = "string_above_max_length";
569
+ var PARAM_PATTERN = /^input\[(\d+)\]\.id$/;
570
+ var PARAM_REFERENCE_PATTERN = /input\[\d+\]\.id/g;
571
+ var MAXIMUM_LENGTH_PATTERN = /maximum length \d+/gi;
572
+ var SIMPLE_ESCAPES = {
573
+ '"': '"',
574
+ "\\": "\\",
575
+ "/": "/",
576
+ b: "\b",
577
+ f: "\f",
578
+ n: "\n",
579
+ r: "\r",
580
+ t: " "
581
+ };
582
+ var REPAIRABLE_CONTROLS = /* @__PURE__ */ new Set(["\n", " ", "\r"]);
583
+ var MAX_BODY_CHARS = 64e3;
584
+ var MAX_OBJECT_CANDIDATES = 32;
585
+ function parseReasoningIdRejection(status, responseBody) {
586
+ if (status !== 400) return void 0;
587
+ try {
588
+ return classify(responseBody);
589
+ } catch {
590
+ return void 0;
591
+ }
592
+ }
593
+ __name(parseReasoningIdRejection, "parseReasoningIdRejection");
594
+ function classify(responseBody) {
595
+ const text = toEnvelopeText(responseBody);
596
+ if (text === void 0) return void 0;
597
+ const envelope = readEnvelope(text, MAX_OBJECT_CANDIDATES, true);
598
+ if (!envelope) return void 0;
599
+ const error = readErrorMember(envelope.value);
600
+ if (!error) return void 0;
601
+ return matchRejection(error) ?? matchQuotedRejection(error, MAX_OBJECT_CANDIDATES - envelope.objects);
602
+ }
603
+ __name(classify, "classify");
604
+ function matchRejection(error) {
605
+ if (error["code"] !== REJECTION_CODE) return void 0;
606
+ const param = error["param"];
607
+ if (typeof param !== "string") return void 0;
608
+ const named = PARAM_PATTERN.exec(param);
609
+ if (!named) return void 0;
610
+ const index = Number(named[1]);
611
+ if (!Number.isSafeInteger(index) || index < 0) return void 0;
612
+ const message = error["message"];
613
+ return {
614
+ namedIndex: index,
615
+ maxLength: extractMaxLength(
616
+ typeof message === "string" ? message : void 0,
617
+ param
618
+ )
619
+ };
620
+ }
621
+ __name(matchRejection, "matchRejection");
622
+ function matchQuotedRejection(error, budget) {
623
+ const message = error["message"];
624
+ if (typeof message !== "string") return void 0;
625
+ const start = message.indexOf("{");
626
+ if (start < 0) return void 0;
627
+ const quoted = readEnvelope(message.slice(start), budget, false);
628
+ if (!quoted) return void 0;
629
+ const inner = readErrorMember(quoted.value);
630
+ return inner ? matchRejection(inner) : void 0;
631
+ }
632
+ __name(matchQuotedRejection, "matchQuotedRejection");
633
+ function readErrorMember(value) {
634
+ if (!isPlainObject(value)) return void 0;
635
+ const error = value["error"];
636
+ return isPlainObject(error) ? error : void 0;
637
+ }
638
+ __name(readErrorMember, "readErrorMember");
639
+ function isPlainObject(value) {
640
+ return typeof value === "object" && value !== null && !Array.isArray(value);
641
+ }
642
+ __name(isPlainObject, "isPlainObject");
643
+ function downgradeRejectedReasoningItems(items, rejection) {
644
+ const named = items[rejection.namedIndex];
645
+ if (!isReasoningItem(named)) return items;
646
+ const { maxLength } = rejection;
647
+ if (maxLength !== null && named.id.length <= maxLength) return items;
648
+ const rewritten = [];
649
+ let changed = false;
650
+ for (const item of items) {
651
+ if (!isReasoningItem(item) || !exceedsMax(item, maxLength)) {
652
+ rewritten.push(item);
653
+ continue;
654
+ }
655
+ changed = true;
656
+ const summary = readSummaryTexts(item);
657
+ if (summary.length === 0) continue;
658
+ rewritten.push({
659
+ type: "message",
660
+ role: "assistant",
661
+ content: summary.join("\n")
662
+ });
663
+ }
664
+ return changed ? rewritten : items;
665
+ }
666
+ __name(downgradeRejectedReasoningItems, "downgradeRejectedReasoningItems");
667
+ function exceedsMax(item, maxLength) {
668
+ return maxLength === null || item.id.length > maxLength;
669
+ }
670
+ __name(exceedsMax, "exceedsMax");
671
+ function isReasoningItem(item) {
672
+ return typeof item === "object" && item !== null && item.type === "reasoning" && typeof item.id === "string";
673
+ }
674
+ __name(isReasoningItem, "isReasoningItem");
675
+ function readSummaryTexts(item) {
676
+ if (!Array.isArray(item.summary)) return [];
677
+ const texts = [];
678
+ for (const entry of item.summary) {
679
+ if (typeof entry === "object" && entry !== null && entry.type === "summary_text" && typeof entry.text === "string" && entry.text.length > 0) {
680
+ texts.push(entry.text);
681
+ }
682
+ }
683
+ return texts;
684
+ }
685
+ __name(readSummaryTexts, "readSummaryTexts");
686
+ function extractMaxLength(message, param) {
687
+ if (!message) return null;
688
+ const references = message.match(PARAM_REFERENCE_PATTERN);
689
+ if (!references || references.length !== 1 || references[0] !== param) {
690
+ return null;
691
+ }
692
+ const maxima = message.match(MAXIMUM_LENGTH_PATTERN);
693
+ if (!maxima || maxima.length !== 1) return null;
694
+ const digits = /\d+/.exec(maxima[0]);
695
+ if (!digits) return null;
696
+ const value = Number(digits[0]);
697
+ if (!Number.isSafeInteger(value) || value <= 0) return null;
698
+ return value;
699
+ }
700
+ __name(extractMaxLength, "extractMaxLength");
701
+ function toEnvelopeText(responseBody) {
702
+ let text;
703
+ if (typeof responseBody === "string") {
704
+ text = responseBody;
705
+ } else if (typeof responseBody === "object" && responseBody !== null && !Array.isArray(responseBody)) {
706
+ try {
707
+ text = JSON.stringify(responseBody);
708
+ } catch {
709
+ return void 0;
710
+ }
711
+ if (typeof text !== "string") return void 0;
712
+ } else {
713
+ return void 0;
714
+ }
715
+ if (text.length > MAX_BODY_CHARS) return void 0;
716
+ let start = 0;
717
+ while (start < text.length && isJsonWhitespace(text[start])) start++;
718
+ return text[start] === "{" ? text.slice(start) : void 0;
719
+ }
720
+ __name(toEnvelopeText, "toEnvelopeText");
721
+ function readEnvelope(text, budget, repairErrorMessage) {
722
+ const normalized = normalizeEnvelope(text, budget, repairErrorMessage);
723
+ if (!normalized) return void 0;
724
+ try {
725
+ return { value: JSON.parse(normalized.json), objects: normalized.objects };
726
+ } catch {
727
+ return void 0;
728
+ }
729
+ }
730
+ __name(readEnvelope, "readEnvelope");
731
+ function normalizeEnvelope(text, budget, repairErrorMessage) {
732
+ const out = [];
733
+ const stack = [];
734
+ let objects = 0;
735
+ let closed = false;
736
+ let i = 0;
737
+ while (i < text.length) {
738
+ const ch = text[i];
739
+ if (closed) {
740
+ if (!isJsonWhitespace(ch)) return void 0;
741
+ i++;
742
+ continue;
743
+ }
744
+ if (ch === '"') {
745
+ const top = stack[stack.length - 1];
746
+ const atKey = top?.object === true && top.atKey;
747
+ const repairable = repairErrorMessage && top?.object === true && !atKey && top.recognizedError && top.key === "message";
748
+ const literal = readStringLiteral(text, i, repairable);
749
+ if (!literal) return void 0;
750
+ if (top?.object && top.atKey) {
751
+ if (top.keys.has(literal.value)) return void 0;
752
+ top.keys.add(literal.value);
753
+ top.atKey = false;
754
+ top.key = literal.value;
755
+ }
756
+ out.push(literal.json);
757
+ i = literal.next;
758
+ continue;
759
+ }
760
+ if (ch === "{" || ch === "[") {
761
+ const object = ch === "{";
762
+ if (object && ++objects > budget) return void 0;
763
+ const parent = stack[stack.length - 1];
764
+ stack.push({
765
+ object,
766
+ keys: /* @__PURE__ */ new Set(),
767
+ recognizedError: object && stack.length === 1 && parent?.object === true && parent.key === "error",
768
+ atKey: object,
769
+ key: void 0
770
+ });
771
+ } else if (ch === "}" || ch === "]") {
772
+ const top = stack.pop();
773
+ if (!top || top.object !== (ch === "}")) return void 0;
774
+ if (stack.length === 0) closed = true;
775
+ } else if (ch === ",") {
776
+ const top = stack[stack.length - 1];
777
+ if (top?.object) {
778
+ top.atKey = true;
779
+ top.key = void 0;
780
+ }
781
+ }
782
+ out.push(ch);
783
+ i++;
784
+ }
785
+ if (!closed || stack.length > 0) return void 0;
786
+ return { json: out.join(""), objects };
787
+ }
788
+ __name(normalizeEnvelope, "normalizeEnvelope");
789
+ function isJsonWhitespace(ch) {
790
+ return ch === " " || ch === " " || ch === "\n" || ch === "\r";
791
+ }
792
+ __name(isJsonWhitespace, "isJsonWhitespace");
793
+ function readStringLiteral(text, start, repairable) {
794
+ let value = "";
795
+ let json = '"';
796
+ let i = start + 1;
797
+ while (i < text.length) {
798
+ const ch = text[i];
799
+ if (ch === '"') return { value, json: `${json}"`, next: i + 1 };
800
+ if (ch === "\\") {
801
+ const escape = text[i + 1];
802
+ if (escape === "u") {
803
+ const hex = text.slice(i + 2, i + 6);
804
+ if (!/^[0-9a-fA-F]{4}$/.test(hex)) return void 0;
805
+ value += String.fromCharCode(parseInt(hex, 16));
806
+ json += text.slice(i, i + 6);
807
+ i += 6;
808
+ continue;
809
+ }
810
+ const simple = escape === void 0 ? void 0 : SIMPLE_ESCAPES[escape];
811
+ if (simple === void 0) return void 0;
812
+ value += simple;
813
+ json += `\\${escape}`;
814
+ i += 2;
815
+ continue;
816
+ }
817
+ const code = ch.charCodeAt(0);
818
+ if (code < 32) {
819
+ if (!repairable || !REPAIRABLE_CONTROLS.has(ch)) return void 0;
820
+ value += ch;
821
+ json += `\\u${code.toString(16).padStart(4, "0")}`;
822
+ i++;
823
+ continue;
824
+ }
825
+ value += ch;
826
+ json += ch;
827
+ i++;
828
+ }
829
+ return void 0;
830
+ }
831
+ __name(readStringLiteral, "readStringLiteral");
832
+ function countReasoningItems(items) {
833
+ return items.filter(isReasoningItem).length;
834
+ }
835
+ __name(countReasoningItems, "countReasoningItems");
836
+
837
+ // packages/core/src/core/openaiResponsesContentGenerator/responses-pipeline.ts
838
+ import { createHash } from "node:crypto";
839
+ var debugLogger2 = createDebugLogger("RESPONSES_PIPELINE");
840
+ var StreamInactivityTimeoutError = class extends Error {
841
+ constructor(idleMs, chunksReceived) {
842
+ super(
843
+ `No stream activity for ${idleMs}ms after ${chunksReceived} chunks. Set ${QWEN_STREAM_IDLE_TIMEOUT_MS_ENV} to increase this window (or 0 to disable it).`
844
+ );
845
+ this.idleMs = idleMs;
846
+ this.chunksReceived = chunksReceived;
847
+ this.name = "StreamInactivityTimeoutError";
848
+ }
849
+ static {
850
+ __name(this, "StreamInactivityTimeoutError");
851
+ }
852
+ code = "ETIMEDOUT";
853
+ };
854
+ var StreamLifetimeExceededError = class extends Error {
855
+ constructor(maxLifetimeMs, chunksReceived) {
856
+ super(
857
+ `Stream exceeded its ${maxLifetimeMs}ms upstream-wait cap after ${chunksReceived} chunks. Set ${QWEN_STREAM_MAX_LIFETIME_MS_ENV} to increase this window (or 0 to disable it).`
858
+ );
859
+ this.maxLifetimeMs = maxLifetimeMs;
860
+ this.chunksReceived = chunksReceived;
861
+ this.name = "StreamLifetimeExceededError";
862
+ }
863
+ static {
864
+ __name(this, "StreamLifetimeExceededError");
865
+ }
866
+ code = "ETIMEDOUT";
867
+ };
868
+ var StreamConnectTimeoutError = class extends Error {
869
+ constructor(connectTimeoutMs) {
870
+ super(
871
+ `Responses API connect phase exceeded ${connectTimeoutMs}ms before any response headers arrived. Increase the model request timeout (or set it to 0 to disable this bound).`
872
+ );
873
+ this.connectTimeoutMs = connectTimeoutMs;
874
+ this.name = "StreamConnectTimeoutError";
875
+ }
876
+ static {
877
+ __name(this, "StreamConnectTimeoutError");
878
+ }
879
+ code = "ETIMEDOUT";
880
+ };
881
+ var ErrorBodyTimeoutError = class extends Error {
882
+ constructor(bodyTimeoutMs, status) {
883
+ super(
884
+ `Responses API error response body (HTTP ${status}) did not complete within ${bodyTimeoutMs}ms. Increase the model request timeout (or set it to 0 to disable this bound).`
885
+ );
886
+ this.bodyTimeoutMs = bodyTimeoutMs;
887
+ this.status = status;
888
+ this.name = "ErrorBodyTimeoutError";
889
+ }
890
+ static {
891
+ __name(this, "ErrorBodyTimeoutError");
892
+ }
893
+ code = "ETIMEDOUT";
894
+ };
895
+ function newAbortError() {
896
+ const abortErr = new Error("Aborted");
897
+ abortErr.name = "AbortError";
898
+ return abortErr;
899
+ }
900
+ __name(newAbortError, "newAbortError");
901
+ var CLASSIFIABLE_ERROR_BODY_CHARS = 64e3;
902
+ var MAX_ERROR_BODY_CHARS = CLASSIFIABLE_ERROR_BODY_CHARS + 1;
903
+ function resolveStreamGuardMs(fromConfig, configLabel, envName, defaultMs) {
904
+ if (typeof fromConfig === "number") {
905
+ if (Number.isInteger(fromConfig) && fromConfig <= MAX_STREAM_GUARD_TIMEOUT_MS) {
906
+ return fromConfig;
907
+ }
908
+ console.warn(
909
+ `[qwen-code] Ignoring out-of-range ${configLabel}=${fromConfig} (expected an integer in (-\u221E, ${MAX_STREAM_GUARD_TIMEOUT_MS}]); falling back to ${envName}/default.`
910
+ );
911
+ }
912
+ const raw = process.env[envName];
913
+ const trimmed = raw?.trim();
914
+ if (trimmed) {
915
+ if (/^\d+$/.test(trimmed)) {
916
+ const parsed = Number(trimmed);
917
+ if (parsed <= MAX_STREAM_GUARD_TIMEOUT_MS) {
918
+ return parsed;
919
+ }
920
+ }
921
+ console.warn(
922
+ `[qwen-code] Ignoring invalid ${envName}="${raw}" (expected an integer of milliseconds in [0, ${MAX_STREAM_GUARD_TIMEOUT_MS}]); using default ${defaultMs}ms.`
923
+ );
924
+ }
925
+ return defaultMs;
926
+ }
927
+ __name(resolveStreamGuardMs, "resolveStreamGuardMs");
928
+ function resolveStreamIdleTimeoutMs(config) {
929
+ return resolveStreamGuardMs(
930
+ config.streamIdleTimeoutMs,
931
+ "streamIdleTimeoutMs",
932
+ QWEN_STREAM_IDLE_TIMEOUT_MS_ENV,
933
+ DEFAULT_STREAM_IDLE_TIMEOUT_MS
934
+ );
935
+ }
936
+ __name(resolveStreamIdleTimeoutMs, "resolveStreamIdleTimeoutMs");
937
+ function resolveStreamMaxLifetimeMs(config) {
938
+ return resolveStreamGuardMs(
939
+ config.streamMaxLifetimeMs,
940
+ "streamMaxLifetimeMs",
941
+ QWEN_STREAM_MAX_LIFETIME_MS_ENV,
942
+ DEFAULT_STREAM_MAX_LIFETIME_MS
943
+ );
944
+ }
945
+ __name(resolveStreamMaxLifetimeMs, "resolveStreamMaxLifetimeMs");
946
+ var ResponsesPipeline = class {
947
+ static {
948
+ __name(this, "ResponsesPipeline");
949
+ }
950
+ config;
951
+ cliConfig;
952
+ // Resolved once (config field > env > default) so the env read happens per
953
+ // pipeline, not per streaming request.
954
+ streamIdleTimeoutMs;
955
+ // Total-lifetime cap for a single streaming response (accumulated
956
+ // upstream-wait, never reset by chunk arrival). Companion to the idle
957
+ // watchdog -- see StreamLifetimeExceededError / issue #8597.
958
+ streamMaxLifetimeMs;
959
+ // Connect-phase timeout (ms). Honors ContentGeneratorConfig.timeout the same
960
+ // way the embed client does, via resolveRequestTimeout: undefined -> default,
961
+ // `0`/negative -> disabled.
962
+ connectTimeoutMs;
963
+ constructor(config, cliConfig) {
964
+ this.config = config;
965
+ this.cliConfig = cliConfig;
966
+ this.streamIdleTimeoutMs = resolveStreamIdleTimeoutMs(config);
967
+ this.streamMaxLifetimeMs = resolveStreamMaxLifetimeMs(config);
968
+ this.connectTimeoutMs = resolveRequestTimeout(config.timeout);
969
+ }
970
+ async *executeStream(request, userPromptId, signal) {
971
+ yield* await this.connectStream(request, userPromptId, signal);
972
+ }
973
+ /**
974
+ * Eagerly performs the connect phase (fetch + non-2xx handling + content-type
975
+ * guard) and returns a lazy generator over the response body. Callers that
976
+ * wrap the returned promise in retryWithBackoff (index.ts's
977
+ * generateContentStream) then see connection-time HTTP errors -- a 500/502/504
978
+ * or a 429 storm -- surface from the awaited promise and get retried, instead
979
+ * of the errors escaping later during lazy iteration outside the retry
980
+ * wrapper (a lazy `async *` generator resolves its promise before any network
981
+ * I/O runs).
982
+ */
983
+ async connectStream(request, userPromptId, signal) {
984
+ const activeRequest = this.buildRequest(request, userPromptId);
985
+ const reader = await this.connectWithReasoningReplayRecovery(
986
+ activeRequest,
987
+ signal
988
+ );
989
+ return this.iterateBody(reader, new ResponsesStreamState(), signal);
990
+ }
991
+ /**
992
+ * Connect, and if the endpoint explicitly refuses a replayed reasoning item
993
+ * id, send the same request once more with those items downgraded (issue
994
+ * #9452).
995
+ *
996
+ * The first request always goes out exactly as built. Recovery matters
997
+ * because the offending ids live in persisted history: without it, every
998
+ * subsequent send in that session rebuilds the same ids and fails the same
999
+ * way, so the session is permanently wedged against that endpoint.
1000
+ */
1001
+ async connectWithReasoningReplayRecovery(apiRequest, signal) {
1002
+ let retryRequest;
1003
+ try {
1004
+ return await this.connect(apiRequest, signal);
1005
+ } catch (error) {
1006
+ retryRequest = this.buildReasoningReplayRetry(apiRequest, error);
1007
+ if (!retryRequest) throw error;
1008
+ }
1009
+ return this.connect(retryRequest, signal);
1010
+ }
1011
+ /**
1012
+ * The retry request, or undefined when the error is not a reasoning-id
1013
+ * rejection or nothing in this body would change. Builds a new request
1014
+ * object -- the caller's request, the input array, and every item it holds
1015
+ * are left untouched.
1016
+ */
1017
+ buildReasoningReplayRetry(apiRequest, error) {
1018
+ if (typeof error !== "object" || error === null) return void 0;
1019
+ const { reasoningIdRejection: rejection } = error;
1020
+ if (!rejection) return void 0;
1021
+ const input = downgradeRejectedReasoningItems(apiRequest.input, rejection);
1022
+ if (input === apiRequest.input) return void 0;
1023
+ const reasoningItems = countReasoningItems(apiRequest.input);
1024
+ debugLogger2.debug(
1025
+ "Retrying once with downgraded reasoning replay",
1026
+ `namedIndex=${rejection.namedIndex}`,
1027
+ `maxLengthReported=${rejection.maxLength !== null}`,
1028
+ `reasoningItems=${reasoningItems}`,
1029
+ `downgradedItems=${reasoningItems - countReasoningItems(input)}`
1030
+ );
1031
+ return { ...apiRequest, input };
1032
+ }
1033
+ async execute(request, userPromptId, signal) {
1034
+ const chunks = [];
1035
+ for await (const chunk of this.executeStream(
1036
+ request,
1037
+ userPromptId,
1038
+ signal
1039
+ )) {
1040
+ chunks.push(chunk);
1041
+ }
1042
+ return mergeStreamResponses(chunks);
1043
+ }
1044
+ /**
1045
+ * Key the OpenAI prefix cache on the SESSION, not the turn.
1046
+ *
1047
+ * `userPromptId` is `${sessionId}########${counter}` -- it changes on every
1048
+ * send, so using it directly gives each turn its own cache namespace and no
1049
+ * request in a session can ever hit the prefix cache written by the one
1050
+ * before it. Nothing fails when that happens; the cost is silent, which is
1051
+ * why it survived until review.
1052
+ *
1053
+ * Matches the Chat wire's `applyOfficialOpenAIPromptCaching`
1054
+ * (openaiContentGenerator/prefix-caching.ts), which keys on
1055
+ * `qwen-code:${sessionId}` -- that landed on main in #8418 after this
1056
+ * branch forked, so the two wires would otherwise disagree on merge.
1057
+ *
1058
+ * `Config.getSessionId()` is typed `string`, so the guard below is for the
1059
+ * empty-string case only -- falling back to `userPromptId` there keeps a
1060
+ * per-request key rather than collapsing every session onto a bare
1061
+ * `qwen-code:` prefix.
1062
+ */
1063
+ buildPromptCacheKey(userPromptId) {
1064
+ const sessionId = this.cliConfig.getSessionId();
1065
+ return sanitizePromptCacheKey(
1066
+ sessionId ? `qwen-code:${sessionId}` : userPromptId
1067
+ );
1068
+ }
1069
+ buildRequest(request, userPromptId) {
1070
+ const { instructions, input } = convertGeminiContentsToResponsesInput(request);
1071
+ const tools = convertGeminiToolsToResponsesTools(request);
1072
+ const reasoning = this.buildReasoning(request);
1073
+ const apiRequest = {
1074
+ model: this.config.model,
1075
+ input: cleanOrphanedFunctionCalls(input),
1076
+ instructions,
1077
+ tools,
1078
+ stream: true,
1079
+ prompt_cache_key: this.buildPromptCacheKey(userPromptId),
1080
+ // We never reference previous_response_id, so server-side storage of
1081
+ // the response buys nothing. The spec pairs reasoning.encrypted_content
1082
+ // with store:false as the intended stateless-replay recipe -- set it
1083
+ // unconditionally for consistency, not just when reasoning is on.
1084
+ store: false
1085
+ };
1086
+ if (tools && tools.length > 0) {
1087
+ apiRequest.tool_choice = "auto";
1088
+ apiRequest.parallel_tool_calls = true;
1089
+ const fcMode = request.config?.toolConfig?.functionCallingConfig?.mode;
1090
+ if (fcMode === "ANY") {
1091
+ apiRequest.tool_choice = "required";
1092
+ } else if (fcMode === "NONE") {
1093
+ apiRequest.tool_choice = "none";
1094
+ }
1095
+ }
1096
+ if (reasoning) {
1097
+ apiRequest.reasoning = reasoning;
1098
+ apiRequest.include = ["reasoning.encrypted_content"];
1099
+ }
1100
+ const temperature = this.config.samplingParams?.temperature ?? request.config?.temperature;
1101
+ if (temperature != null) {
1102
+ apiRequest.temperature = temperature;
1103
+ }
1104
+ const topP = this.config.samplingParams?.top_p ?? request.config?.topP;
1105
+ if (topP != null) {
1106
+ apiRequest.top_p = topP;
1107
+ }
1108
+ const configMaxTokens = this.config.samplingParams?.max_tokens;
1109
+ const requestMaxTokens = request.config?.maxOutputTokens;
1110
+ const maxOut = reconcileMaxTokens(configMaxTokens, requestMaxTokens) ?? configMaxTokens ?? requestMaxTokens;
1111
+ if (maxOut != null) {
1112
+ apiRequest.max_output_tokens = maxOut;
1113
+ }
1114
+ if (this.config.extra_body) {
1115
+ const thinkingOptOut = request.config?.thinkingConfig?.includeThoughts === false;
1116
+ const requestRecord = apiRequest;
1117
+ for (const [key, value] of Object.entries(this.config.extra_body)) {
1118
+ if (key === "enable_thinking") continue;
1119
+ if (thinkingOptOut && (key === "reasoning" || key === "include")) {
1120
+ continue;
1121
+ }
1122
+ if (!(key in requestRecord) || requestRecord[key] === void 0) {
1123
+ requestRecord[key] = value;
1124
+ }
1125
+ }
1126
+ }
1127
+ return apiRequest;
1128
+ }
1129
+ buildReasoning(request) {
1130
+ if (request.config?.thinkingConfig?.includeThoughts === false) {
1131
+ return void 0;
1132
+ }
1133
+ const r = this.config.reasoning;
1134
+ if (r === false) return void 0;
1135
+ const legacyEnableThinking = this.config.extra_body?.["enable_thinking"];
1136
+ if (r === void 0 && legacyEnableThinking !== true) return void 0;
1137
+ const reasoning = {};
1138
+ if (r?.effort) {
1139
+ reasoning.effort = r.effort;
1140
+ } else if (legacyEnableThinking === true) {
1141
+ reasoning.effort = "medium";
1142
+ }
1143
+ if (reasoning.effort) {
1144
+ reasoning.summary = "auto";
1145
+ }
1146
+ return Object.keys(reasoning).length > 0 ? reasoning : void 0;
1147
+ }
1148
+ /**
1149
+ * Connect phase: build and send the request, validate the HTTP response, and
1150
+ * return a reader over the SSE body. Eagerly awaited so connection-time
1151
+ * failures (non-2xx, missing body, non-SSE content-type, transport errors)
1152
+ * reject the promise the caller can wrap in retryWithBackoff.
1153
+ */
1154
+ async connect(apiRequest, signal) {
1155
+ const baseUrl = (this.config.baseUrl || "https://api.openai.com").replace(/\/v1\/?$/, "").replace(/\/$/, "");
1156
+ const url = `${baseUrl}/v1/responses`;
1157
+ const headers = {
1158
+ "content-type": "application/json",
1159
+ accept: "text/event-stream"
1160
+ };
1161
+ const apiKey = this.config.apiKey ?? (this.config.apiKeyEnvKey ? process.env[this.config.apiKeyEnvKey] : void 0);
1162
+ if (apiKey) {
1163
+ headers["authorization"] = `Bearer ${apiKey}`;
1164
+ }
1165
+ if (this.config.customHeaders) {
1166
+ for (const [name, value] of Object.entries(this.config.customHeaders)) {
1167
+ headers[name.toLowerCase()] = value;
1168
+ }
1169
+ }
1170
+ const body = JSON.stringify(apiRequest);
1171
+ debugLogger2.debug(
1172
+ `POST ${redactProxyCredentials(url)}`,
1173
+ body.substring(0, 500)
1174
+ );
1175
+ const connectController = new AbortController();
1176
+ if (signal) {
1177
+ if (signal.aborted) {
1178
+ connectController.abort();
1179
+ } else {
1180
+ signal.addEventListener("abort", () => connectController.abort(), {
1181
+ once: true
1182
+ });
1183
+ }
1184
+ }
1185
+ const fetchOpts = {
1186
+ method: "POST",
1187
+ headers,
1188
+ body,
1189
+ signal: connectController.signal
1190
+ };
1191
+ const runtimeOptions = buildRuntimeFetchOptions(
1192
+ "openai",
1193
+ this.cliConfig.getProxy()
1194
+ );
1195
+ if (runtimeOptions?.fetchOptions?.dispatcher) {
1196
+ fetchOpts.dispatcher = runtimeOptions.fetchOptions.dispatcher;
1197
+ }
1198
+ const fetchFn = runtimeOptions?.fetch ?? fetch;
1199
+ const connectTimeoutMs = this.connectTimeoutMs;
1200
+ const timeoutActive = connectTimeoutMs > 0 && connectTimeoutMs < DISABLED_REQUEST_TIMEOUT_MS;
1201
+ let response;
1202
+ if (timeoutActive) {
1203
+ let timer;
1204
+ const timeout = new Promise((_resolve, reject) => {
1205
+ timer = setTimeout(() => {
1206
+ if (signal?.aborted) {
1207
+ const abortErr = new Error("Aborted");
1208
+ abortErr.name = "AbortError";
1209
+ reject(abortErr);
1210
+ } else {
1211
+ connectController.abort();
1212
+ reject(new StreamConnectTimeoutError(connectTimeoutMs));
1213
+ }
1214
+ }, connectTimeoutMs);
1215
+ timer.unref?.();
1216
+ });
1217
+ try {
1218
+ response = await Promise.race([
1219
+ fetchFn(url, fetchOpts),
1220
+ timeout
1221
+ ]);
1222
+ } catch (error) {
1223
+ throw redactProxyError(error);
1224
+ } finally {
1225
+ if (timer !== void 0) clearTimeout(timer);
1226
+ }
1227
+ } else {
1228
+ try {
1229
+ response = await fetchFn(url, fetchOpts);
1230
+ } catch (error) {
1231
+ throw redactProxyError(error);
1232
+ }
1233
+ }
1234
+ if (!response.ok) {
1235
+ const errBody = await this.readErrorResponseBody(
1236
+ response,
1237
+ signal,
1238
+ connectController
1239
+ );
1240
+ const rejection = parseReasoningIdRejection(response.status, errBody);
1241
+ let diagnosticBody = errBody.replace(
1242
+ /\\+\/?/g,
1243
+ (match) => match.endsWith("/") ? "/" : match
1244
+ );
1245
+ if (errBody.length > CLASSIFIABLE_ERROR_BODY_CHARS) {
1246
+ diagnosticBody = diagnosticBody.replace(/\/\/[^/\s]*$/, "//<redacted>");
1247
+ }
1248
+ const excerpt = redactProxyCredentials(diagnosticBody).substring(0, 500);
1249
+ const err = new Error(
1250
+ `Responses API error ${response.status}: ${excerpt}`
1251
+ );
1252
+ err.status = response.status;
1253
+ err.reasoningIdRejection = rejection;
1254
+ throw redactProxyError(err);
1255
+ }
1256
+ if (!response.body) {
1257
+ throw new Error("Responses API returned no body");
1258
+ }
1259
+ const contentType = response.headers.get("content-type") ?? "";
1260
+ if (!/^\s*text\/event-stream\s*(?:;|$)/i.test(contentType)) {
1261
+ throw new Error(
1262
+ `Responses API returned non-SSE content-type: ${contentType || "<missing>"}`
1263
+ );
1264
+ }
1265
+ return response.body.getReader();
1266
+ }
1267
+ /**
1268
+ * Read a non-2xx response body under three bounds: the configured request
1269
+ * timeout, the caller's AbortSignal, and a character cap.
1270
+ *
1271
+ * The whole body is kept when it fits inside the cap, because
1272
+ * responses-reasoning-rejection.ts classifies from the complete envelope; a
1273
+ * body that hits the cap is returned one character over the classifier's
1274
+ * own ceiling, so recovery fails closed on it rather than acting on a
1275
+ * prefix. The excerpt the surfaced message quotes is capped separately by
1276
+ * the caller, and nothing here logs the body.
1277
+ *
1278
+ * On either bound the body is cancelled and the request aborted, so the
1279
+ * socket is freed instead of draining a body nobody will read.
1280
+ */
1281
+ async readErrorResponseBody(response, signal, requestController) {
1282
+ const timeoutMs = this.connectTimeoutMs;
1283
+ const bounded = timeoutMs > 0 && timeoutMs < DISABLED_REQUEST_TIMEOUT_MS;
1284
+ let rejectTermination;
1285
+ const termination = new Promise((_resolve, reject) => {
1286
+ rejectTermination = reject;
1287
+ });
1288
+ termination.catch(() => {
1289
+ });
1290
+ let timer;
1291
+ let onAbort;
1292
+ if (signal?.aborted) {
1293
+ rejectTermination(newAbortError());
1294
+ } else if (signal) {
1295
+ onAbort = /* @__PURE__ */ __name(() => rejectTermination(newAbortError()), "onAbort");
1296
+ signal.addEventListener("abort", onAbort, { once: true });
1297
+ }
1298
+ if (bounded) {
1299
+ timer = setTimeout(() => {
1300
+ rejectTermination(
1301
+ signal?.aborted ? newAbortError() : new ErrorBodyTimeoutError(timeoutMs, response.status)
1302
+ );
1303
+ }, timeoutMs);
1304
+ timer.unref?.();
1305
+ }
1306
+ const cleanup = /* @__PURE__ */ __name(() => {
1307
+ if (timer !== void 0) clearTimeout(timer);
1308
+ if (onAbort && signal) signal.removeEventListener("abort", onAbort);
1309
+ }, "cleanup");
1310
+ const body = response.body;
1311
+ if (!body) {
1312
+ try {
1313
+ const text2 = await Promise.race([
1314
+ Promise.resolve(response.text()).catch(() => ""),
1315
+ termination
1316
+ ]);
1317
+ return text2.slice(0, MAX_ERROR_BODY_CHARS);
1318
+ } finally {
1319
+ cleanup();
1320
+ }
1321
+ }
1322
+ const reader = body.getReader();
1323
+ const decoder = new TextDecoder();
1324
+ let text = "";
1325
+ let completed = false;
1326
+ try {
1327
+ while (text.length < MAX_ERROR_BODY_CHARS) {
1328
+ const readPromise = reader.read();
1329
+ let result;
1330
+ try {
1331
+ result = await Promise.race([readPromise, termination]);
1332
+ } catch (error) {
1333
+ void Promise.resolve(readPromise).catch(() => {
1334
+ });
1335
+ throw error;
1336
+ }
1337
+ if (result.done) {
1338
+ completed = true;
1339
+ break;
1340
+ }
1341
+ text += decoder.decode(result.value, { stream: true });
1342
+ }
1343
+ if (completed) text += decoder.decode();
1344
+ return text.slice(0, MAX_ERROR_BODY_CHARS);
1345
+ } finally {
1346
+ cleanup();
1347
+ void reader.cancel().catch(() => {
1348
+ });
1349
+ if (!completed) requestController.abort();
1350
+ }
1351
+ }
1352
+ /**
1353
+ * Body-iteration phase: lazily drain the SSE reader, parse frames, and yield
1354
+ * Gemini responses. Two guards wrap each `reader.read()`, mirroring the Chat
1355
+ * pipeline: an idle watchdog fails a silent mid-stream stall with a retryable
1356
+ * ETIMEDOUT (the timer resets on every chunk, so an actively streaming model
1357
+ * is never interrupted; `streamIdleTimeoutMs <= 0` disables it), and a
1358
+ * total-lifetime cap on accumulated upstream-wait (NOT reset by chunk
1359
+ * arrival) fails a drip-fed stream that keeps resetting the idle timer but
1360
+ * never completes (issue #8597; `streamMaxLifetimeMs <= 0` disables it).
1361
+ */
1362
+ async *iterateBody(reader, streamState, signal) {
1363
+ const idleMs = this.streamIdleTimeoutMs;
1364
+ const maxLifetimeMs = this.streamMaxLifetimeMs;
1365
+ let chunksReceived = 0;
1366
+ let upstreamMs = 0;
1367
+ const readChunk = /* @__PURE__ */ __name(() => {
1368
+ if (idleMs <= 0 && maxLifetimeMs <= 0) return reader.read();
1369
+ const remainingLifetimeMs = maxLifetimeMs > 0 ? maxLifetimeMs - upstreamMs : Number.POSITIVE_INFINITY;
1370
+ if (remainingLifetimeMs <= 0) {
1371
+ if (signal?.aborted) {
1372
+ const abortErr = new Error("Aborted");
1373
+ abortErr.name = "AbortError";
1374
+ return Promise.reject(abortErr);
1375
+ }
1376
+ return Promise.reject(
1377
+ new StreamLifetimeExceededError(maxLifetimeMs, chunksReceived)
1378
+ );
1379
+ }
1380
+ const readPromise = reader.read();
1381
+ const awaitedAt = performance.now();
1382
+ let timer;
1383
+ const timeout = new Promise((_resolve, reject) => {
1384
+ const idleIn = idleMs > 0 ? idleMs : Number.POSITIVE_INFINITY;
1385
+ const wait = Math.min(idleIn, remainingLifetimeMs);
1386
+ timer = setTimeout(
1387
+ () => {
1388
+ if (signal?.aborted) {
1389
+ const abortErr = new Error("Aborted");
1390
+ abortErr.name = "AbortError";
1391
+ reject(abortErr);
1392
+ } else if (remainingLifetimeMs <= idleIn) {
1393
+ reject(
1394
+ new StreamLifetimeExceededError(maxLifetimeMs, chunksReceived)
1395
+ );
1396
+ } else {
1397
+ reject(new StreamInactivityTimeoutError(idleMs, chunksReceived));
1398
+ }
1399
+ },
1400
+ Math.max(wait, 0)
1401
+ );
1402
+ timer.unref?.();
1403
+ });
1404
+ return Promise.race([readPromise, timeout]).then((result) => {
1405
+ upstreamMs += performance.now() - awaitedAt;
1406
+ return result;
1407
+ }).catch((err) => {
1408
+ void Promise.resolve(readPromise).catch(() => {
1409
+ });
1410
+ throw err;
1411
+ }).finally(() => {
1412
+ if (timer !== void 0) clearTimeout(timer);
1413
+ });
1414
+ }, "readChunk");
1415
+ const convertParsedFrame = /* @__PURE__ */ __name((eventType, data) => {
1416
+ const sseEvent = { event: eventType, data };
1417
+ return convertResponsesEventToGemini(
1418
+ sseEvent,
1419
+ this.config.model,
1420
+ streamState
1421
+ );
1422
+ }, "convertParsedFrame");
1423
+ const parseSSEFrame = /* @__PURE__ */ __name((eventType, dataStr) => {
1424
+ try {
1425
+ const data = JSON.parse(dataStr);
1426
+ return convertParsedFrame(eventType, data);
1427
+ } catch (err) {
1428
+ if (err instanceof SyntaxError) {
1429
+ debugLogger2.debug(
1430
+ `Failed to parse SSE data: ${dataStr.substring(0, 200)}`
1431
+ );
1432
+ return null;
1433
+ }
1434
+ throw redactProxyError(err);
1435
+ }
1436
+ }, "parseSSEFrame");
1437
+ const decoder = new TextDecoder();
1438
+ let buffer = "";
1439
+ let currentEventType = null;
1440
+ let dataAccumulator = "";
1441
+ try {
1442
+ while (true) {
1443
+ const { done, value } = await readChunk();
1444
+ if (done) break;
1445
+ chunksReceived += 1;
1446
+ buffer += decoder.decode(value, { stream: true });
1447
+ const lines = buffer.split("\n");
1448
+ buffer = lines.pop() ?? "";
1449
+ for (const line of lines) {
1450
+ if (line.startsWith("event:")) {
1451
+ currentEventType = line.slice(6).trim();
1452
+ dataAccumulator = "";
1453
+ continue;
1454
+ }
1455
+ if (line.startsWith("data:")) {
1456
+ const dataContent = line.slice(5).replace(/^ /, "");
1457
+ if (dataContent === "[DONE]") continue;
1458
+ if (currentEventType) {
1459
+ dataAccumulator += (dataAccumulator ? "\n" : "") + dataContent;
1460
+ } else {
1461
+ try {
1462
+ const data = JSON.parse(dataContent);
1463
+ const eventType = data["type"];
1464
+ if (eventType) {
1465
+ const geminiResp = convertParsedFrame(eventType, data);
1466
+ if (geminiResp) {
1467
+ yield geminiResp;
1468
+ }
1469
+ }
1470
+ } catch (err) {
1471
+ if (err instanceof SyntaxError) {
1472
+ debugLogger2.debug(
1473
+ `Failed to parse SSE data: ${dataContent.substring(0, 200)}`
1474
+ );
1475
+ } else {
1476
+ throw redactProxyError(err);
1477
+ }
1478
+ }
1479
+ }
1480
+ continue;
1481
+ }
1482
+ if (line.trim() === "" && currentEventType && dataAccumulator) {
1483
+ const geminiResp = parseSSEFrame(currentEventType, dataAccumulator);
1484
+ if (geminiResp) {
1485
+ yield geminiResp;
1486
+ }
1487
+ currentEventType = null;
1488
+ dataAccumulator = "";
1489
+ } else if (line.trim() === "") {
1490
+ currentEventType = null;
1491
+ dataAccumulator = "";
1492
+ }
1493
+ }
1494
+ }
1495
+ if (buffer.startsWith("data:")) {
1496
+ const dataContent = buffer.slice(5).replace(/^ /, "");
1497
+ if (dataContent !== "[DONE]") {
1498
+ if (currentEventType) {
1499
+ dataAccumulator += (dataAccumulator ? "\n" : "") + dataContent;
1500
+ } else {
1501
+ try {
1502
+ const data = JSON.parse(dataContent);
1503
+ const eventType = data["type"];
1504
+ if (eventType) {
1505
+ const geminiResp = convertParsedFrame(eventType, data);
1506
+ if (geminiResp) {
1507
+ yield geminiResp;
1508
+ }
1509
+ }
1510
+ } catch (err) {
1511
+ if (err instanceof SyntaxError) {
1512
+ debugLogger2.debug(
1513
+ `Failed to parse SSE data: ${dataContent.substring(0, 200)}`
1514
+ );
1515
+ } else {
1516
+ throw redactProxyError(err);
1517
+ }
1518
+ }
1519
+ }
1520
+ }
1521
+ }
1522
+ if (currentEventType && dataAccumulator) {
1523
+ const geminiResp = parseSSEFrame(currentEventType, dataAccumulator);
1524
+ if (geminiResp) {
1525
+ yield geminiResp;
1526
+ }
1527
+ }
1528
+ } finally {
1529
+ await reader.cancel().catch(() => {
1530
+ });
1531
+ reader.releaseLock();
1532
+ }
1533
+ }
1534
+ };
1535
+ var PROMPT_CACHE_KEY_MAX_LENGTH = 64;
1536
+ function sanitizePromptCacheKey(key) {
1537
+ if (key.length <= PROMPT_CACHE_KEY_MAX_LENGTH) return key;
1538
+ return createHash("sha256").update(key).digest("hex").slice(0, PROMPT_CACHE_KEY_MAX_LENGTH);
1539
+ }
1540
+ __name(sanitizePromptCacheKey, "sanitizePromptCacheKey");
1541
+ function mergeStreamResponses(chunks) {
1542
+ if (chunks.length === 0) {
1543
+ const empty = new GenerateContentResponse();
1544
+ empty.candidates = [];
1545
+ return empty;
1546
+ }
1547
+ if (chunks.length === 1) return chunks[0];
1548
+ const allParts = chunks.flatMap(
1549
+ (c) => c.candidates?.[0]?.content?.parts ?? []
1550
+ );
1551
+ const usageChunk = [...chunks].reverse().find((c) => c.usageMetadata);
1552
+ const finishChunk = [...chunks].reverse().find((c) => c.candidates?.[0]?.finishReason);
1553
+ const finishReason = finishChunk?.candidates?.[0]?.finishReason;
1554
+ const merged = new GenerateContentResponse();
1555
+ merged.responseId = chunks.find((c) => c.responseId)?.responseId;
1556
+ merged.modelVersion = chunks[0]?.modelVersion;
1557
+ merged.createTime = chunks[0]?.createTime;
1558
+ if (usageChunk?.usageMetadata) {
1559
+ merged.usageMetadata = usageChunk.usageMetadata;
1560
+ }
1561
+ merged.candidates = [
1562
+ {
1563
+ content: { parts: allParts, role: "model" },
1564
+ index: 0,
1565
+ safetyRatings: [],
1566
+ ...finishReason ? { finishReason } : {}
1567
+ }
1568
+ ];
1569
+ return merged;
1570
+ }
1571
+ __name(mergeStreamResponses, "mergeStreamResponses");
1572
+
1573
+ // packages/core/src/core/openaiResponsesContentGenerator/index.ts
1574
+ var debugLogger3 = createDebugLogger("RESPONSES");
1575
+ var OpenAIResponsesContentGenerator = class {
1576
+ static {
1577
+ __name(this, "OpenAIResponsesContentGenerator");
1578
+ }
1579
+ pipeline;
1580
+ contentGeneratorConfig;
1581
+ cliConfig;
1582
+ openaiClient = null;
1583
+ constructor(contentGeneratorConfig, cliConfig) {
1584
+ this.contentGeneratorConfig = contentGeneratorConfig;
1585
+ this.cliConfig = cliConfig;
1586
+ this.pipeline = new ResponsesPipeline(contentGeneratorConfig, cliConfig);
1587
+ }
1588
+ async getOpenAIClient() {
1589
+ if (this.openaiClient) return this.openaiClient;
1590
+ const OpenAISDK = (await import("./openai-WX26N5OJ.js")).default;
1591
+ const apiKey = this.contentGeneratorConfig.apiKey ?? (this.contentGeneratorConfig.apiKeyEnvKey ? process.env[this.contentGeneratorConfig.apiKeyEnvKey] : void 0);
1592
+ const runtimeOptions = buildRuntimeFetchOptions(
1593
+ "openai",
1594
+ this.cliConfig.getProxy()
1595
+ );
1596
+ const baseURL = this.contentGeneratorConfig.baseUrl ? `${this.contentGeneratorConfig.baseUrl.replace(/\/v1\/?$/, "").replace(/\/$/, "")}/v1` : void 0;
1597
+ this.openaiClient = new OpenAISDK({
1598
+ apiKey,
1599
+ baseURL,
1600
+ timeout: resolveRequestTimeout(this.contentGeneratorConfig.timeout),
1601
+ maxRetries: this.contentGeneratorConfig.maxRetries ?? DEFAULT_MAX_RETRIES,
1602
+ // Mirror the streaming pipeline (responses-pipeline.ts), which
1603
+ // applies customHeaders to every request -- without this, headers
1604
+ // configured for the streaming path (e.g. a proxy auth header)
1605
+ // silently don't reach embedContent's requests.
1606
+ ...this.contentGeneratorConfig.customHeaders ? { defaultHeaders: this.contentGeneratorConfig.customHeaders } : {},
1607
+ ...runtimeOptions || {}
1608
+ });
1609
+ return this.openaiClient;
1610
+ }
1611
+ async generateContent(request, userPromptId) {
1612
+ return this.pipeline.execute(
1613
+ request,
1614
+ userPromptId,
1615
+ request.config?.abortSignal ?? void 0
1616
+ );
1617
+ }
1618
+ async generateContentStream(request, userPromptId) {
1619
+ const signal = request.config?.abortSignal ?? void 0;
1620
+ return this.pipeline.connectStream(request, userPromptId, signal);
1621
+ }
1622
+ async embedContent(request) {
1623
+ const text = extractTextFromContents(request.contents);
1624
+ const client = await this.getOpenAIClient();
1625
+ try {
1626
+ const embedding = await client.embeddings.create({
1627
+ model: this.contentGeneratorConfig.model.includes("embed") ? this.contentGeneratorConfig.model : "text-embedding-ada-002",
1628
+ input: text
1629
+ });
1630
+ const first = embedding.data[0];
1631
+ if (!first) {
1632
+ throw new Error("Embedding API returned empty data array");
1633
+ }
1634
+ return {
1635
+ embeddings: [{ values: first.embedding }]
1636
+ };
1637
+ } catch (error) {
1638
+ const redactedError = redactProxyError(error);
1639
+ debugLogger3.error("Embedding error:", redactedError);
1640
+ throw new Error(
1641
+ `Embedding error: ${redactedError instanceof Error ? redactedError.message : String(redactedError)}`
1642
+ );
1643
+ }
1644
+ }
1645
+ };
1646
+ function createOpenAIResponsesContentGenerator(contentGeneratorConfig, cliConfig) {
1647
+ return new OpenAIResponsesContentGenerator(contentGeneratorConfig, cliConfig);
1648
+ }
1649
+ __name(createOpenAIResponsesContentGenerator, "createOpenAIResponsesContentGenerator");
1650
+ export {
1651
+ OpenAIResponsesContentGenerator,
1652
+ createOpenAIResponsesContentGenerator
1653
+ };
1654
+ /**
1655
+ * @license
1656
+ * Copyright 2025 Qwen
1657
+ * SPDX-License-Identifier: Apache-2.0
1658
+ */