@qwen-code/qwen-code 0.20.2-headless-image-routing.1 → 0.21.0
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.
- package/bundled/qc-helper/docs/configuration/settings.md +5 -0
- package/bundled/qc-helper/docs/features/sub-agents.md +23 -5
- package/bundled/qc-helper/docs/integration-github-action.md +9 -9
- package/bundled/review/SKILL.md +7 -3
- package/chunks/MaxSizedBox-5DPPWPGT.js +85 -0
- package/chunks/{StandaloneSessionPicker-PLQQB22E.js → StandaloneSessionPicker-BIRMPLRD.js} +66 -59
- package/chunks/{acp-startup-profiler-N3RHHXJ3.js → acp-startup-profiler-RV3IV562.js} +2 -2
- package/chunks/{acpAgent-AIVK2EM5.js → acpAgent-6J2U72PQ.js} +705 -182
- package/chunks/agent-6ODUANDO.js +81 -0
- package/chunks/agent-headless-7BYQTMHW.js +75 -0
- package/chunks/{anthropicContentGenerator-HGWAHO24.js → anthropicContentGenerator-75BKLTSP.js} +117 -43
- package/chunks/{artifact-tool-56T5IMBP.js → artifact-tool-Y5T7GG7F.js} +3 -3
- package/chunks/{askUserQuestion-E25OBIC2.js → askUserQuestion-2H6747FR.js} +3 -3
- package/chunks/bridge-ZUB64FAE.js +90 -0
- package/chunks/{build-GHIZ4MSZ.js → build-RV63TIRH.js} +2 -3
- package/chunks/{ca-N6VVUFVB.js → ca-25EDXPFZ.js} +2 -0
- package/chunks/{channel-worker-group-QZV2SP5U.js → channel-worker-group-2ZD7TVAT.js} +8 -7
- package/chunks/{channel-worker-manager-3GMAU45H.js → channel-worker-manager-4OA4BCGB.js} +190 -30
- package/chunks/{channel-worker-supervisor-QCXSXCRY.js → channel-worker-supervisor-V7KCFJTS.js} +7 -6
- package/chunks/{chunk-TYQMGACW.js → chunk-22C7BQ6D.js} +508 -10967
- package/chunks/chunk-2JZBVYTU.js +452 -0
- package/chunks/{chunk-H2XVO6NE.js → chunk-2MIN6GRR.js} +1 -1
- package/chunks/{chunk-4DWTDZGS.js → chunk-2NH6DYI4.js} +12 -12
- package/chunks/chunk-2SCDWPXI.js +246 -0
- package/chunks/{chunk-QE4KFTBS.js → chunk-2X55UKQE.js} +3 -3
- package/chunks/{chunk-QBUDF33N.js → chunk-3QMGYBFN.js} +1 -1
- package/chunks/{chunk-3OAKYHRG.js → chunk-3RN6GBKS.js} +1 -1
- package/chunks/{chunk-QR6U5QPP.js → chunk-3SJ43L4W.js} +4 -0
- package/chunks/chunk-46UV252V.js +128 -0
- package/chunks/{chunk-GHRSKGHF.js → chunk-4WIZGAH3.js} +7 -7
- package/chunks/{chunk-CAS7CB3T.js → chunk-55DJUCI2.js} +87 -29
- package/chunks/{chunk-QNLNLENL.js → chunk-5I2IWRSH.js} +2 -2
- package/chunks/{chunk-H24SOJIQ.js → chunk-5NBDS5S6.js} +147 -7
- package/chunks/{chunk-E4IMU4Y5.js → chunk-63P4EL5V.js} +1 -1
- package/chunks/chunk-6FGBXPWM.js +293 -0
- package/chunks/{chunk-FFFM6NJV.js → chunk-6GMVPFB2.js} +155 -73
- package/chunks/{chunk-KWK7UE6L.js → chunk-6OUGMXDC.js} +6 -6
- package/chunks/{chunk-QRUIS3DN.js → chunk-6PEXNQTX.js} +22 -1
- package/chunks/{chunk-FZPTCQY7.js → chunk-7JURR4JT.js} +1 -1
- package/chunks/{chunk-Q6NAKZTA.js → chunk-7MVVZO4N.js} +4 -4
- package/chunks/{chunk-6ZBPS62S.js → chunk-7ZCNENPP.js} +1 -1
- package/chunks/{chunk-6X4GWOPW.js → chunk-A5L3JMUA.js} +1 -1
- package/chunks/{chunk-YO2XRXY6.js → chunk-ACY3A37B.js} +3 -3
- package/chunks/chunk-AMDSOFFV.js +10860 -0
- package/chunks/{chunk-RV4C2ZFG.js → chunk-BIQWWWJN.js} +1 -1
- package/chunks/{chunk-ZHERRXZJ.js → chunk-BJX6ZSUK.js} +4 -4
- package/chunks/chunk-BK2UNYWD.js +29 -0
- package/chunks/{chunk-FRPDJNK3.js → chunk-BKHWX6I2.js} +3 -3
- package/chunks/chunk-BPJSQIJX.js +100 -0
- package/chunks/{chunk-M7WBGLYP.js → chunk-BULDBTYC.js} +2 -0
- package/chunks/{chunk-ZDP2Y2AL.js → chunk-CIKQ7KKO.js} +4625 -8645
- package/chunks/{chunk-PEJWA3QQ.js → chunk-D3UEZIQH.js} +4 -2
- package/chunks/chunk-DHHOYAPR.js +1462 -0
- package/chunks/{chunk-LESHKUWF.js → chunk-DLWL3Z7A.js} +5 -3
- package/chunks/{chunk-XHATNRQA.js → chunk-DP3IHZGG.js} +0 -2
- package/chunks/chunk-E5TUC6CA.js +479 -0
- package/chunks/{chunk-JC26SJ5Y.js → chunk-EBJQ6AXW.js} +13 -12
- package/chunks/{chunk-RCWKCN2Z.js → chunk-EPDRMGT4.js} +164 -17
- package/chunks/{chunk-FUFCALSJ.js → chunk-ETSW4KLJ.js} +2 -2
- package/chunks/{chunk-KHOVYUHX.js → chunk-FNQ6T3CV.js} +20 -3
- package/chunks/{chunk-SP5WRGVG.js → chunk-FQK6JAFG.js} +72 -23
- package/chunks/{chunk-NWZY2SPY.js → chunk-FSITMZJH.js} +8 -8
- package/chunks/{chunk-6RLROE6G.js → chunk-GLWP3FDB.js} +80 -15
- package/chunks/{chunk-KPBVP6SL.js → chunk-GSN55ZRI.js} +5 -5
- package/chunks/{chunk-MLYGPZGU.js → chunk-H4SBPHSA.js} +3 -3
- package/chunks/chunk-H5FFA6TH.js +902 -0
- package/chunks/{chunk-TDKQP3M6.js → chunk-HIJQF5B5.js} +1 -1
- package/chunks/{chunk-5G3ZVADU.js → chunk-IJTOWOD7.js} +17 -6
- package/chunks/chunk-IKCX4CCL.js +469 -0
- package/chunks/{chunk-LPEONXNV.js → chunk-IKYJHJNF.js} +3 -3
- package/chunks/{chunk-DTZY2SH2.js → chunk-IO3IX5Q4.js} +1 -1
- package/chunks/{chunk-RS7MT2QG.js → chunk-IPUUTYMV.js} +2 -4
- package/chunks/{chunk-XU457J4V.js → chunk-IRH27ZC2.js} +2 -2
- package/chunks/{chunk-46DK772E.js → chunk-J24WCGIN.js} +4 -4
- package/chunks/{chunk-4LVZNIDO.js → chunk-J56UI34H.js} +4 -13
- package/chunks/{chunk-TJTKSVIV.js → chunk-JLU636DO.js} +5 -1
- package/chunks/{chunk-RKWX4CMO.js → chunk-JVPM2ULZ.js} +6 -6
- package/chunks/{chunk-ENPCQK44.js → chunk-JXJFVC6E.js} +37 -18
- package/chunks/{chunk-NABLFI57.js → chunk-JZA3JUDJ.js} +1 -1
- package/chunks/{chunk-CGLQAVZE.js → chunk-K36B6G2O.js} +5 -5
- package/chunks/{chunk-GPSKDNEE.js → chunk-K4XWPEWB.js} +4 -4
- package/chunks/{chunk-QOZOIPSF.js → chunk-KIM5GUMA.js} +650 -113
- package/chunks/{chunk-JZSM2IZ3.js → chunk-KMQ33DO4.js} +7 -5
- package/chunks/{chunk-E2UVIFI2.js → chunk-KRXPRVGL.js} +0 -1
- package/chunks/{chunk-WHGVTP7Q.js → chunk-L26JL52R.js} +3 -3
- package/chunks/{chunk-7Z6JQEL6.js → chunk-L5UHQJTJ.js} +1 -1
- package/chunks/{chunk-O2XSCRCS.js → chunk-LB6DUZ26.js} +259 -67
- package/chunks/chunk-LEH5C7FV.js +232 -0
- package/chunks/{chunk-RWV32G2M.js → chunk-LH2BYDQ5.js} +6 -4
- package/chunks/{chunk-QKTHJXCS.js → chunk-LK7CHLVP.js} +79 -2
- package/chunks/{chunk-VRRF3GW5.js → chunk-LKEJ26GS.js} +11 -11
- package/chunks/{chunk-SQFXI7VK.js → chunk-LQIW3YFY.js} +227 -41
- package/chunks/chunk-LS77BEZP.js +405 -0
- package/chunks/{chunk-BSHD62QJ.js → chunk-M4FMGVY4.js} +3 -3
- package/chunks/{chunk-57FIIFJN.js → chunk-M5JM7OSF.js} +1 -1
- package/chunks/{chunk-7362QS5B.js → chunk-MB4MZHMJ.js} +80 -37
- package/chunks/{chunk-4K56OJFJ.js → chunk-MUP3T3AD.js} +1 -1
- package/chunks/{chunk-3HFNGB2O.js → chunk-MVSUYZDT.js} +4 -4
- package/chunks/{chunk-T5IO6FZ4.js → chunk-MZAXJAUM.js} +1 -1
- package/chunks/{chunk-QKNXKTZX.js → chunk-NH6KE4JX.js} +3 -3
- package/chunks/chunk-NIBLUX3Y.js +934 -0
- package/chunks/{chunk-OQB4EXO4.js → chunk-NL7LTRLR.js} +1 -1
- package/chunks/{chunk-CS2FSS7W.js → chunk-OFDOK3VM.js} +5 -5
- package/chunks/{chunk-LIZRAKPB.js → chunk-OHNBB4XR.js} +1 -1
- package/chunks/{chunk-MDZTPSXO.js → chunk-OKY7HXPG.js} +2 -2
- package/chunks/{chunk-NHDKSOEY.js → chunk-P3QQPMQA.js} +5 -5
- package/chunks/{chunk-7THPNISK.js → chunk-PC6JANNU.js} +5 -5
- package/chunks/{chunk-OTQ6PSZC.js → chunk-PHOF65IG.js} +3498 -1030
- package/chunks/{chunk-OQ5SYCPE.js → chunk-PJIZUQVC.js} +2 -2
- package/chunks/{chunk-5DTTYNB7.js → chunk-PQNHRFJC.js} +16 -3
- package/chunks/{chunk-YM3SZTH4.js → chunk-PR75REBZ.js} +18 -1
- package/chunks/{chunk-RECUEJ7B.js → chunk-PSOO6YXD.js} +18 -15
- package/chunks/{chunk-X6N25LXS.js → chunk-PWTZEM3C.js} +2 -2
- package/chunks/{chunk-5NJTNQUW.js → chunk-PWVFN2LF.js} +1 -1
- package/chunks/{chunk-7AUH6A4T.js → chunk-Q4M4MDQ4.js} +2 -2
- package/chunks/{chunk-EZPB6S2I.js → chunk-QAF7NMK7.js} +1 -1
- package/chunks/{chunk-5GI55PF5.js → chunk-R5AFZNQW.js} +5 -5
- package/chunks/{chunk-T5B5NQZX.js → chunk-RF3EXIHJ.js} +47 -60
- package/chunks/{chunk-4K7VDKAD.js → chunk-RHLZR4E5.js} +1 -1
- package/chunks/{chunk-TJDW42MV.js → chunk-RIBKPMRP.js} +220 -141
- package/chunks/{chunk-RVLZCXEE.js → chunk-RWTEFFPU.js} +82 -3
- package/chunks/{chunk-L5QZGCRH.js → chunk-RZIX2G32.js} +1 -1
- package/chunks/{chunk-LLKWRXSS.js → chunk-SQCQ4KO2.js} +350 -418
- package/chunks/{chunk-THJNPLI4.js → chunk-TARRHLLG.js} +1 -0
- package/chunks/{chunk-XCXYRDHB.js → chunk-TEHGS6UP.js} +47 -18
- package/chunks/{chunk-PQIVAWXN.js → chunk-TGILQ3YH.js} +8 -8
- package/chunks/{chunk-Q2YKNMLS.js → chunk-TOFQCPDC.js} +43 -10
- package/chunks/{chunk-L3KUB6XM.js → chunk-TPRQ7RZH.js} +586 -242
- package/chunks/{chunk-T4TZQJ7W.js → chunk-TWPJO254.js} +5 -16
- package/chunks/{chunk-HIP6TVWA.js → chunk-U7M2DMGW.js} +3 -3
- package/chunks/{chunk-ACW3VNUE.js → chunk-UDX5OBWR.js} +41 -9
- package/chunks/{chunk-LW2FUYBN.js → chunk-USTWD7QV.js} +6 -4
- package/chunks/{chunk-NPQDJGKU.js → chunk-UUUTRMI2.js} +1 -1
- package/chunks/chunk-UW5EOVUN.js +249 -0
- package/chunks/{chunk-6IL7KRLE.js → chunk-VAK25FTU.js} +1 -1
- package/chunks/{chunk-O4BHWVUD.js → chunk-VIA5XA4U.js} +5 -2
- package/chunks/{chunk-EBXZ2YGV.js → chunk-VRYUBFMC.js} +1 -1
- package/chunks/{chunk-TWVE5ZS5.js → chunk-VULLI6WQ.js} +172 -6
- package/chunks/{chunk-LNDD3IML.js → chunk-WCXCRJYB.js} +1 -1
- package/chunks/{chunk-2LI23QA6.js → chunk-X5XDDSSH.js} +1 -1
- package/chunks/{chunk-Q35QUZDQ.js → chunk-Y34KJKDC.js} +1 -1
- package/chunks/{chunk-7NR2AIK6.js → chunk-YBL3QUDD.js} +2 -2
- package/chunks/{chunk-H4AR2JQF.js → chunk-YH6G52F2.js} +3 -3
- package/chunks/{chunk-MBOJHHPI.js → chunk-YPE6A4GC.js} +2 -2
- package/chunks/{chunk-3EK5ZOUQ.js → chunk-YX324OPW.js} +1 -1
- package/chunks/{chunk-4PTLZ3NX.js → chunk-Z2BC6UJ5.js} +3 -3
- package/chunks/{chunk-QLJUC7TG.js → chunk-ZD6UTE4A.js} +1 -1
- package/chunks/{chunk-LX3COOXF.js → chunk-ZFDTEDCF.js} +6 -6
- package/chunks/chunk-ZJHVAS7M.js +289 -0
- package/chunks/{chunk-4OWXOUYF.js → chunk-ZNAUOR2I.js} +15 -12
- package/chunks/{chunk-T2L47JJK.js → chunk-ZOIFNCKL.js} +4 -4
- package/chunks/{computer-use-2VIV73WK.js → computer-use-SOQ4E3VX.js} +43 -35
- package/chunks/{config-utils-FYTBZLCJ.js → config-utils-7V7GGIW6.js} +3 -3
- package/chunks/contextCommand-JLHYA34Z.js +80 -0
- package/chunks/{create-sub-session-AZ77LBL3.js → create-sub-session-IWW2IZ2T.js} +3 -3
- package/chunks/{create-sub-session-XDHHC2P4.js → create-sub-session-QRJLW5BV.js} +43 -35
- package/chunks/{cron-create-KTWJM7QT.js → cron-create-YIID5XAW.js} +6 -6
- package/chunks/{cron-delete-2P3I5ULL.js → cron-delete-ZVHYCEP2.js} +5 -5
- package/chunks/{cron-list-PXDPGEDQ.js → cron-list-XEGS463Q.js} +5 -5
- package/chunks/{daemon-RAPSDJH7.js → daemon-YO6433NF.js} +350 -53
- package/chunks/daemon-status-provider-2233Q37D.js +89 -0
- package/chunks/{de-4IBXM7CN.js → de-HGRCYDEJ.js} +1 -0
- package/chunks/{dist-UIFWIFRO.js → dist-46NQKLTW.js} +2 -2
- package/chunks/{dist-XRYV6TJP.js → dist-AIKFMUKK.js} +50 -4
- package/chunks/{dist-XBJVSWS2.js → dist-BBLXMS3N.js} +14 -2
- package/chunks/{dist-OMW6WDEO.js → dist-F6IBUDR4.js} +40 -9
- package/chunks/{dist-PJLG2XYX.js → dist-WEAHOXDM.js} +1 -1
- package/chunks/{dist-OAV7LJGJ.js → dist-YFNEUWSE.js} +26 -2
- package/chunks/earlyInputCapture-A7NDU3PF.js +82 -0
- package/chunks/{edit-CS6SFEXC.js → edit-OBDSQURM.js} +43 -35
- package/chunks/{en-USMCCJAJ.js → en-MTWBNGDO.js} +15 -0
- package/chunks/{enter-worktree-LMAL75DY.js → enter-worktree-U6MRPQ2P.js} +43 -35
- package/chunks/{enterPlanMode-WVJB4DSS.js → enterPlanMode-BC5QUZZ2.js} +43 -35
- package/chunks/{environment-6YHC4JAJ.js → environment-W5UFC2CH.js} +46 -38
- package/chunks/errors-M7CLORXH.js +88 -0
- package/chunks/{exit-worktree-KPFD742L.js → exit-worktree-DGNYMECB.js} +43 -35
- package/chunks/{exitPlanMode-UEJS6CDY.js → exitPlanMode-GXTBWQAR.js} +43 -35
- package/chunks/{fast-path-G2N4NRCA.js → fast-path-JJZFJANL.js} +6 -6
- package/chunks/{fast-path-settings-DAOVFADC.js → fast-path-settings-WQJU2LAT.js} +2 -2
- package/chunks/{fr-WVHEBDDB.js → fr-45RLL55O.js} +1 -0
- package/chunks/{gemini-2MDVIOVT.js → gemini-QS36EBZV.js} +132 -102
- package/chunks/{geminiContentGenerator-ZXTDBMFR.js → geminiContentGenerator-AG4KB6CV.js} +14 -8
- package/chunks/{getMachineId-bsd-QFVLPUPT.js → getMachineId-bsd-V7W3GODC.js} +1 -1
- package/chunks/{getMachineId-darwin-DGMQQE2E.js → getMachineId-darwin-TDO75DQP.js} +1 -1
- package/chunks/{getMachineId-linux-R4Z6CSWC.js → getMachineId-linux-TF43WQT2.js} +1 -1
- package/chunks/{getMachineId-unsupported-Z3SBVBUV.js → getMachineId-unsupported-ZGUO3TXT.js} +1 -1
- package/chunks/{getMachineId-win-SCK5UFDT.js → getMachineId-win-ECFYZZFQ.js} +1 -1
- package/chunks/{glob-562XFLIZ.js → glob-V7R3PSK3.js} +43 -35
- package/chunks/{grep-MGEFBDQK.js → grep-QYPSK7OP.js} +43 -35
- package/chunks/handleAutoUpdate-6DBEZYPV.js +81 -0
- package/chunks/{i18n-R6HJENXA.js → i18n-VUJJZIMU.js} +44 -36
- package/chunks/image-gen-Z3VPGKRC.js +240 -0
- package/chunks/initializer-UWAK5U5O.js +86 -0
- package/chunks/installationInfo-6O2YAA52.js +80 -0
- package/chunks/{ja-KY4ROZTE.js → ja-B7DF7DFG.js} +1 -0
- package/chunks/{keychain-token-storage-6ACJDYIB.js → keychain-token-storage-MDTG3WRM.js} +3 -3
- package/chunks/{kittyProtocolDetector-HCNNKJTI.js → kittyProtocolDetector-MBRTDRBK.js} +5 -3
- package/chunks/list-GB4ESM3T.js +89 -0
- package/chunks/list-agents-5KJJHR6I.js +80 -0
- package/chunks/loadedSettingsAdapter-OT6JVQ7U.js +83 -0
- package/chunks/loggingContentGenerator-HS3S5H3Q.js +1077 -0
- package/chunks/{loop-wakeup-RNMRVA66.js → loop-wakeup-FXKNNYSY.js} +7 -7
- package/chunks/{ls-J2ZI5XYK.js → ls-NTK6VOQJ.js} +5 -5
- package/chunks/{lsp-UMS3NUB5.js → lsp-2JI24STP.js} +3 -3
- package/chunks/{managed-npm-update-4KNYSOYC.js → managed-npm-update-JYEMMXA3.js} +94 -38
- package/chunks/mcp-6DBDJPFU.js +83 -0
- package/chunks/{monitor-DMHKE4SW.js → monitor-R3ODH5U6.js} +45 -36
- package/chunks/node-UUDY34IG.js +305 -0
- package/chunks/nonInteractiveCli-MOYCYBBU.js +141 -0
- package/chunks/{notebook-edit-35SJGEOR.js → notebook-edit-BNOK452R.js} +43 -35
- package/chunks/{openaiContentGenerator-5LPAFXPF.js → openaiContentGenerator-WMCU3O2H.js} +27 -17
- package/chunks/pidfile-TFRZZZIO.js +86 -0
- package/chunks/{processUtils-GM2I55KF.js → processUtils-RT7UNCC2.js} +2 -2
- package/chunks/{pt-OK455PLH.js → pt-22Q3FP73.js} +1 -0
- package/chunks/{qwenContentGenerator-HKOYNP7H.js → qwenContentGenerator-HHCRK4SX.js} +56 -42
- package/chunks/{qwenOAuth2-NUUYC3V5.js → qwenOAuth2-OWLB5AKH.js} +14 -27
- package/chunks/read-file-APMO3PSX.js +31 -0
- package/chunks/{read-mcp-resource-F6HYMDUY.js → read-mcp-resource-4DKQWGHD.js} +3 -3
- package/chunks/{record-artifact-7GCFLDD7.js → record-artifact-RQKFYO5B.js} +3 -3
- package/chunks/resumeHistoryUtils-6KRYEAWZ.js +91 -0
- package/chunks/ripGrep-BEJDEDXW.js +73 -0
- package/chunks/{ru-7SPDGMGD.js → ru-FZCNZHDC.js} +1 -0
- package/chunks/{run-qwen-serve-5VH3F4NW.js → run-qwen-serve-FU6HEM4J.js} +271 -57
- package/chunks/{runtime-OH77YH7W.js → runtime-XXRRTNP6.js} +55 -45
- package/chunks/{scheduler-WJQSLCSV.js → scheduler-G2ZS2Z7E.js} +43 -35
- package/chunks/{sdk-exporters-grpc-ETLH47EP.js → sdk-exporters-grpc-AK3LGHNO.js} +3 -3
- package/chunks/{sdk-exporters-http-T3POX73F.js → sdk-exporters-http-FYBSUCPD.js} +6 -6
- package/chunks/{sdk-impl-NSLPDH6I.js → sdk-impl-GMVPB7NB.js} +6 -6
- package/chunks/{send-message-PYIJ2PZL.js → send-message-Q6OOR6BR.js} +46 -9
- package/chunks/serve-7BSTXJ4T.js +89 -0
- package/chunks/{server-E4N4AI6Z.js → server-4UMH7OIZ.js} +2362 -411
- package/chunks/{session-5YUWIOQE.js → session-K3O3Q2SV.js} +105 -87
- package/chunks/{settings-YY7ZSFO7.js → settings-CR2EWTBA.js} +53 -45
- package/chunks/shell-HH3PF3A2.js +83 -0
- package/chunks/{skill-PAIDX3EU.js → skill-I3SDA4MB.js} +17 -16
- package/chunks/spawnChannel-RWNDBXGA.js +82 -0
- package/chunks/{src-IZXLJI5M.js → src-GE4TTTML.js} +302 -184
- package/chunks/{standalone-update-X675JVBL.js → standalone-update-Q6WFRZZQ.js} +45 -37
- package/chunks/{startInteractiveUI-ND2IVBU3.js → startInteractiveUI-SLZGHRPH.js} +747 -310
- package/chunks/{syntheticOutput-H7RTI5KL.js → syntheticOutput-I3757IWH.js} +4 -4
- package/chunks/{task-create-7474AJJD.js → task-create-N7WQSGYA.js} +10 -10
- package/chunks/{task-list-633HGOIB.js → task-list-FOPULZEP.js} +7 -7
- package/chunks/{task-stop-MNUGHPIA.js → task-stop-H6RHXFVQ.js} +4 -4
- package/chunks/{task-update-66GQB5LI.js → task-update-M57TFZJT.js} +10 -10
- package/chunks/{team-create-2DEYNMMN.js → team-create-YJALH5D2.js} +46 -38
- package/chunks/{team-delete-BB3CG3QF.js → team-delete-QE2UXJL7.js} +7 -7
- package/chunks/{team-plan-approval-65AVAOCT.js → team-plan-approval-34QFYKGN.js} +43 -35
- package/chunks/theme-manager-SWRILQHI.js +77 -0
- package/chunks/{todoWrite-KRAUN54W.js → todoWrite-VQ7FKOHL.js} +5 -5
- package/chunks/{tool-search-ZQP3SMTV.js → tool-search-NF7GB6LE.js} +16 -16
- package/chunks/total-session-admission-DLHHHLD3.js +84 -0
- package/chunks/{tree-sitter-FS4VPMZA.js → tree-sitter-4D7QS7F6.js} +1 -1
- package/chunks/{tree-sitter-bash-6B46JJCV.js → tree-sitter-bash-VEJGF5XF.js} +1 -1
- package/chunks/{trustedFolders-LURI52LP.js → trustedFolders-KHXHY6PY.js} +44 -36
- package/chunks/{update-relaunch-BPWFIDLM.js → update-relaunch-WBUZJC5O.js} +5 -5
- package/chunks/updateCheck-RKL6M5XN.js +92 -0
- package/chunks/useAutoAcceptIndicator-CFQ5BUJL.js +93 -0
- package/chunks/{validateNonInterActiveAuth-HWD6Y22I.js → validateNonInterActiveAuth-3R223G3R.js} +89 -80
- package/chunks/{version-OD4JAFG7.js → version-HS7YSFHV.js} +1 -1
- package/chunks/{web-fetch-RFBKNU24.js → web-fetch-NKCSG7ZE.js} +18 -16
- package/chunks/{web-search-AKTVS5YZ.js → web-search-S62WAP4S.js} +13 -27
- package/chunks/{workflow-VZVCOSZN.js → workflow-QAGU5RU4.js} +44 -36
- package/chunks/workspace-providers-status-QSVZUETE.js +86 -0
- package/chunks/{workspace-registration-store-Q5SFJSX4.js → workspace-registration-store-24JMHDGF.js} +2 -2
- package/chunks/workspace-registry-UT4RBNBM.js +88 -0
- package/chunks/workspace-service-JFWRUS4V.js +98 -0
- package/chunks/workspace-skills-status-ZBBKJOI2.js +85 -0
- package/chunks/write-file-VHIXW5M7.js +73 -0
- package/chunks/{zh-WY5DWYZD.js → zh-LUIGBD55.js} +15 -0
- package/chunks/{zh-TW-BM47YBFH.js → zh-TW-F5KG2IYD.js} +15 -0
- package/cli-entry.js +10 -1
- package/cli.js +13 -13
- package/locales/ca.js +2 -0
- package/locales/de.js +1 -0
- package/locales/en.js +25 -0
- package/locales/fr.js +1 -0
- package/locales/ja.js +1 -0
- package/locales/pt.js +1 -0
- package/locales/ru.js +1 -0
- package/locales/zh-TW.js +23 -0
- package/locales/zh.js +23 -0
- package/package.json +3 -3
- package/web-shell/assets/{arc-BWFm0SI0.js → arc-DcbWnB9T.js} +1 -1
- package/web-shell/assets/{architectureDiagram-3BPJPVTR-CZ_yL-DQ.js → architectureDiagram-3BPJPVTR-kMMF5sud.js} +1 -1
- package/web-shell/assets/{blockDiagram-GPEHLZMM-B9F9mJvG.js → blockDiagram-GPEHLZMM-Htl9vTJS.js} +1 -1
- package/web-shell/assets/{c4Diagram-AAUBKEIU-BUdwJW5f.js → c4Diagram-AAUBKEIU-BnZnm0mQ.js} +1 -1
- package/web-shell/assets/channel-Cq7YKtfC.js +1 -0
- package/web-shell/assets/{chunk-2J33WTMH-w4cF-qlF.js → chunk-2J33WTMH-DziB7kDG.js} +1 -1
- package/web-shell/assets/{chunk-4BX2VUAB-BXwURxHJ.js → chunk-4BX2VUAB-CmkD8daw.js} +1 -1
- package/web-shell/assets/{chunk-55IACEB6-Gem3LalC.js → chunk-55IACEB6-CHAd9A_U.js} +1 -1
- package/web-shell/assets/{chunk-727SXJPM-A3ddVojI.js → chunk-727SXJPM-Dqaam3fE.js} +1 -1
- package/web-shell/assets/{chunk-AQP2D5EJ-CjHZ5L_R.js → chunk-AQP2D5EJ-D_-saBYM.js} +1 -1
- package/web-shell/assets/{chunk-FMBD7UC4-CKgdgcpv.js → chunk-FMBD7UC4-B9r_veWD.js} +1 -1
- package/web-shell/assets/{chunk-ND2GUHAM-Cn2Dykjb.js → chunk-ND2GUHAM-B3EaCSpL.js} +1 -1
- package/web-shell/assets/{chunk-QZHKN3VN--0SyraC5.js → chunk-QZHKN3VN-CYq8x9mn.js} +1 -1
- package/web-shell/assets/classDiagram-4FO5ZUOK-CQ9aC1Tg.js +1 -0
- package/web-shell/assets/classDiagram-v2-Q7XG4LA2-CQ9aC1Tg.js +1 -0
- package/web-shell/assets/{cose-bilkent-S5V4N54A-CphhAity.js → cose-bilkent-S5V4N54A-D0ng4uiB.js} +1 -1
- package/web-shell/assets/{dagre-BM42HDAG-DU--jiKp.js → dagre-BM42HDAG-DCZollQv.js} +1 -1
- package/web-shell/assets/{diagram-2AECGRRQ-BzvuZw1Y.js → diagram-2AECGRRQ-Dfk2pWS0.js} +1 -1
- package/web-shell/assets/{diagram-5GNKFQAL-D84-49Y0.js → diagram-5GNKFQAL-kX38ltWR.js} +1 -1
- package/web-shell/assets/{diagram-KO2AKTUF-DQTq-3_3.js → diagram-KO2AKTUF-CJz2vsXh.js} +1 -1
- package/web-shell/assets/{diagram-LMA3HP47-8FTrshzN.js → diagram-LMA3HP47-BvMLZm_7.js} +1 -1
- package/web-shell/assets/{diagram-OG6HWLK6-BCjpDBCm.js → diagram-OG6HWLK6-l7kfStkO.js} +1 -1
- package/web-shell/assets/{erDiagram-TEJ5UH35-BtRObkmg.js → erDiagram-TEJ5UH35-BSVa8GGT.js} +1 -1
- package/web-shell/assets/{flowDiagram-I6XJVG4X-DTrW6oxy.js → flowDiagram-I6XJVG4X-CoawKIXH.js} +1 -1
- package/web-shell/assets/{ganttDiagram-6RSMTGT7-BgPNSW6j.js → ganttDiagram-6RSMTGT7-DFUDH0zF.js} +1 -1
- package/web-shell/assets/{gitGraphDiagram-PVQCEYII-BTclNgGV.js → gitGraphDiagram-PVQCEYII-Y2pvpT4e.js} +1 -1
- package/web-shell/assets/{index-CxA7AqY6.js → index-D0GX0zZf.js} +1 -1
- package/web-shell/assets/index-D9haPt0X.css +5 -0
- package/web-shell/assets/index-ckX9Pq5k.js +1230 -0
- package/web-shell/assets/{infoDiagram-5YYISTIA-DCE4AJt2.js → infoDiagram-5YYISTIA-CU8_zLiX.js} +1 -1
- package/web-shell/assets/{ishikawaDiagram-YF4QCWOH-C8iE6q4Y.js → ishikawaDiagram-YF4QCWOH-AVQiV0DU.js} +1 -1
- package/web-shell/assets/{journeyDiagram-JHISSGLW-C_dxdyEc.js → journeyDiagram-JHISSGLW-DQ0VSKa3.js} +1 -1
- package/web-shell/assets/{kanban-definition-UN3LZRKU-Dw3n1u3w.js → kanban-definition-UN3LZRKU-BqnWqsE_.js} +1 -1
- package/web-shell/assets/{linear-C2BF2zJ9.js → linear-BkoihsaA.js} +1 -1
- package/web-shell/assets/{mermaid.core-CGTQU3MA.js → mermaid.core-5RJs-31j.js} +5 -5
- package/web-shell/assets/{mindmap-definition-RKZ34NQL-BVFZm9ZC.js → mindmap-definition-RKZ34NQL-D33Bxnpd.js} +1 -1
- package/web-shell/assets/{pieDiagram-4H26LBE5-Cc-TNN3n.js → pieDiagram-4H26LBE5-BuEAw3BH.js} +1 -1
- package/web-shell/assets/{quadrantDiagram-W4KKPZXB-CgW3Rzsi.js → quadrantDiagram-W4KKPZXB-Kox_usEq.js} +1 -1
- package/web-shell/assets/{requirementDiagram-4Y6WPE33-BAaj0Y3B.js → requirementDiagram-4Y6WPE33-CNjeUif0.js} +1 -1
- package/web-shell/assets/{sankeyDiagram-5OEKKPKP-XJWmekxS.js → sankeyDiagram-5OEKKPKP-BCd2OL_U.js} +1 -1
- package/web-shell/assets/{sequenceDiagram-3UESZ5HK-CtRc_0wf.js → sequenceDiagram-3UESZ5HK-CF2ZTsz0.js} +1 -1
- package/web-shell/assets/{stateDiagram-AJRCARHV-WCnvMGy5.js → stateDiagram-AJRCARHV-qenSzHtm.js} +1 -1
- package/web-shell/assets/stateDiagram-v2-BHNVJYJU-B7W4zlCr.js +1 -0
- package/web-shell/assets/{timeline-definition-PNZ67QCA-C9cRx49L.js → timeline-definition-PNZ67QCA-B5DyWdgs.js} +1 -1
- package/web-shell/assets/{vennDiagram-CIIHVFJN-BvXOCEt-.js → vennDiagram-CIIHVFJN-DqP4I_o_.js} +1 -1
- package/web-shell/assets/{wardley-L42UT6IY-ByafGtzu.js → wardley-L42UT6IY-CJe2e4mg.js} +1 -1
- package/web-shell/assets/{wardleyDiagram-YWT4CUSO-CozAnw8x.js → wardleyDiagram-YWT4CUSO-BMDSw-Rr.js} +1 -1
- package/web-shell/assets/{xychartDiagram-2RQKCTM6-Camu9Qvq.js → xychartDiagram-2RQKCTM6-BTVZYkxD.js} +1 -1
- package/web-shell/index.html +17 -13
- package/chunks/MaxSizedBox-3XQIBACV.js +0 -78
- package/chunks/agent-QXD5NSKA.js +0 -73
- package/chunks/agent-headless-4VXR2TBK.js +0 -67
- package/chunks/bridge-GIBRSPE6.js +0 -81
- package/chunks/chunk-CBOQ3HY7.js +0 -2019
- package/chunks/chunk-MA6GYKK7.js +0 -6928
- package/chunks/contextCommand-XQU7KLIH.js +0 -72
- package/chunks/daemon-status-provider-KQVNB4VA.js +0 -80
- package/chunks/earlyInputCapture-WP5SA3KH.js +0 -74
- package/chunks/errors-JEYPXX4S.js +0 -80
- package/chunks/handleAutoUpdate-2VJPAW43.js +0 -73
- package/chunks/initializer-UOX67ZFQ.js +0 -78
- package/chunks/installationInfo-NQNY34X3.js +0 -72
- package/chunks/list-2Z7KS7ZF.js +0 -81
- package/chunks/loadedSettingsAdapter-LIYY3LE4.js +0 -75
- package/chunks/mcp-AJ4QW3JA.js +0 -75
- package/chunks/nonInteractiveCli-PUSO5QF6.js +0 -134
- package/chunks/pidfile-EH2JW2PB.js +0 -78
- package/chunks/read-file-JZ5VXILQ.js +0 -31
- package/chunks/resumeHistoryUtils-Z3HG4WKM.js +0 -84
- package/chunks/ripGrep-JNLJCT2B.js +0 -65
- package/chunks/serve-NN5FXWR6.js +0 -81
- package/chunks/shell-FXT3NVC6.js +0 -75
- package/chunks/spawnChannel-XAWLXNOD.js +0 -74
- package/chunks/theme-manager-2WZHPK2M.js +0 -69
- package/chunks/total-session-admission-HULB2TEQ.js +0 -75
- package/chunks/updateCheck-D4ESCHBJ.js +0 -88
- package/chunks/useAutoAcceptIndicator-CBNLOF2P.js +0 -86
- package/chunks/workspace-providers-status-TJTVHORI.js +0 -78
- package/chunks/workspace-registry-H6VM5WXK.js +0 -79
- package/chunks/workspace-service-ZNKD3I2J.js +0 -90
- package/chunks/workspace-skills-status-OOBIXADG.js +0 -77
- package/chunks/write-file-CAKK5IAO.js +0 -65
- package/web-shell/assets/channel-DiLlxxIf.js +0 -1
- package/web-shell/assets/classDiagram-4FO5ZUOK-CkylTdM4.js +0 -1
- package/web-shell/assets/classDiagram-v2-Q7XG4LA2-CkylTdM4.js +0 -1
- package/web-shell/assets/index-CGtQqOIa.css +0 -5
- package/web-shell/assets/index-TtM0hVjU.js +0 -1207
- package/web-shell/assets/stateDiagram-v2-BHNVJYJU-D1gzH2Ue.js +0 -1
|
@@ -0,0 +1,1462 @@
|
|
|
1
|
+
// Force strict mode and setup for ESM
|
|
2
|
+
"use strict";
|
|
3
|
+
import {
|
|
4
|
+
InvalidStreamError,
|
|
5
|
+
createOpenAIReasoningThoughtPart
|
|
6
|
+
} from "./chunk-BPJSQIJX.js";
|
|
7
|
+
import {
|
|
8
|
+
convertSchema,
|
|
9
|
+
relaxSchemaForFunctionCalling,
|
|
10
|
+
safeJsonParse,
|
|
11
|
+
setGenAiUsageProvenance
|
|
12
|
+
} from "./chunk-H5FFA6TH.js";
|
|
13
|
+
import {
|
|
14
|
+
setToolCallPreparations
|
|
15
|
+
} from "./chunk-LS77BEZP.js";
|
|
16
|
+
import {
|
|
17
|
+
TOKEN_ESTIMATE_UNITS_PER_TOKEN,
|
|
18
|
+
estimateTextTokenUnits,
|
|
19
|
+
estimateTextTokens,
|
|
20
|
+
normalizeMcpToolName
|
|
21
|
+
} from "./chunk-46UV252V.js";
|
|
22
|
+
import {
|
|
23
|
+
createDebugLogger
|
|
24
|
+
} from "./chunk-NL7LTRLR.js";
|
|
25
|
+
import {
|
|
26
|
+
FinishReason,
|
|
27
|
+
GenerateContentResponse
|
|
28
|
+
} from "./chunk-22C7BQ6D.js";
|
|
29
|
+
import {
|
|
30
|
+
init_esbuild_shims
|
|
31
|
+
} from "./chunk-5O2XNYP6.js";
|
|
32
|
+
import {
|
|
33
|
+
__name
|
|
34
|
+
} from "./chunk-J2S4EL5Y.js";
|
|
35
|
+
|
|
36
|
+
// packages/core/src/core/openaiContentGenerator/converter.ts
|
|
37
|
+
init_esbuild_shims();
|
|
38
|
+
|
|
39
|
+
// packages/core/src/core/openaiContentGenerator/taggedThinkingParser.ts
|
|
40
|
+
init_esbuild_shims();
|
|
41
|
+
var debugLogger = createDebugLogger("TAGGED_THINKING_PARSER");
|
|
42
|
+
var OPEN_TAGS = ["<think>", "<thinking>"];
|
|
43
|
+
var CLOSE_TAGS = ["</think>", "</thinking>"];
|
|
44
|
+
var MAX_TAG_LENGTH = Math.max(
|
|
45
|
+
...OPEN_TAGS.map((t) => t.length),
|
|
46
|
+
...CLOSE_TAGS.map((t) => t.length)
|
|
47
|
+
);
|
|
48
|
+
function appendPart(parts, text, mode) {
|
|
49
|
+
if (!text) return;
|
|
50
|
+
parts.push(mode === "thought" ? { text, thought: true } : { text });
|
|
51
|
+
}
|
|
52
|
+
__name(appendPart, "appendPart");
|
|
53
|
+
function isPrefixOfAnyTag(lower, offset, tags) {
|
|
54
|
+
const remainingLen = lower.length - offset;
|
|
55
|
+
if (remainingLen <= 0) return false;
|
|
56
|
+
if (remainingLen > MAX_TAG_LENGTH) return false;
|
|
57
|
+
return tags.some(
|
|
58
|
+
(tag) => tag.startsWith(lower.slice(offset, offset + remainingLen))
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
__name(isPrefixOfAnyTag, "isPrefixOfAnyTag");
|
|
62
|
+
function findMatchingTag(lower, offset, tags) {
|
|
63
|
+
return tags.find((tag) => lower.startsWith(tag, offset));
|
|
64
|
+
}
|
|
65
|
+
__name(findMatchingTag, "findMatchingTag");
|
|
66
|
+
var TaggedThinkingParser = class {
|
|
67
|
+
static {
|
|
68
|
+
__name(this, "TaggedThinkingParser");
|
|
69
|
+
}
|
|
70
|
+
mode = "text";
|
|
71
|
+
buffer = "";
|
|
72
|
+
parse(chunk, final = false) {
|
|
73
|
+
this.buffer += chunk;
|
|
74
|
+
const lower = this.buffer.toLowerCase();
|
|
75
|
+
const parts = [];
|
|
76
|
+
let segment = "";
|
|
77
|
+
let index = 0;
|
|
78
|
+
while (index < this.buffer.length) {
|
|
79
|
+
const activeTags = this.mode === "text" ? OPEN_TAGS : CLOSE_TAGS;
|
|
80
|
+
const matchedTag = findMatchingTag(lower, index, activeTags);
|
|
81
|
+
if (matchedTag) {
|
|
82
|
+
debugLogger.debug(
|
|
83
|
+
`taggedThinking: detected tag "${matchedTag}" at offset ${index}`
|
|
84
|
+
);
|
|
85
|
+
appendPart(parts, segment, this.mode);
|
|
86
|
+
segment = "";
|
|
87
|
+
this.mode = this.mode === "text" ? "thought" : "text";
|
|
88
|
+
index += matchedTag.length;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (!final && isPrefixOfAnyTag(lower, index, activeTags)) {
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
segment += this.buffer[index];
|
|
95
|
+
index += 1;
|
|
96
|
+
}
|
|
97
|
+
if (index < this.buffer.length) {
|
|
98
|
+
appendPart(parts, segment, this.mode);
|
|
99
|
+
this.buffer = this.buffer.slice(index);
|
|
100
|
+
debugLogger.debug(
|
|
101
|
+
`taggedThinking: emitted ${parts.length} part(s), buffered ${this.buffer.length} char(s)`
|
|
102
|
+
);
|
|
103
|
+
return parts;
|
|
104
|
+
}
|
|
105
|
+
this.buffer = "";
|
|
106
|
+
if (this.mode === "thought" && segment) {
|
|
107
|
+
debugLogger.warn(
|
|
108
|
+
`taggedThinking: flushing ${segment.length} chars of unclosed thought on stream end`
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
appendPart(parts, segment, this.mode);
|
|
112
|
+
debugLogger.debug(
|
|
113
|
+
`taggedThinking: emitted ${parts.length} part(s), flush complete`
|
|
114
|
+
);
|
|
115
|
+
return parts;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
function parseTaggedThinkingText(text) {
|
|
119
|
+
return new TaggedThinkingParser().parse(text, true);
|
|
120
|
+
}
|
|
121
|
+
__name(parseTaggedThinkingText, "parseTaggedThinkingText");
|
|
122
|
+
|
|
123
|
+
// packages/core/src/core/openaiContentGenerator/converter.ts
|
|
124
|
+
var debugLogger2 = createDebugLogger("CONVERTER");
|
|
125
|
+
var SPLIT_TOOL_MEDIA_TEXT = "(attached media from previous tool call)";
|
|
126
|
+
var CUMULATIVE_DELTA_EXACT_REPEAT_MIN_LENGTH = 64;
|
|
127
|
+
var CUMULATIVE_DETECTION_WINDOW_BYTES = 1024;
|
|
128
|
+
function normalizeStreamingTextDelta(rawDelta, state) {
|
|
129
|
+
if (rawDelta.length === 0) {
|
|
130
|
+
return "";
|
|
131
|
+
}
|
|
132
|
+
if (state.emittedText.length === 0) {
|
|
133
|
+
state.emittedText = rawDelta;
|
|
134
|
+
state.emittedLength = rawDelta.length;
|
|
135
|
+
return rawDelta;
|
|
136
|
+
}
|
|
137
|
+
if (state.cumulativeMode) {
|
|
138
|
+
if (rawDelta.startsWith(state.emittedText)) {
|
|
139
|
+
const suffix = rawDelta.slice(state.emittedText.length);
|
|
140
|
+
state.emittedText = rawDelta;
|
|
141
|
+
state.emittedLength = rawDelta.length;
|
|
142
|
+
return suffix;
|
|
143
|
+
}
|
|
144
|
+
if (state.emittedText.startsWith(rawDelta)) {
|
|
145
|
+
debugLogger2.debug(
|
|
146
|
+
`normalizeStreamingTextDelta: cumulative rewind suppression (emitted=${state.emittedText.length}b, chunk=${rawDelta.length}b)`
|
|
147
|
+
);
|
|
148
|
+
return "";
|
|
149
|
+
}
|
|
150
|
+
debugLogger2.debug(
|
|
151
|
+
"normalizeStreamingTextDelta: exiting cumulative mode (chunk does not match prior accumulated text)"
|
|
152
|
+
);
|
|
153
|
+
state.cumulativeMode = false;
|
|
154
|
+
state.emittedText = rawDelta;
|
|
155
|
+
state.emittedLength += rawDelta.length;
|
|
156
|
+
return rawDelta;
|
|
157
|
+
}
|
|
158
|
+
if (rawDelta.length > state.emittedText.length && rawDelta.startsWith(state.emittedText)) {
|
|
159
|
+
const baselineLen = state.emittedText.length;
|
|
160
|
+
const baselineFrozenAtCap = baselineLen >= CUMULATIVE_DETECTION_WINDOW_BYTES && state.emittedLength > baselineLen;
|
|
161
|
+
const sliceFrom = baselineFrozenAtCap ? state.emittedLength : baselineLen;
|
|
162
|
+
if (rawDelta.length > sliceFrom) {
|
|
163
|
+
const suffix = rawDelta.slice(sliceFrom);
|
|
164
|
+
state.emittedText = rawDelta;
|
|
165
|
+
state.emittedLength = rawDelta.length;
|
|
166
|
+
state.cumulativeMode = true;
|
|
167
|
+
debugLogger2.debug(
|
|
168
|
+
`normalizeStreamingTextDelta: entered cumulative mode (prefix overlap, baseline=${baselineLen}b sliceFrom=${sliceFrom}b -> curr=${rawDelta.length}b)`
|
|
169
|
+
);
|
|
170
|
+
return suffix;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (rawDelta === state.emittedText) {
|
|
174
|
+
if (rawDelta.length >= CUMULATIVE_DELTA_EXACT_REPEAT_MIN_LENGTH) {
|
|
175
|
+
state.cumulativeMode = true;
|
|
176
|
+
debugLogger2.debug(
|
|
177
|
+
`normalizeStreamingTextDelta: entered cumulative mode (exact repeat, ${rawDelta.length}b)`
|
|
178
|
+
);
|
|
179
|
+
return "";
|
|
180
|
+
}
|
|
181
|
+
state.emittedLength += rawDelta.length;
|
|
182
|
+
return rawDelta;
|
|
183
|
+
}
|
|
184
|
+
if (state.emittedText.length < CUMULATIVE_DETECTION_WINDOW_BYTES) {
|
|
185
|
+
state.emittedText += rawDelta;
|
|
186
|
+
}
|
|
187
|
+
state.emittedLength += rawDelta.length;
|
|
188
|
+
return rawDelta;
|
|
189
|
+
}
|
|
190
|
+
__name(normalizeStreamingTextDelta, "normalizeStreamingTextDelta");
|
|
191
|
+
function convertGeminiToolParametersToOpenAI(parameters) {
|
|
192
|
+
if (!parameters || typeof parameters !== "object") {
|
|
193
|
+
return parameters;
|
|
194
|
+
}
|
|
195
|
+
const converted = JSON.parse(JSON.stringify(parameters));
|
|
196
|
+
const convertTypes = /* @__PURE__ */ __name((obj) => {
|
|
197
|
+
if (typeof obj !== "object" || obj === null) {
|
|
198
|
+
return obj;
|
|
199
|
+
}
|
|
200
|
+
if (Array.isArray(obj)) {
|
|
201
|
+
return obj.map(convertTypes);
|
|
202
|
+
}
|
|
203
|
+
const result = {};
|
|
204
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
205
|
+
if (key === "type" && typeof value === "string") {
|
|
206
|
+
const lowerValue = value.toLowerCase();
|
|
207
|
+
if (lowerValue === "integer") {
|
|
208
|
+
result[key] = "integer";
|
|
209
|
+
} else if (lowerValue === "number") {
|
|
210
|
+
result[key] = "number";
|
|
211
|
+
} else {
|
|
212
|
+
result[key] = lowerValue;
|
|
213
|
+
}
|
|
214
|
+
} else if (key === "minimum" || key === "maximum" || key === "multipleOf") {
|
|
215
|
+
if (typeof value === "string" && !isNaN(Number(value))) {
|
|
216
|
+
result[key] = Number(value);
|
|
217
|
+
} else {
|
|
218
|
+
result[key] = value;
|
|
219
|
+
}
|
|
220
|
+
} else if (key === "minLength" || key === "maxLength" || key === "minItems" || key === "maxItems") {
|
|
221
|
+
const numberValue = typeof value === "string" ? Number(value) : NaN;
|
|
222
|
+
if (typeof value === "string" && value.trim() !== "" && Number.isInteger(numberValue)) {
|
|
223
|
+
result[key] = numberValue;
|
|
224
|
+
} else {
|
|
225
|
+
result[key] = value;
|
|
226
|
+
}
|
|
227
|
+
} else if (typeof value === "object") {
|
|
228
|
+
result[key] = convertTypes(value);
|
|
229
|
+
} else {
|
|
230
|
+
result[key] = value;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return result;
|
|
234
|
+
}, "convertTypes");
|
|
235
|
+
return convertTypes(converted);
|
|
236
|
+
}
|
|
237
|
+
__name(convertGeminiToolParametersToOpenAI, "convertGeminiToolParametersToOpenAI");
|
|
238
|
+
async function convertGeminiToolsToOpenAI(geminiTools, schemaCompliance = "auto") {
|
|
239
|
+
const openAITools = [];
|
|
240
|
+
for (const tool of geminiTools) {
|
|
241
|
+
let actualTool;
|
|
242
|
+
if ("tool" in tool) {
|
|
243
|
+
actualTool = await tool.tool();
|
|
244
|
+
} else {
|
|
245
|
+
actualTool = tool;
|
|
246
|
+
}
|
|
247
|
+
if (actualTool.functionDeclarations) {
|
|
248
|
+
for (const func of actualTool.functionDeclarations) {
|
|
249
|
+
if (func.name) {
|
|
250
|
+
let parameters;
|
|
251
|
+
if (func.parametersJsonSchema) {
|
|
252
|
+
const paramsCopy = {
|
|
253
|
+
...func.parametersJsonSchema
|
|
254
|
+
};
|
|
255
|
+
parameters = paramsCopy;
|
|
256
|
+
} else if (func.parameters) {
|
|
257
|
+
parameters = convertGeminiToolParametersToOpenAI(
|
|
258
|
+
func.parameters
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
if (parameters) {
|
|
262
|
+
parameters = convertSchema(parameters, schemaCompliance);
|
|
263
|
+
parameters = relaxSchemaForFunctionCalling(parameters);
|
|
264
|
+
}
|
|
265
|
+
openAITools.push({
|
|
266
|
+
type: "function",
|
|
267
|
+
function: {
|
|
268
|
+
name: func.name,
|
|
269
|
+
description: func.description ?? "",
|
|
270
|
+
parameters
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return openAITools;
|
|
278
|
+
}
|
|
279
|
+
__name(convertGeminiToolsToOpenAI, "convertGeminiToolsToOpenAI");
|
|
280
|
+
function convertGeminiRequestToOpenAI(request, requestContext, options = { cleanOrphanToolCalls: true }) {
|
|
281
|
+
let messages = [];
|
|
282
|
+
addSystemInstructionMessage(request, messages);
|
|
283
|
+
processContents(request.contents, messages, requestContext);
|
|
284
|
+
messages = mergeConsecutiveAssistantMessages(messages);
|
|
285
|
+
if (options.cleanOrphanToolCalls) {
|
|
286
|
+
messages = cleanOrphanedToolCalls(messages);
|
|
287
|
+
messages = mergeConsecutiveAssistantMessages(messages);
|
|
288
|
+
}
|
|
289
|
+
return messages;
|
|
290
|
+
}
|
|
291
|
+
__name(convertGeminiRequestToOpenAI, "convertGeminiRequestToOpenAI");
|
|
292
|
+
function convertGeminiResponseToOpenAI(response, requestContext) {
|
|
293
|
+
const candidate = response.candidates?.[0];
|
|
294
|
+
const parts = candidate?.content?.parts || [];
|
|
295
|
+
const thoughtParts = [];
|
|
296
|
+
const contentParts = [];
|
|
297
|
+
const toolCalls = [];
|
|
298
|
+
let toolCallIndex = 0;
|
|
299
|
+
for (const part of parts) {
|
|
300
|
+
if (typeof part === "string") {
|
|
301
|
+
contentParts.push(part);
|
|
302
|
+
} else if ("text" in part && part.text) {
|
|
303
|
+
if ("thought" in part && part.thought) {
|
|
304
|
+
thoughtParts.push(part.text);
|
|
305
|
+
} else {
|
|
306
|
+
contentParts.push(part.text);
|
|
307
|
+
}
|
|
308
|
+
} else if ("functionCall" in part && part.functionCall) {
|
|
309
|
+
toolCalls.push({
|
|
310
|
+
id: part.functionCall.id || `call_${toolCallIndex}`,
|
|
311
|
+
type: "function",
|
|
312
|
+
function: {
|
|
313
|
+
name: part.functionCall.name || "",
|
|
314
|
+
arguments: JSON.stringify(part.functionCall.args || {})
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
toolCallIndex += 1;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
const message = {
|
|
321
|
+
role: "assistant",
|
|
322
|
+
content: contentParts.join("") || null,
|
|
323
|
+
refusal: null
|
|
324
|
+
};
|
|
325
|
+
const reasoningContent = thoughtParts.join("");
|
|
326
|
+
if (reasoningContent) {
|
|
327
|
+
message.reasoning_content = reasoningContent;
|
|
328
|
+
}
|
|
329
|
+
if (toolCalls.length > 0) {
|
|
330
|
+
message.tool_calls = toolCalls;
|
|
331
|
+
}
|
|
332
|
+
const finishReason = mapGeminiFinishReasonToOpenAI(candidate?.finishReason);
|
|
333
|
+
const usageMetadata = response.usageMetadata;
|
|
334
|
+
const usage = {
|
|
335
|
+
prompt_tokens: usageMetadata?.promptTokenCount || 0,
|
|
336
|
+
completion_tokens: usageMetadata?.candidatesTokenCount || 0,
|
|
337
|
+
total_tokens: usageMetadata?.totalTokenCount || 0
|
|
338
|
+
};
|
|
339
|
+
if (usageMetadata?.cachedContentTokenCount !== void 0) {
|
|
340
|
+
usage.prompt_tokens_details = {
|
|
341
|
+
cached_tokens: usageMetadata.cachedContentTokenCount
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
const createdMs = response.createTime ? Number(response.createTime) : Date.now();
|
|
345
|
+
const createdSeconds = Number.isFinite(createdMs) ? Math.floor(createdMs / 1e3) : Math.floor(Date.now() / 1e3);
|
|
346
|
+
return {
|
|
347
|
+
id: response.responseId || `gemini-${Date.now()}`,
|
|
348
|
+
object: "chat.completion",
|
|
349
|
+
created: createdSeconds,
|
|
350
|
+
model: response.modelVersion || requestContext.model,
|
|
351
|
+
choices: [
|
|
352
|
+
{
|
|
353
|
+
index: 0,
|
|
354
|
+
message,
|
|
355
|
+
finish_reason: finishReason,
|
|
356
|
+
logprobs: null
|
|
357
|
+
}
|
|
358
|
+
],
|
|
359
|
+
usage
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
__name(convertGeminiResponseToOpenAI, "convertGeminiResponseToOpenAI");
|
|
363
|
+
function addSystemInstructionMessage(request, messages) {
|
|
364
|
+
if (!request.config?.systemInstruction) return;
|
|
365
|
+
const systemText = extractTextFromContentUnion(
|
|
366
|
+
request.config.systemInstruction
|
|
367
|
+
);
|
|
368
|
+
if (systemText) {
|
|
369
|
+
messages.push({
|
|
370
|
+
role: "system",
|
|
371
|
+
content: systemText
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
__name(addSystemInstructionMessage, "addSystemInstructionMessage");
|
|
376
|
+
function processContents(contents, messages, requestContext) {
|
|
377
|
+
if (Array.isArray(contents)) {
|
|
378
|
+
for (const content of contents) {
|
|
379
|
+
processContent(content, messages, requestContext);
|
|
380
|
+
}
|
|
381
|
+
} else if (contents) {
|
|
382
|
+
processContent(contents, messages, requestContext);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
__name(processContents, "processContents");
|
|
386
|
+
function processContent(content, messages, requestContext) {
|
|
387
|
+
if (typeof content === "string") {
|
|
388
|
+
messages.push({ role: "user", content });
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
if (!isContentObject(content)) return;
|
|
392
|
+
const parts = content.parts || [];
|
|
393
|
+
const role = content.role === "model" ? "assistant" : "user";
|
|
394
|
+
const contentParts = [];
|
|
395
|
+
const reasoningParts = [];
|
|
396
|
+
const toolCalls = [];
|
|
397
|
+
let toolCallIndex = 0;
|
|
398
|
+
const emittedFunctionCallIds = /* @__PURE__ */ new Set();
|
|
399
|
+
const emittedFunctionResponseIds = /* @__PURE__ */ new Set();
|
|
400
|
+
const accumulatedSplitMedia = [];
|
|
401
|
+
for (const part of parts) {
|
|
402
|
+
if (typeof part === "string") {
|
|
403
|
+
contentParts.push({ type: "text", text: part });
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if ("text" in part && "thought" in part && part.thought) {
|
|
407
|
+
if (role === "assistant" && part.text) {
|
|
408
|
+
reasoningParts.push(part.text);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if ("text" in part && part.text && !("thought" in part && part.thought)) {
|
|
412
|
+
contentParts.push({ type: "text", text: part.text });
|
|
413
|
+
}
|
|
414
|
+
const mediaPart = createMediaContentPart(part, requestContext);
|
|
415
|
+
if (mediaPart && role === "user") {
|
|
416
|
+
contentParts.push(mediaPart);
|
|
417
|
+
}
|
|
418
|
+
if ("functionCall" in part && part.functionCall && role === "assistant") {
|
|
419
|
+
const callId = part.functionCall.id;
|
|
420
|
+
if (callId) {
|
|
421
|
+
if (emittedFunctionCallIds.has(callId)) {
|
|
422
|
+
debugLogger2.debug(
|
|
423
|
+
`Dropping duplicate functionCall id=${callId} while converting content`
|
|
424
|
+
);
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
emittedFunctionCallIds.add(callId);
|
|
428
|
+
}
|
|
429
|
+
toolCalls.push({
|
|
430
|
+
id: callId || `call_${toolCallIndex}`,
|
|
431
|
+
type: "function",
|
|
432
|
+
function: {
|
|
433
|
+
name: normalizeMcpToolName(part.functionCall.name || ""),
|
|
434
|
+
arguments: JSON.stringify(part.functionCall.args || {})
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
toolCallIndex += 1;
|
|
438
|
+
}
|
|
439
|
+
if (part.functionResponse && role === "user") {
|
|
440
|
+
const responseId = part.functionResponse.id;
|
|
441
|
+
if (responseId) {
|
|
442
|
+
if (emittedFunctionResponseIds.has(responseId)) {
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
emittedFunctionResponseIds.add(responseId);
|
|
446
|
+
}
|
|
447
|
+
const toolMessage = createToolMessage(
|
|
448
|
+
part.functionResponse,
|
|
449
|
+
requestContext
|
|
450
|
+
);
|
|
451
|
+
if (toolMessage) {
|
|
452
|
+
if (requestContext.splitToolMedia && Array.isArray(toolMessage.content)) {
|
|
453
|
+
const mediaParts = [];
|
|
454
|
+
const textParts = [];
|
|
455
|
+
for (const cp of toolMessage.content) {
|
|
456
|
+
if (cp && (cp.type === "image_url" || cp.type === "input_audio" || cp.type === "video_url" || cp.type === "file")) {
|
|
457
|
+
mediaParts.push(cp);
|
|
458
|
+
} else if (cp && cp.type === "text") {
|
|
459
|
+
textParts.push(cp);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (mediaParts.length > 0) {
|
|
463
|
+
const textOnly = textParts.map((p) => p.text).join("\n");
|
|
464
|
+
toolMessage.content = textOnly || "[media attached in following user message]";
|
|
465
|
+
accumulatedSplitMedia.push(...mediaParts);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
if (requestContext.toolResultContentFormat === "string" && Array.isArray(toolMessage.content)) {
|
|
469
|
+
const toolContent = toolMessage.content;
|
|
470
|
+
if (toolContent.every(
|
|
471
|
+
(cp) => cp?.type === "text"
|
|
472
|
+
)) {
|
|
473
|
+
toolMessage.content = toolContent.map((cp) => cp.text).join("\n");
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
messages.push(toolMessage);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
if (accumulatedSplitMedia.length > 0) {
|
|
481
|
+
messages.push({
|
|
482
|
+
role: "user",
|
|
483
|
+
content: [
|
|
484
|
+
{
|
|
485
|
+
type: "text",
|
|
486
|
+
text: SPLIT_TOOL_MEDIA_TEXT
|
|
487
|
+
},
|
|
488
|
+
...accumulatedSplitMedia
|
|
489
|
+
]
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
if (role === "assistant") {
|
|
493
|
+
if (contentParts.length === 0 && toolCalls.length === 0 && reasoningParts.length === 0) {
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
const assistantTextContent = contentParts.filter(
|
|
497
|
+
(part) => part.type === "text"
|
|
498
|
+
).map((part) => part.text).join("");
|
|
499
|
+
const assistantMessage = {
|
|
500
|
+
role: "assistant",
|
|
501
|
+
// When there is reasoning content but no text, use "" instead of null.
|
|
502
|
+
// Some OpenAI-compatible providers (e.g. Ollama) reject content: null
|
|
503
|
+
// when reasoning_content is present, returning HTTP 400.
|
|
504
|
+
// For tool-call-only messages we keep null to stay spec-compliant.
|
|
505
|
+
content: assistantTextContent || (reasoningParts.length > 0 ? "" : null)
|
|
506
|
+
};
|
|
507
|
+
if (toolCalls.length > 0) {
|
|
508
|
+
assistantMessage.tool_calls = toolCalls;
|
|
509
|
+
}
|
|
510
|
+
const reasoningContent = reasoningParts.join("");
|
|
511
|
+
if (reasoningContent) {
|
|
512
|
+
assistantMessage.reasoning_content = reasoningContent;
|
|
513
|
+
}
|
|
514
|
+
messages.push(assistantMessage);
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
if (contentParts.length > 0) {
|
|
518
|
+
messages.push({
|
|
519
|
+
role: "user",
|
|
520
|
+
content: contentParts
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
__name(processContent, "processContent");
|
|
525
|
+
function extractFunctionResponseContent(response) {
|
|
526
|
+
if (response === null || response === void 0) {
|
|
527
|
+
return "";
|
|
528
|
+
}
|
|
529
|
+
if (typeof response === "string") {
|
|
530
|
+
return response;
|
|
531
|
+
}
|
|
532
|
+
if (typeof response === "object") {
|
|
533
|
+
const responseObject = response;
|
|
534
|
+
const output = responseObject["output"];
|
|
535
|
+
if (typeof output === "string") {
|
|
536
|
+
return output;
|
|
537
|
+
}
|
|
538
|
+
const error = responseObject["error"];
|
|
539
|
+
if (typeof error === "string") {
|
|
540
|
+
return error;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
try {
|
|
544
|
+
const serialized = JSON.stringify(response);
|
|
545
|
+
return serialized ?? String(response);
|
|
546
|
+
} catch {
|
|
547
|
+
return String(response);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
__name(extractFunctionResponseContent, "extractFunctionResponseContent");
|
|
551
|
+
function createToolMessage(response, requestContext) {
|
|
552
|
+
const textContent = extractFunctionResponseContent(response.response);
|
|
553
|
+
const contentParts = [];
|
|
554
|
+
if (textContent) {
|
|
555
|
+
contentParts.push({ type: "text", text: textContent });
|
|
556
|
+
}
|
|
557
|
+
for (const part of response.parts || []) {
|
|
558
|
+
if ("text" in part && typeof part.text === "string") {
|
|
559
|
+
if (part.text.length > 0) {
|
|
560
|
+
contentParts.push({ type: "text", text: part.text });
|
|
561
|
+
}
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
const mediaPart = createMediaContentPart(part, requestContext);
|
|
565
|
+
if (mediaPart) {
|
|
566
|
+
contentParts.push(mediaPart);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
if (contentParts.length === 0) {
|
|
570
|
+
return {
|
|
571
|
+
role: "tool",
|
|
572
|
+
tool_call_id: response.id || "",
|
|
573
|
+
content: ""
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
return {
|
|
577
|
+
role: "tool",
|
|
578
|
+
tool_call_id: response.id || "",
|
|
579
|
+
content: contentParts
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
__name(createToolMessage, "createToolMessage");
|
|
583
|
+
function createMediaContentPart(part, requestContext) {
|
|
584
|
+
const { modalities } = requestContext;
|
|
585
|
+
if (part.inlineData?.mimeType && part.inlineData?.data) {
|
|
586
|
+
const mimeType = part.inlineData.mimeType;
|
|
587
|
+
const mediaType = getMediaType(mimeType);
|
|
588
|
+
const displayName = part.inlineData.displayName || mimeType;
|
|
589
|
+
if (mediaType === "image") {
|
|
590
|
+
if (!modalities.image) {
|
|
591
|
+
return unsupportedModalityPlaceholder(
|
|
592
|
+
"image",
|
|
593
|
+
displayName,
|
|
594
|
+
requestContext
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
const dataUrl = `data:${mimeType};base64,${part.inlineData.data}`;
|
|
598
|
+
return {
|
|
599
|
+
type: "image_url",
|
|
600
|
+
image_url: { url: dataUrl }
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
if (mimeType === "application/pdf") {
|
|
604
|
+
if (!modalities.pdf) {
|
|
605
|
+
return unsupportedModalityPlaceholder(
|
|
606
|
+
"pdf",
|
|
607
|
+
displayName,
|
|
608
|
+
requestContext
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
const filename = part.inlineData.displayName || "document.pdf";
|
|
612
|
+
return {
|
|
613
|
+
type: "file",
|
|
614
|
+
file: {
|
|
615
|
+
filename,
|
|
616
|
+
file_data: `data:${mimeType};base64,${part.inlineData.data}`
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
if (mediaType === "audio") {
|
|
621
|
+
if (!modalities.audio) {
|
|
622
|
+
return unsupportedModalityPlaceholder(
|
|
623
|
+
"audio",
|
|
624
|
+
displayName,
|
|
625
|
+
requestContext
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
const format = getAudioFormat(mimeType);
|
|
629
|
+
if (format) {
|
|
630
|
+
return {
|
|
631
|
+
type: "input_audio",
|
|
632
|
+
input_audio: {
|
|
633
|
+
data: `data:${mimeType};base64,${part.inlineData.data}`,
|
|
634
|
+
format
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
if (mediaType === "video") {
|
|
640
|
+
if (!modalities.video) {
|
|
641
|
+
return unsupportedModalityPlaceholder(
|
|
642
|
+
"video",
|
|
643
|
+
displayName,
|
|
644
|
+
requestContext
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
return {
|
|
648
|
+
type: "video_url",
|
|
649
|
+
video_url: {
|
|
650
|
+
url: `data:${mimeType};base64,${part.inlineData.data}`
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
return {
|
|
655
|
+
type: "text",
|
|
656
|
+
text: `Unsupported inline media type: ${mimeType} (${displayName}).`
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
if (part.fileData?.mimeType && part.fileData?.fileUri) {
|
|
660
|
+
const filename = part.fileData.displayName || "file";
|
|
661
|
+
const fileUri = part.fileData.fileUri;
|
|
662
|
+
const mimeType = part.fileData.mimeType;
|
|
663
|
+
const mediaType = getMediaType(mimeType);
|
|
664
|
+
if (mediaType === "image") {
|
|
665
|
+
if (!modalities.image) {
|
|
666
|
+
return unsupportedModalityPlaceholder(
|
|
667
|
+
"image",
|
|
668
|
+
filename,
|
|
669
|
+
requestContext
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
return {
|
|
673
|
+
type: "image_url",
|
|
674
|
+
image_url: { url: fileUri }
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
if (mimeType === "application/pdf") {
|
|
678
|
+
if (!modalities.pdf) {
|
|
679
|
+
return unsupportedModalityPlaceholder("pdf", filename, requestContext);
|
|
680
|
+
}
|
|
681
|
+
return {
|
|
682
|
+
type: "file",
|
|
683
|
+
file: {
|
|
684
|
+
filename,
|
|
685
|
+
file_data: fileUri
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
if (mediaType === "video") {
|
|
690
|
+
if (!modalities.video) {
|
|
691
|
+
return unsupportedModalityPlaceholder(
|
|
692
|
+
"video",
|
|
693
|
+
filename,
|
|
694
|
+
requestContext
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
return {
|
|
698
|
+
type: "video_url",
|
|
699
|
+
video_url: {
|
|
700
|
+
url: fileUri
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
const displayNameStr = part.fileData.displayName ? ` (${part.fileData.displayName})` : "";
|
|
705
|
+
return {
|
|
706
|
+
type: "text",
|
|
707
|
+
text: `Unsupported file media type: ${mimeType}${displayNameStr}.`
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
return null;
|
|
711
|
+
}
|
|
712
|
+
__name(createMediaContentPart, "createMediaContentPart");
|
|
713
|
+
function unsupportedModalityPlaceholder(modality, displayName, requestContext) {
|
|
714
|
+
debugLogger2.warn(
|
|
715
|
+
`Model '${requestContext.model}' does not support ${modality} input. Replacing with text placeholder: ${displayName}`
|
|
716
|
+
);
|
|
717
|
+
let hint;
|
|
718
|
+
if (modality === "pdf") {
|
|
719
|
+
hint = "This model does not support PDF input directly. The read_file tool cannot extract PDF content either. To extract text from the PDF file, try using skills if applicable, or guide user to install pdf skill by running this slash command:\n/extensions install https://github.com/anthropics/skills:document-skills";
|
|
720
|
+
} else {
|
|
721
|
+
hint = `This model does not support ${modality} input. The read_file tool cannot process this type of file either. To handle this file, try using skills if applicable, or any tools installed at system wide, or let the user know you cannot process this type of file.`;
|
|
722
|
+
}
|
|
723
|
+
return {
|
|
724
|
+
type: "text",
|
|
725
|
+
text: `[Unsupported ${modality} file: "${displayName}". ${hint}]`
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
__name(unsupportedModalityPlaceholder, "unsupportedModalityPlaceholder");
|
|
729
|
+
function getMediaType(mimeType) {
|
|
730
|
+
if (mimeType.startsWith("image/")) return "image";
|
|
731
|
+
if (mimeType.startsWith("audio/")) return "audio";
|
|
732
|
+
if (mimeType.startsWith("video/")) return "video";
|
|
733
|
+
return "file";
|
|
734
|
+
}
|
|
735
|
+
__name(getMediaType, "getMediaType");
|
|
736
|
+
function getAudioFormat(mimeType) {
|
|
737
|
+
if (mimeType.includes("wav")) return "wav";
|
|
738
|
+
if (mimeType.includes("mp3") || mimeType.includes("mpeg")) return "mp3";
|
|
739
|
+
return null;
|
|
740
|
+
}
|
|
741
|
+
__name(getAudioFormat, "getAudioFormat");
|
|
742
|
+
function isContentObject(content) {
|
|
743
|
+
return typeof content === "object" && content !== null && "role" in content && "parts" in content && Array.isArray(content["parts"]);
|
|
744
|
+
}
|
|
745
|
+
__name(isContentObject, "isContentObject");
|
|
746
|
+
function extractTextFromContentUnion(contentUnion) {
|
|
747
|
+
if (typeof contentUnion === "string") {
|
|
748
|
+
return contentUnion;
|
|
749
|
+
}
|
|
750
|
+
if (Array.isArray(contentUnion)) {
|
|
751
|
+
return contentUnion.map((item) => extractTextFromContentUnion(item)).filter(Boolean).join("\n");
|
|
752
|
+
}
|
|
753
|
+
if (typeof contentUnion === "object" && contentUnion !== null) {
|
|
754
|
+
if ("parts" in contentUnion) {
|
|
755
|
+
const content = contentUnion;
|
|
756
|
+
return content.parts?.map((part) => {
|
|
757
|
+
if (typeof part === "string") return part;
|
|
758
|
+
if ("text" in part) return part.text || "";
|
|
759
|
+
return "";
|
|
760
|
+
}).filter(Boolean).join("\n") || "";
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
return "";
|
|
764
|
+
}
|
|
765
|
+
__name(extractTextFromContentUnion, "extractTextFromContentUnion");
|
|
766
|
+
function convertOpenAITextToParts(text, requestContext, final = true) {
|
|
767
|
+
if (!requestContext.responseParsingOptions?.taggedThinkingTags) {
|
|
768
|
+
return text ? [{ text }] : [];
|
|
769
|
+
}
|
|
770
|
+
if (requestContext.taggedThinkingParser) {
|
|
771
|
+
return requestContext.taggedThinkingParser.parse(text, final);
|
|
772
|
+
}
|
|
773
|
+
return parseTaggedThinkingText(text);
|
|
774
|
+
}
|
|
775
|
+
__name(convertOpenAITextToParts, "convertOpenAITextToParts");
|
|
776
|
+
function hasThoughtPart(parts) {
|
|
777
|
+
return parts.some((part) => part.thought === true);
|
|
778
|
+
}
|
|
779
|
+
__name(hasThoughtPart, "hasThoughtPart");
|
|
780
|
+
var THINKING_TAG_PATTERN = /<\/?think(?:ing)?\s*>/i;
|
|
781
|
+
var CLOSING_THINKING_TAG_PATTERN = /\n[^\S\r\n]*<\/think(?:ing)?[^\S\r\n]*>/i;
|
|
782
|
+
var LEADING_CLOSING_THINKING_TAG_PATTERN = /^[^\S\r\n]*<\/think(?:ing)?[^\S\r\n]*>/i;
|
|
783
|
+
var LEADING_THINKING_TAG_PATTERN = /^\s*<\/?think(?:ing)?\s*>/i;
|
|
784
|
+
var STANDALONE_CLOSING_THINKING_TAG_PATTERN = /^\s*<\/(think|thinking)\s*>\s*$/i;
|
|
785
|
+
var STANDALONE_OPENING_THINKING_TAG_PATTERN = /^\s*<(think|thinking)\s*>\s*$/i;
|
|
786
|
+
var MAX_THINKING_TAG_CANDIDATE_LENGTH = 128;
|
|
787
|
+
function canBeStandaloneThinkingTagPrefix(text) {
|
|
788
|
+
const candidate = text.trimStart().toLowerCase();
|
|
789
|
+
if (!candidate) return true;
|
|
790
|
+
return ["<think", "<thinking", "</think", "</thinking"].some((tag) => {
|
|
791
|
+
if (tag.startsWith(candidate)) return true;
|
|
792
|
+
if (!candidate.startsWith(tag)) return false;
|
|
793
|
+
return /^\s*(?:>\s*)?$/.test(candidate.slice(tag.length));
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
__name(canBeStandaloneThinkingTagPrefix, "canBeStandaloneThinkingTagPrefix");
|
|
797
|
+
function classifyContentOnlyThinkingTagPrefix(text, streamFinished) {
|
|
798
|
+
const candidate = text.trimStart().toLowerCase();
|
|
799
|
+
if (!candidate) return "clean";
|
|
800
|
+
const consumeTag = /* @__PURE__ */ __name((value, closing) => {
|
|
801
|
+
const match = LEADING_THINKING_TAG_PATTERN.exec(value)?.[0];
|
|
802
|
+
if (match) {
|
|
803
|
+
return match.trimStart().startsWith("</") === closing ? match.length : void 0;
|
|
804
|
+
}
|
|
805
|
+
if (!canBeStandaloneThinkingTagPrefix(value)) return void 0;
|
|
806
|
+
if (!value || value === "<") return null;
|
|
807
|
+
return closing === value.startsWith("</") ? null : void 0;
|
|
808
|
+
}, "consumeTag");
|
|
809
|
+
let rest = candidate;
|
|
810
|
+
for (const closing of [false, true, false]) {
|
|
811
|
+
const tagLength = consumeTag(rest, closing);
|
|
812
|
+
if (tagLength === null) return "pending";
|
|
813
|
+
if (tagLength === void 0) return "clean";
|
|
814
|
+
rest = rest.slice(tagLength).trimStart();
|
|
815
|
+
}
|
|
816
|
+
let depth = 1;
|
|
817
|
+
let hasNestedOpening = false;
|
|
818
|
+
for (; ; ) {
|
|
819
|
+
const nextTag = THINKING_TAG_PATTERN.exec(rest);
|
|
820
|
+
if (!nextTag) break;
|
|
821
|
+
const closing = nextTag[0].startsWith("</");
|
|
822
|
+
depth += closing ? -1 : 1;
|
|
823
|
+
if (depth === 0) return "clean";
|
|
824
|
+
hasNestedOpening ||= !closing;
|
|
825
|
+
rest = rest.slice(nextTag.index + nextTag[0].length);
|
|
826
|
+
}
|
|
827
|
+
if (!hasNestedOpening) return "pending";
|
|
828
|
+
return streamFinished ? "leaked" : "suspicious";
|
|
829
|
+
}
|
|
830
|
+
__name(classifyContentOnlyThinkingTagPrefix, "classifyContentOnlyThinkingTagPrefix");
|
|
831
|
+
function throwProtocolTagLeak(requestContext) {
|
|
832
|
+
requestContext.pendingThinkingTagCandidate = void 0;
|
|
833
|
+
requestContext.pendingUntrustedResponseParts = void 0;
|
|
834
|
+
throw new InvalidStreamError(
|
|
835
|
+
"Model response leaked thinking tags.",
|
|
836
|
+
"PROTOCOL_TAG_LEAK"
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
__name(throwProtocolTagLeak, "throwProtocolTagLeak");
|
|
840
|
+
function convertOpenAIResponseToGemini(openaiResponse, requestContext) {
|
|
841
|
+
const choice = openaiResponse.choices?.[0];
|
|
842
|
+
const message = choice?.message;
|
|
843
|
+
const reasoningText = message?.reasoning_content ?? message?.reasoning;
|
|
844
|
+
const response = new GenerateContentResponse();
|
|
845
|
+
if (choice) {
|
|
846
|
+
const parts = [];
|
|
847
|
+
const textParts = choice.message.content ? convertOpenAITextToParts(choice.message.content, requestContext) : [];
|
|
848
|
+
if (reasoningText && !hasThoughtPart(textParts)) {
|
|
849
|
+
parts.push(createOpenAIReasoningThoughtPart(reasoningText));
|
|
850
|
+
}
|
|
851
|
+
parts.push(...textParts);
|
|
852
|
+
if (choice.message.tool_calls) {
|
|
853
|
+
for (const toolCall of choice.message.tool_calls) {
|
|
854
|
+
if (toolCall.function) {
|
|
855
|
+
let args = {};
|
|
856
|
+
if (toolCall.function.arguments) {
|
|
857
|
+
args = safeJsonParse(toolCall.function.arguments, {});
|
|
858
|
+
}
|
|
859
|
+
parts.push({
|
|
860
|
+
functionCall: {
|
|
861
|
+
id: toolCall.id,
|
|
862
|
+
name: toolCall.function.name,
|
|
863
|
+
args
|
|
864
|
+
}
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
response.candidates = [
|
|
870
|
+
{
|
|
871
|
+
content: {
|
|
872
|
+
parts,
|
|
873
|
+
role: "model"
|
|
874
|
+
},
|
|
875
|
+
finishReason: mapOpenAIFinishReasonToGemini(
|
|
876
|
+
choice.finish_reason || "stop"
|
|
877
|
+
),
|
|
878
|
+
index: 0,
|
|
879
|
+
safetyRatings: []
|
|
880
|
+
}
|
|
881
|
+
];
|
|
882
|
+
} else {
|
|
883
|
+
response.candidates = [];
|
|
884
|
+
}
|
|
885
|
+
response.responseId = openaiResponse.id;
|
|
886
|
+
response.createTime = openaiResponse.created ? openaiResponse.created.toString() : (/* @__PURE__ */ new Date()).getTime().toString();
|
|
887
|
+
response.modelVersion = openaiResponse.model || void 0;
|
|
888
|
+
response.promptFeedback = { safetyRatings: [] };
|
|
889
|
+
if (openaiResponse.usage) {
|
|
890
|
+
const usage = openaiResponse.usage;
|
|
891
|
+
const promptTokens = usage.prompt_tokens || 0;
|
|
892
|
+
const completionTokens = usage.completion_tokens || 0;
|
|
893
|
+
const totalTokens = usage.total_tokens || 0;
|
|
894
|
+
const extendedUsage = usage;
|
|
895
|
+
const cachedTokens = usage.prompt_tokens_details?.cached_tokens ?? extendedUsage.cached_tokens ?? 0;
|
|
896
|
+
const cachedInputTokensReported = typeof usage.prompt_tokens_details?.cached_tokens === "number" || typeof extendedUsage.cached_tokens === "number";
|
|
897
|
+
const providerReasoningTokens = usage.completion_tokens_details?.reasoning_tokens;
|
|
898
|
+
let thinkingTokens = providerReasoningTokens;
|
|
899
|
+
if (thinkingTokens == null) {
|
|
900
|
+
const estimatedThinkingTokens = estimateTextTokens(reasoningText ?? "");
|
|
901
|
+
thinkingTokens = completionTokens > 0 ? Math.min(estimatedThinkingTokens, completionTokens) : estimatedThinkingTokens;
|
|
902
|
+
if (thinkingTokens > 0) {
|
|
903
|
+
debugLogger2.debug(
|
|
904
|
+
`convertOpenAIResponseToGemini: reasoning_tokens absent; estimated ${thinkingTokens} from text`
|
|
905
|
+
);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
const hasTokenBreakdown = totalTokens === 0 || promptTokens !== 0 || completionTokens !== 0;
|
|
909
|
+
response.usageMetadata = {
|
|
910
|
+
...hasTokenBreakdown ? {
|
|
911
|
+
promptTokenCount: promptTokens,
|
|
912
|
+
candidatesTokenCount: completionTokens
|
|
913
|
+
} : {},
|
|
914
|
+
totalTokenCount: totalTokens,
|
|
915
|
+
cachedContentTokenCount: cachedTokens,
|
|
916
|
+
thoughtsTokenCount: thinkingTokens
|
|
917
|
+
};
|
|
918
|
+
setGenAiUsageProvenance(response.usageMetadata, {
|
|
919
|
+
cachedInputTokensReported
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
return response;
|
|
923
|
+
}
|
|
924
|
+
__name(convertOpenAIResponseToGemini, "convertOpenAIResponseToGemini");
|
|
925
|
+
function convertOpenAIChunkToGemini(chunk, requestContext) {
|
|
926
|
+
const choice = chunk.choices?.[0];
|
|
927
|
+
const response = new GenerateContentResponse();
|
|
928
|
+
const preparations = [];
|
|
929
|
+
const toolCallParser = requestContext.toolCallParser;
|
|
930
|
+
if (!toolCallParser) {
|
|
931
|
+
throw new Error(
|
|
932
|
+
"convertOpenAIChunkToGemini requires requestContext.toolCallParser \u2014 attach a fresh StreamingToolCallParser at stream start."
|
|
933
|
+
);
|
|
934
|
+
}
|
|
935
|
+
if (choice) {
|
|
936
|
+
let parts = [];
|
|
937
|
+
let contentParts = [];
|
|
938
|
+
const reasoningText = choice.delta?.reasoning_content ?? choice.delta?.reasoning;
|
|
939
|
+
if (typeof choice.delta?.content === "string") {
|
|
940
|
+
const normalizedContent = normalizeStreamingTextDelta(
|
|
941
|
+
choice.delta.content,
|
|
942
|
+
requestContext.textDeltaState ??= {
|
|
943
|
+
emittedText: "",
|
|
944
|
+
emittedLength: 0,
|
|
945
|
+
cumulativeMode: false
|
|
946
|
+
}
|
|
947
|
+
);
|
|
948
|
+
if (normalizedContent || choice.finish_reason) {
|
|
949
|
+
contentParts = convertOpenAITextToParts(
|
|
950
|
+
normalizedContent,
|
|
951
|
+
requestContext,
|
|
952
|
+
Boolean(choice.finish_reason)
|
|
953
|
+
);
|
|
954
|
+
}
|
|
955
|
+
} else if (choice.finish_reason) {
|
|
956
|
+
contentParts = convertOpenAITextToParts("", requestContext, true);
|
|
957
|
+
}
|
|
958
|
+
if (hasThoughtPart(contentParts)) {
|
|
959
|
+
requestContext.hasTaggedThinkingThought = true;
|
|
960
|
+
requestContext.pendingReasoningText = void 0;
|
|
961
|
+
debugLogger2.debug(
|
|
962
|
+
"convertOpenAIChunkToGemini: tagged thinking content emitted a thought; dropping buffered reasoning"
|
|
963
|
+
);
|
|
964
|
+
if (requestContext.pendingContentParts?.length) {
|
|
965
|
+
debugLogger2.debug(
|
|
966
|
+
`convertOpenAIChunkToGemini: flushing ${requestContext.pendingContentParts.length} buffered content part(s) before tagged content`
|
|
967
|
+
);
|
|
968
|
+
parts.push(...requestContext.pendingContentParts);
|
|
969
|
+
requestContext.pendingContentParts = void 0;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
if (reasoningText && (!requestContext.responseParsingOptions?.taggedThinkingTags || !requestContext.hasTaggedThinkingThought)) {
|
|
973
|
+
const reasoningDeltaState = requestContext.reasoningDeltaState ??= {
|
|
974
|
+
emittedText: "",
|
|
975
|
+
emittedLength: 0,
|
|
976
|
+
cumulativeMode: false
|
|
977
|
+
};
|
|
978
|
+
const normalizedReasoningText = normalizeStreamingTextDelta(
|
|
979
|
+
reasoningText,
|
|
980
|
+
reasoningDeltaState
|
|
981
|
+
);
|
|
982
|
+
if (normalizedReasoningText) {
|
|
983
|
+
reasoningDeltaState.emittedTokenUnits = (reasoningDeltaState.emittedTokenUnits ?? 0) + estimateTextTokenUnits(normalizedReasoningText);
|
|
984
|
+
requestContext.hasStructuredReasoningContent = true;
|
|
985
|
+
if (THINKING_TAG_PATTERN.test(normalizedReasoningText)) {
|
|
986
|
+
requestContext.hasThinkingTagInReasoning = true;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
if (normalizedReasoningText && !requestContext.responseParsingOptions?.taggedThinkingTags) {
|
|
990
|
+
parts.push(createOpenAIReasoningThoughtPart(normalizedReasoningText));
|
|
991
|
+
} else if (normalizedReasoningText && !requestContext.hasTaggedThinkingThought) {
|
|
992
|
+
requestContext.pendingReasoningText = (requestContext.pendingReasoningText ?? "") + normalizedReasoningText;
|
|
993
|
+
debugLogger2.debug(
|
|
994
|
+
`convertOpenAIChunkToGemini: buffered reasoning text (${requestContext.pendingReasoningText.length} chars) for tagged stream`
|
|
995
|
+
);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
if (requestContext.responseParsingOptions?.taggedThinkingTags && !requestContext.hasTaggedThinkingThought && requestContext.pendingReasoningText && contentParts.length) {
|
|
999
|
+
requestContext.pendingContentParts = [
|
|
1000
|
+
...requestContext.pendingContentParts ?? [],
|
|
1001
|
+
...contentParts
|
|
1002
|
+
];
|
|
1003
|
+
debugLogger2.debug(
|
|
1004
|
+
`convertOpenAIChunkToGemini: buffered ${contentParts.length} content part(s) behind pending reasoning`
|
|
1005
|
+
);
|
|
1006
|
+
contentParts = [];
|
|
1007
|
+
}
|
|
1008
|
+
if (choice.finish_reason && requestContext.responseParsingOptions?.taggedThinkingTags && !requestContext.hasTaggedThinkingThought && requestContext.pendingReasoningText) {
|
|
1009
|
+
debugLogger2.debug(
|
|
1010
|
+
"convertOpenAIChunkToGemini: flushing buffered reasoning for tagged stream with no tagged thought"
|
|
1011
|
+
);
|
|
1012
|
+
parts.push(
|
|
1013
|
+
createOpenAIReasoningThoughtPart(requestContext.pendingReasoningText)
|
|
1014
|
+
);
|
|
1015
|
+
requestContext.pendingReasoningText = void 0;
|
|
1016
|
+
}
|
|
1017
|
+
if (choice.finish_reason && requestContext.pendingContentParts?.length) {
|
|
1018
|
+
debugLogger2.debug(
|
|
1019
|
+
`convertOpenAIChunkToGemini: flushing ${requestContext.pendingContentParts.length} buffered content part(s) on stream finish`
|
|
1020
|
+
);
|
|
1021
|
+
parts.push(...requestContext.pendingContentParts);
|
|
1022
|
+
requestContext.pendingContentParts = void 0;
|
|
1023
|
+
}
|
|
1024
|
+
parts.push(...contentParts);
|
|
1025
|
+
if (choice.delta?.tool_calls) {
|
|
1026
|
+
for (const toolCall of choice.delta.tool_calls) {
|
|
1027
|
+
const index = toolCall.index ?? 0;
|
|
1028
|
+
const parseResult = toolCall.function?.arguments ? toolCallParser.addChunk(
|
|
1029
|
+
index,
|
|
1030
|
+
toolCall.function.arguments,
|
|
1031
|
+
toolCall.id,
|
|
1032
|
+
toolCall.function.name
|
|
1033
|
+
) : toolCallParser.addChunk(
|
|
1034
|
+
index,
|
|
1035
|
+
"",
|
|
1036
|
+
// Empty chunk for metadata-only updates
|
|
1037
|
+
toolCall.id,
|
|
1038
|
+
toolCall.function?.name
|
|
1039
|
+
);
|
|
1040
|
+
const { id: callId, name: toolName } = toolCallParser.getToolCallMeta(
|
|
1041
|
+
parseResult.actualIndex ?? index
|
|
1042
|
+
);
|
|
1043
|
+
if (callId && toolName) {
|
|
1044
|
+
const emitted = requestContext.preparedToolCallIds ??= /* @__PURE__ */ new Set();
|
|
1045
|
+
if (!emitted.has(callId)) {
|
|
1046
|
+
emitted.add(callId);
|
|
1047
|
+
preparations.push({ callId, toolName });
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
const getVisibleText = /* @__PURE__ */ __name((part) => part.thought !== true && typeof part.text === "string" ? part.text : "", "getVisibleText");
|
|
1053
|
+
let visibleText = parts.map(getVisibleText).join("");
|
|
1054
|
+
const pendingTagCandidate = requestContext.pendingThinkingTagCandidate;
|
|
1055
|
+
const replayedTagPrefix = !pendingTagCandidate?.closingTagName && /\S/.test(pendingTagCandidate?.text ?? "") && pendingTagCandidate?.text === visibleText;
|
|
1056
|
+
const replayedClosingTag = STANDALONE_CLOSING_THINKING_TAG_PATTERN.exec(
|
|
1057
|
+
visibleText
|
|
1058
|
+
)?.[1]?.toLowerCase();
|
|
1059
|
+
if (replayedTagPrefix || pendingTagCandidate?.closingTagName && pendingTagCandidate.closingTagName === replayedClosingTag) {
|
|
1060
|
+
parts = parts.filter((part) => !getVisibleText(part));
|
|
1061
|
+
visibleText = "";
|
|
1062
|
+
}
|
|
1063
|
+
const combinedCandidateText = (pendingTagCandidate?.text ?? "") + visibleText;
|
|
1064
|
+
const hasStructuredReasoning = requestContext.hasStructuredReasoningContent === true;
|
|
1065
|
+
const detectContentOnlyThinkingTagLeaks = requestContext.responseParsingOptions?.contentOnlyThinkingTagLeaks === true;
|
|
1066
|
+
const contentOnlyThinkingState = hasStructuredReasoning || requestContext.hasVisibleContent === true || !detectContentOnlyThinkingTagLeaks ? "clean" : classifyContentOnlyThinkingTagPrefix(
|
|
1067
|
+
combinedCandidateText,
|
|
1068
|
+
Boolean(choice.finish_reason)
|
|
1069
|
+
);
|
|
1070
|
+
const canStartTagCandidate = requestContext.hasVisibleContent !== true && visibleText.length > 0 && (hasStructuredReasoning && canBeStandaloneThinkingTagPrefix(combinedCandidateText) || contentOnlyThinkingState !== "clean");
|
|
1071
|
+
if (pendingTagCandidate || canStartTagCandidate) {
|
|
1072
|
+
const closingTag = STANDALONE_CLOSING_THINKING_TAG_PATTERN.exec(
|
|
1073
|
+
combinedCandidateText
|
|
1074
|
+
)?.[1]?.toLowerCase();
|
|
1075
|
+
const closingTagName = closingTag === "think" || closingTag === "thinking" ? closingTag : void 0;
|
|
1076
|
+
const openingTag = STANDALONE_OPENING_THINKING_TAG_PATTERN.test(
|
|
1077
|
+
combinedCandidateText
|
|
1078
|
+
);
|
|
1079
|
+
const isPossibleTag = canBeStandaloneThinkingTagPrefix(combinedCandidateText) || contentOnlyThinkingState === "pending" || contentOnlyThinkingState === "suspicious";
|
|
1080
|
+
const finishedWhitespaceCandidate = Boolean(choice.finish_reason) && !closingTagName && !/\S/.test(combinedCandidateText);
|
|
1081
|
+
const releaseContentOnlyCandidate = contentOnlyThinkingState === "pending" && (Boolean(choice.finish_reason) || combinedCandidateText.trimStart().length > MAX_THINKING_TAG_CANDIDATE_LENGTH);
|
|
1082
|
+
if (contentOnlyThinkingState === "leaked") {
|
|
1083
|
+
throwProtocolTagLeak(requestContext);
|
|
1084
|
+
}
|
|
1085
|
+
if (openingTag && hasStructuredReasoning) {
|
|
1086
|
+
throwProtocolTagLeak(requestContext);
|
|
1087
|
+
}
|
|
1088
|
+
if (pendingTagCandidate?.closingTagName && !closingTagName) {
|
|
1089
|
+
throwProtocolTagLeak(requestContext);
|
|
1090
|
+
}
|
|
1091
|
+
if (finishedWhitespaceCandidate || releaseContentOnlyCandidate) {
|
|
1092
|
+
parts = parts.filter((part) => !getVisibleText(part));
|
|
1093
|
+
if (combinedCandidateText) {
|
|
1094
|
+
parts.push({ text: combinedCandidateText });
|
|
1095
|
+
}
|
|
1096
|
+
visibleText = combinedCandidateText;
|
|
1097
|
+
requestContext.pendingThinkingTagCandidate = void 0;
|
|
1098
|
+
} else if (isPossibleTag) {
|
|
1099
|
+
if (!closingTagName && combinedCandidateText.trimStart().length > MAX_THINKING_TAG_CANDIDATE_LENGTH) {
|
|
1100
|
+
throwProtocolTagLeak(requestContext);
|
|
1101
|
+
}
|
|
1102
|
+
requestContext.pendingThinkingTagCandidate = closingTagName ? { text: `</${closingTagName}>`, closingTagName } : { text: combinedCandidateText };
|
|
1103
|
+
parts = parts.filter((part) => !getVisibleText(part));
|
|
1104
|
+
visibleText = "";
|
|
1105
|
+
if (choice.finish_reason && !closingTagName) {
|
|
1106
|
+
throwProtocolTagLeak(requestContext);
|
|
1107
|
+
}
|
|
1108
|
+
} else if (pendingTagCandidate) {
|
|
1109
|
+
parts = parts.filter((part) => !getVisibleText(part));
|
|
1110
|
+
parts.push({ text: combinedCandidateText });
|
|
1111
|
+
visibleText = combinedCandidateText;
|
|
1112
|
+
requestContext.pendingThinkingTagCandidate = void 0;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
const leakedThinkingTag = requestContext.hasStructuredReasoningContent === true && (requestContext.hasVisibleContent !== true && LEADING_THINKING_TAG_PATTERN.test(visibleText) || requestContext.hasThinkingTagInReasoning === true && (CLOSING_THINKING_TAG_PATTERN.test(visibleText) || requestContext.atVisibleLineStart === true && LEADING_CLOSING_THINKING_TAG_PATTERN.test(visibleText)));
|
|
1116
|
+
if (/\S/.test(visibleText)) {
|
|
1117
|
+
requestContext.hasVisibleContent = true;
|
|
1118
|
+
}
|
|
1119
|
+
if (visibleText && requestContext.hasThinkingTagInReasoning === true) {
|
|
1120
|
+
const lastLineBreak = visibleText.lastIndexOf("\n");
|
|
1121
|
+
const lineSuffix = visibleText.slice(lastLineBreak + 1);
|
|
1122
|
+
requestContext.atVisibleLineStart = (lastLineBreak >= 0 || requestContext.atVisibleLineStart === true) && /^[^\S\r\n]*$/.test(lineSuffix);
|
|
1123
|
+
}
|
|
1124
|
+
if (leakedThinkingTag) {
|
|
1125
|
+
throwProtocolTagLeak(requestContext);
|
|
1126
|
+
}
|
|
1127
|
+
const toolCallWithoutName = toolCallParser.hasNamelessToolCall();
|
|
1128
|
+
const completedToolCalls = choice.finish_reason ? toolCallParser.getCompletedToolCalls() : [];
|
|
1129
|
+
const toolCallsTruncated = choice.finish_reason ? toolCallParser.hasIncompleteToolCalls() : false;
|
|
1130
|
+
if (choice.finish_reason && requestContext.pendingThinkingTagCandidate?.closingTagName) {
|
|
1131
|
+
if (requestContext.hasThinkingTagInReasoning === true || choice.finish_reason !== "tool_calls" || completedToolCalls.length === 0 || toolCallWithoutName || toolCallParser.hasConflictingToolCallIdentity() || toolCallsTruncated || toolCallParser.hasInvalidToolCallArguments()) {
|
|
1132
|
+
throwProtocolTagLeak(requestContext);
|
|
1133
|
+
}
|
|
1134
|
+
requestContext.protocolTagSanitized = {
|
|
1135
|
+
tagName: requestContext.pendingThinkingTagCandidate.closingTagName,
|
|
1136
|
+
toolCallCount: completedToolCalls.length
|
|
1137
|
+
};
|
|
1138
|
+
requestContext.pendingThinkingTagCandidate = void 0;
|
|
1139
|
+
}
|
|
1140
|
+
if (choice.finish_reason && (toolCallParser.hasInvalidToolCallIndex() || toolCallWithoutName || choice.finish_reason === "tool_calls" && completedToolCalls.length === 0)) {
|
|
1141
|
+
requestContext.pendingUntrustedResponseParts = void 0;
|
|
1142
|
+
throw new InvalidStreamError(
|
|
1143
|
+
"Model response contained a malformed tool call.",
|
|
1144
|
+
"MALFORMED_TOOL_CALL"
|
|
1145
|
+
);
|
|
1146
|
+
}
|
|
1147
|
+
const shouldHoldParts = !choice.finish_reason && (toolCallWithoutName || requestContext.hasThinkingTagInReasoning === true || requestContext.pendingThinkingTagCandidate !== void 0);
|
|
1148
|
+
if (shouldHoldParts) {
|
|
1149
|
+
(requestContext.pendingUntrustedResponseParts ??= []).push(...parts);
|
|
1150
|
+
parts.length = 0;
|
|
1151
|
+
} else if (requestContext.pendingUntrustedResponseParts) {
|
|
1152
|
+
parts = requestContext.pendingUntrustedResponseParts.concat(parts);
|
|
1153
|
+
requestContext.pendingUntrustedResponseParts = void 0;
|
|
1154
|
+
}
|
|
1155
|
+
if (choice.finish_reason) {
|
|
1156
|
+
for (const toolCall of completedToolCalls) {
|
|
1157
|
+
if (toolCall.name) {
|
|
1158
|
+
parts.push({
|
|
1159
|
+
functionCall: {
|
|
1160
|
+
id: toolCall.id || `call_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`,
|
|
1161
|
+
name: toolCall.name,
|
|
1162
|
+
args: toolCall.args
|
|
1163
|
+
}
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
const effectiveFinishReason = toolCallsTruncated && choice.finish_reason !== "length" ? "length" : choice.finish_reason;
|
|
1169
|
+
const candidate = {
|
|
1170
|
+
content: {
|
|
1171
|
+
parts,
|
|
1172
|
+
role: "model"
|
|
1173
|
+
},
|
|
1174
|
+
index: 0,
|
|
1175
|
+
safetyRatings: []
|
|
1176
|
+
};
|
|
1177
|
+
if (effectiveFinishReason) {
|
|
1178
|
+
candidate.finishReason = mapOpenAIFinishReasonToGemini(
|
|
1179
|
+
effectiveFinishReason
|
|
1180
|
+
);
|
|
1181
|
+
}
|
|
1182
|
+
response.candidates = [candidate];
|
|
1183
|
+
} else {
|
|
1184
|
+
response.candidates = [];
|
|
1185
|
+
}
|
|
1186
|
+
response.responseId = chunk.id;
|
|
1187
|
+
response.createTime = chunk.created ? chunk.created.toString() : (/* @__PURE__ */ new Date()).getTime().toString();
|
|
1188
|
+
response.modelVersion = chunk.model || void 0;
|
|
1189
|
+
response.promptFeedback = { safetyRatings: [] };
|
|
1190
|
+
if (chunk.usage) {
|
|
1191
|
+
const usage = chunk.usage;
|
|
1192
|
+
const promptTokens = usage.prompt_tokens || 0;
|
|
1193
|
+
const completionTokens = usage.completion_tokens || 0;
|
|
1194
|
+
const totalTokens = usage.total_tokens || 0;
|
|
1195
|
+
const providerReasoningTokens = usage.completion_tokens_details?.reasoning_tokens;
|
|
1196
|
+
const estimatedThinkingTokens = Math.ceil(
|
|
1197
|
+
(requestContext.reasoningDeltaState?.emittedTokenUnits ?? 0) / TOKEN_ESTIMATE_UNITS_PER_TOKEN
|
|
1198
|
+
);
|
|
1199
|
+
const thinkingTokens = providerReasoningTokens ?? (completionTokens > 0 ? Math.min(estimatedThinkingTokens, completionTokens) : estimatedThinkingTokens);
|
|
1200
|
+
if (providerReasoningTokens == null && estimatedThinkingTokens > 0) {
|
|
1201
|
+
debugLogger2.debug(
|
|
1202
|
+
`convertOpenAIChunkToGemini: reasoning_tokens absent; estimated ${thinkingTokens} from streamed text`
|
|
1203
|
+
);
|
|
1204
|
+
}
|
|
1205
|
+
const extendedUsage = usage;
|
|
1206
|
+
const cachedTokens = usage.prompt_tokens_details?.cached_tokens ?? extendedUsage.cached_tokens ?? 0;
|
|
1207
|
+
const cachedInputTokensReported = typeof usage.prompt_tokens_details?.cached_tokens === "number" || typeof extendedUsage.cached_tokens === "number";
|
|
1208
|
+
const hasTokenBreakdown = totalTokens === 0 || promptTokens !== 0 || completionTokens !== 0;
|
|
1209
|
+
response.usageMetadata = {
|
|
1210
|
+
...hasTokenBreakdown ? {
|
|
1211
|
+
promptTokenCount: promptTokens,
|
|
1212
|
+
candidatesTokenCount: completionTokens
|
|
1213
|
+
} : {},
|
|
1214
|
+
thoughtsTokenCount: thinkingTokens,
|
|
1215
|
+
totalTokenCount: totalTokens,
|
|
1216
|
+
cachedContentTokenCount: cachedTokens
|
|
1217
|
+
};
|
|
1218
|
+
setGenAiUsageProvenance(response.usageMetadata, {
|
|
1219
|
+
cachedInputTokensReported
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
if (preparations.length > 0) {
|
|
1223
|
+
setToolCallPreparations(response, preparations);
|
|
1224
|
+
}
|
|
1225
|
+
return response;
|
|
1226
|
+
}
|
|
1227
|
+
__name(convertOpenAIChunkToGemini, "convertOpenAIChunkToGemini");
|
|
1228
|
+
function mapOpenAIFinishReasonToGemini(openaiReason) {
|
|
1229
|
+
if (!openaiReason) return FinishReason.FINISH_REASON_UNSPECIFIED;
|
|
1230
|
+
const mapping = {
|
|
1231
|
+
stop: FinishReason.STOP,
|
|
1232
|
+
length: FinishReason.MAX_TOKENS,
|
|
1233
|
+
content_filter: FinishReason.SAFETY,
|
|
1234
|
+
function_call: FinishReason.STOP,
|
|
1235
|
+
tool_calls: FinishReason.STOP
|
|
1236
|
+
};
|
|
1237
|
+
return mapping[openaiReason] || FinishReason.FINISH_REASON_UNSPECIFIED;
|
|
1238
|
+
}
|
|
1239
|
+
__name(mapOpenAIFinishReasonToGemini, "mapOpenAIFinishReasonToGemini");
|
|
1240
|
+
function mapGeminiFinishReasonToOpenAI(geminiReason) {
|
|
1241
|
+
if (!geminiReason) {
|
|
1242
|
+
return "stop";
|
|
1243
|
+
}
|
|
1244
|
+
switch (geminiReason) {
|
|
1245
|
+
case FinishReason.STOP:
|
|
1246
|
+
return "stop";
|
|
1247
|
+
case FinishReason.MAX_TOKENS:
|
|
1248
|
+
return "length";
|
|
1249
|
+
case FinishReason.SAFETY:
|
|
1250
|
+
case FinishReason.RECITATION:
|
|
1251
|
+
case FinishReason.BLOCKLIST:
|
|
1252
|
+
case FinishReason.PROHIBITED_CONTENT:
|
|
1253
|
+
case FinishReason.SPII:
|
|
1254
|
+
case FinishReason.IMAGE_SAFETY:
|
|
1255
|
+
case FinishReason.IMAGE_RECITATION:
|
|
1256
|
+
case FinishReason.IMAGE_PROHIBITED_CONTENT:
|
|
1257
|
+
case FinishReason.IMAGE_OTHER:
|
|
1258
|
+
return "content_filter";
|
|
1259
|
+
case FinishReason.NO_IMAGE:
|
|
1260
|
+
return "stop";
|
|
1261
|
+
default:
|
|
1262
|
+
return "stop";
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
__name(mapGeminiFinishReasonToOpenAI, "mapGeminiFinishReasonToOpenAI");
|
|
1266
|
+
function hasToolCalls(message) {
|
|
1267
|
+
return message.role === "assistant" && "tool_calls" in message && Array.isArray(message.tool_calls) && message.tool_calls.length > 0;
|
|
1268
|
+
}
|
|
1269
|
+
__name(hasToolCalls, "hasToolCalls");
|
|
1270
|
+
function isSplitToolMediaMessage(message) {
|
|
1271
|
+
if (message.role !== "user" || !("content" in message) || !Array.isArray(message.content)) {
|
|
1272
|
+
return false;
|
|
1273
|
+
}
|
|
1274
|
+
const firstPart = message.content[0];
|
|
1275
|
+
return firstPart?.type === "text" && firstPart.text === SPLIT_TOOL_MEDIA_TEXT;
|
|
1276
|
+
}
|
|
1277
|
+
__name(isSplitToolMediaMessage, "isSplitToolMediaMessage");
|
|
1278
|
+
function cleanOrphanedToolCalls(messages) {
|
|
1279
|
+
const cleaned = [];
|
|
1280
|
+
const validToolCallsByAssistant = /* @__PURE__ */ new Map();
|
|
1281
|
+
const validToolResponseIndexesByAssistant = /* @__PURE__ */ new Map();
|
|
1282
|
+
const splitMediaIndexesByAssistant = /* @__PURE__ */ new Map();
|
|
1283
|
+
const emittedWithAssistant = /* @__PURE__ */ new Set();
|
|
1284
|
+
const survivingToolCallIds = /* @__PURE__ */ new Set();
|
|
1285
|
+
for (let index = 0; index < messages.length; index += 1) {
|
|
1286
|
+
const message = messages[index];
|
|
1287
|
+
if (hasToolCalls(message)) {
|
|
1288
|
+
const candidateToolCalls = [];
|
|
1289
|
+
const candidateToolCallIds = /* @__PURE__ */ new Set();
|
|
1290
|
+
for (const toolCall of message.tool_calls) {
|
|
1291
|
+
const id = toolCall.id;
|
|
1292
|
+
if (!id || survivingToolCallIds.has(id)) {
|
|
1293
|
+
continue;
|
|
1294
|
+
}
|
|
1295
|
+
if (candidateToolCallIds.has(id)) {
|
|
1296
|
+
continue;
|
|
1297
|
+
}
|
|
1298
|
+
candidateToolCallIds.add(id);
|
|
1299
|
+
candidateToolCalls.push(toolCall);
|
|
1300
|
+
}
|
|
1301
|
+
const adjacentToolResponseIds = /* @__PURE__ */ new Set();
|
|
1302
|
+
const toolResponseIndexes = [];
|
|
1303
|
+
const splitMediaIndexes = [];
|
|
1304
|
+
let lastToolResponseMatchesAssistant = false;
|
|
1305
|
+
for (let nextIndex = index + 1; nextIndex < messages.length; nextIndex += 1) {
|
|
1306
|
+
const nextMessage = messages[nextIndex];
|
|
1307
|
+
if (nextMessage.role === "tool" && "tool_call_id" in nextMessage) {
|
|
1308
|
+
if (!nextMessage.tool_call_id) {
|
|
1309
|
+
lastToolResponseMatchesAssistant = false;
|
|
1310
|
+
continue;
|
|
1311
|
+
}
|
|
1312
|
+
if (candidateToolCallIds.has(nextMessage.tool_call_id) && !adjacentToolResponseIds.has(nextMessage.tool_call_id)) {
|
|
1313
|
+
adjacentToolResponseIds.add(nextMessage.tool_call_id);
|
|
1314
|
+
toolResponseIndexes.push(nextIndex);
|
|
1315
|
+
lastToolResponseMatchesAssistant = true;
|
|
1316
|
+
} else {
|
|
1317
|
+
lastToolResponseMatchesAssistant = false;
|
|
1318
|
+
}
|
|
1319
|
+
continue;
|
|
1320
|
+
}
|
|
1321
|
+
if (isSplitToolMediaMessage(nextMessage)) {
|
|
1322
|
+
if (lastToolResponseMatchesAssistant) {
|
|
1323
|
+
splitMediaIndexes.push(nextIndex);
|
|
1324
|
+
}
|
|
1325
|
+
continue;
|
|
1326
|
+
}
|
|
1327
|
+
if (nextMessage.role === "assistant" && !hasToolCalls(nextMessage)) {
|
|
1328
|
+
continue;
|
|
1329
|
+
}
|
|
1330
|
+
break;
|
|
1331
|
+
}
|
|
1332
|
+
const validToolCalls = candidateToolCalls.filter(
|
|
1333
|
+
(toolCall) => adjacentToolResponseIds.has(toolCall.id)
|
|
1334
|
+
);
|
|
1335
|
+
for (const toolCall of validToolCalls) {
|
|
1336
|
+
survivingToolCallIds.add(toolCall.id);
|
|
1337
|
+
}
|
|
1338
|
+
validToolCallsByAssistant.set(index, validToolCalls);
|
|
1339
|
+
validToolResponseIndexesByAssistant.set(index, toolResponseIndexes);
|
|
1340
|
+
splitMediaIndexesByAssistant.set(index, splitMediaIndexes);
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
for (let index = 0; index < messages.length; index += 1) {
|
|
1344
|
+
if (emittedWithAssistant.has(index)) {
|
|
1345
|
+
continue;
|
|
1346
|
+
}
|
|
1347
|
+
const message = messages[index];
|
|
1348
|
+
if (hasToolCalls(message)) {
|
|
1349
|
+
const reasoningContent = message.reasoning_content;
|
|
1350
|
+
const validToolCalls = validToolCallsByAssistant.get(index) ?? [];
|
|
1351
|
+
if (validToolCalls.length > 0) {
|
|
1352
|
+
const cleanedMessage = { ...message };
|
|
1353
|
+
cleanedMessage.tool_calls = validToolCalls;
|
|
1354
|
+
cleaned.push(cleanedMessage);
|
|
1355
|
+
for (const toolResponseIndex of validToolResponseIndexesByAssistant.get(
|
|
1356
|
+
index
|
|
1357
|
+
) ?? []) {
|
|
1358
|
+
const toolResponse = messages[toolResponseIndex];
|
|
1359
|
+
if (toolResponse) {
|
|
1360
|
+
cleaned.push(toolResponse);
|
|
1361
|
+
emittedWithAssistant.add(toolResponseIndex);
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
for (const splitMediaIndex of splitMediaIndexesByAssistant.get(index) ?? []) {
|
|
1365
|
+
const splitMediaMessage = messages[splitMediaIndex];
|
|
1366
|
+
if (splitMediaMessage) {
|
|
1367
|
+
cleaned.push(splitMediaMessage);
|
|
1368
|
+
emittedWithAssistant.add(splitMediaIndex);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
} else if (typeof message.content === "string" && message.content.trim() || reasoningContent) {
|
|
1372
|
+
const cleanedMessage = { ...message };
|
|
1373
|
+
delete cleanedMessage.tool_calls;
|
|
1374
|
+
cleaned.push(cleanedMessage);
|
|
1375
|
+
} else {
|
|
1376
|
+
debugLogger2.debug(
|
|
1377
|
+
`cleanOrphanedToolCalls: dropping assistant with ${message.tool_calls.length} orphaned tool call(s) and no text/reasoning content`
|
|
1378
|
+
);
|
|
1379
|
+
}
|
|
1380
|
+
} else if (message.role === "tool" && "tool_call_id" in message) {
|
|
1381
|
+
debugLogger2.debug(
|
|
1382
|
+
`cleanOrphanedToolCalls: dropping orphaned tool response ${message.tool_call_id || "<empty>"}`
|
|
1383
|
+
);
|
|
1384
|
+
} else if (isSplitToolMediaMessage(message)) {
|
|
1385
|
+
debugLogger2.debug(
|
|
1386
|
+
"cleanOrphanedToolCalls: dropping orphaned split tool media message"
|
|
1387
|
+
);
|
|
1388
|
+
} else {
|
|
1389
|
+
cleaned.push(message);
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
return cleaned;
|
|
1393
|
+
}
|
|
1394
|
+
__name(cleanOrphanedToolCalls, "cleanOrphanedToolCalls");
|
|
1395
|
+
function mergeConsecutiveAssistantMessages(messages) {
|
|
1396
|
+
const merged = [];
|
|
1397
|
+
for (const message of messages) {
|
|
1398
|
+
if (message.role === "assistant" && merged.length > 0) {
|
|
1399
|
+
const lastMessage = merged[merged.length - 1];
|
|
1400
|
+
if (lastMessage.role === "assistant") {
|
|
1401
|
+
const lastToolCalls = "tool_calls" in lastMessage ? lastMessage.tool_calls || [] : [];
|
|
1402
|
+
const currentToolCalls = "tool_calls" in message ? message.tool_calls || [] : [];
|
|
1403
|
+
const lastContent = lastMessage.content;
|
|
1404
|
+
const currentContent = message.content;
|
|
1405
|
+
const useArrayFormat = Array.isArray(lastContent) || Array.isArray(currentContent);
|
|
1406
|
+
let combinedContent;
|
|
1407
|
+
if (useArrayFormat) {
|
|
1408
|
+
const lastParts = Array.isArray(lastContent) ? lastContent : typeof lastContent === "string" && lastContent ? [{ type: "text", text: lastContent }] : [];
|
|
1409
|
+
const currentParts = Array.isArray(currentContent) ? currentContent : typeof currentContent === "string" && currentContent ? [{ type: "text", text: currentContent }] : [];
|
|
1410
|
+
combinedContent = [
|
|
1411
|
+
...lastParts,
|
|
1412
|
+
...currentParts
|
|
1413
|
+
];
|
|
1414
|
+
} else {
|
|
1415
|
+
const lastText = typeof lastContent === "string" ? lastContent : "";
|
|
1416
|
+
const currentText = typeof currentContent === "string" ? currentContent : "";
|
|
1417
|
+
const mergedText = [lastText, currentText].filter(Boolean).join("");
|
|
1418
|
+
combinedContent = mergedText || null;
|
|
1419
|
+
}
|
|
1420
|
+
const combinedToolCalls = [...lastToolCalls, ...currentToolCalls];
|
|
1421
|
+
lastMessage.content = combinedContent || null;
|
|
1422
|
+
if (combinedToolCalls.length > 0) {
|
|
1423
|
+
lastMessage.tool_calls = combinedToolCalls;
|
|
1424
|
+
}
|
|
1425
|
+
const lastReasoning = lastMessage.reasoning_content;
|
|
1426
|
+
const currentReasoning = message.reasoning_content;
|
|
1427
|
+
const combinedReasoning = [lastReasoning, currentReasoning].filter(Boolean).join("");
|
|
1428
|
+
if (combinedReasoning) {
|
|
1429
|
+
lastMessage.reasoning_content = combinedReasoning;
|
|
1430
|
+
}
|
|
1431
|
+
continue;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
merged.push(message);
|
|
1435
|
+
}
|
|
1436
|
+
return merged;
|
|
1437
|
+
}
|
|
1438
|
+
__name(mergeConsecutiveAssistantMessages, "mergeConsecutiveAssistantMessages");
|
|
1439
|
+
var OpenAIContentConverter = {
|
|
1440
|
+
convertGeminiToolParametersToOpenAI,
|
|
1441
|
+
convertGeminiToolsToOpenAI,
|
|
1442
|
+
convertGeminiRequestToOpenAI,
|
|
1443
|
+
convertGeminiResponseToOpenAI,
|
|
1444
|
+
convertOpenAIResponseToGemini,
|
|
1445
|
+
convertOpenAIChunkToGemini
|
|
1446
|
+
};
|
|
1447
|
+
|
|
1448
|
+
// packages/core/src/core/openaiContentGenerator/requestCaptureContext.ts
|
|
1449
|
+
init_esbuild_shims();
|
|
1450
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
1451
|
+
var openaiRequestCaptureContext = new AsyncLocalStorage();
|
|
1452
|
+
|
|
1453
|
+
export {
|
|
1454
|
+
TaggedThinkingParser,
|
|
1455
|
+
OpenAIContentConverter,
|
|
1456
|
+
openaiRequestCaptureContext
|
|
1457
|
+
};
|
|
1458
|
+
/**
|
|
1459
|
+
* @license
|
|
1460
|
+
* Copyright 2025 Qwen
|
|
1461
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1462
|
+
*/
|