nolo-cli 0.264.0-alpha.2 → 0.266.0-alpha.1
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/{chunk-LXP53WGF.js → chunk-05wkntba.js} +44 -40
- package/{chunk-XFYFMTOM.js → chunk-08ts2q1n.js} +9 -11
- package/{chromeCommands-MVEEIY4R.js → chunk-0a3m1n6h.js} +182 -238
- package/chunk-0gfvc7g8.js +13 -0
- package/{chunk-CF7PE763.js → chunk-0h0sncy4.js} +3 -4
- package/{chunk-3UH7SS4W.js → chunk-0nsxwrge.js} +232 -241
- package/chunk-0ra8cne4.js +11 -0
- package/{chunk-MRACVEPZ.js → chunk-0sgwk7am.js} +1 -3
- package/{chunk-PEXGRTTQ.js → chunk-0tsfn0dk.js} +44 -45
- package/{chunk-WOAZVUSN.js → chunk-0y8cbwzy.js} +26 -30
- package/chunk-12gz55kk.js +6 -0
- package/{chunk-GLKOYSRU.js → chunk-186gshgw.js} +3 -6
- package/chunk-19w4ss38.js +44 -0
- package/{chunk-RF576RYE.js → chunk-1cakzp6r.js} +23 -23
- package/chunk-1fbfwbzp.js +27 -0
- package/{chunk-4IVMDQBA.js → chunk-1fv9k8zt.js} +103 -68
- package/{chunk-Q5FJJ6XI.js → chunk-1js4cdzp.js} +11 -19
- package/{chunk-YECCIUYU.js → chunk-1nhx0er5.js} +63 -63
- package/chunk-1p152b7g.js +12 -0
- package/{chunk-HXEO5DNV.js → chunk-1ynbq3yr.js} +322 -353
- package/{chunk-6UBGXX2W.js → chunk-1zrg4h5n.js} +3 -4
- package/{chunk-Y5GCAMGP.js → chunk-2g6zsfq8.js} +1 -3
- package/chunk-2hekb0eh.js +17 -0
- package/chunk-2pj6qzq5.js +12 -0
- package/chunk-2tvd4jyp.js +226 -0
- package/chunk-2ygg7azv.js +846 -0
- package/chunk-33405wtv.js +50 -0
- package/chunk-34axejtd.js +30 -0
- package/{tableCommands-FCPDULSU.js → chunk-3700dvt3.js} +224 -276
- package/{pdf-KE3QI2V7.js → chunk-3j08t1nm.js} +12505 -10133
- package/chunk-3j9gq18v.js +111 -0
- package/{chunk-LYPJYBE5.js → chunk-3qfpcdkm.js} +486 -505
- package/{settingThunks-PNC7ZISV.js → chunk-3r2x7h64.js} +189 -272
- package/{agentGrantCommands-2VLLXGIU.js → chunk-3tbj5fxt.js} +61 -56
- package/chunk-40whhjj5.js +168 -0
- package/chunk-4301919y.js +7 -0
- package/chunk-43adz39e.js +77 -0
- package/{chunk-5ZUL4CUO.js → chunk-49v3zc4g.js} +1 -3
- package/chunk-4dd7mxkb.js +72 -0
- package/{chunk-BKP325XS.js → chunk-4hapfzpq.js} +66 -62
- package/chunk-4mm7dz0m.js +95 -0
- package/chunk-4pqxempz.js +440 -0
- package/chunk-4x9zf5pv.js +10 -0
- package/{chunk-CA7LGAHV.js → chunk-511q8qzv.js} +66 -57
- package/{chunk-U7OULUMF.js → chunk-53v9g0np.js} +49 -64
- package/chunk-572mg6q5.js +19 -0
- package/{chunk-QAW6BEWQ.js → chunk-57eyhmwr.js} +17173 -16165
- package/chunk-5hsr0zjm.js +156 -0
- package/chunk-5k883yyd.js +20 -0
- package/chunk-5m0wsee4.js +639 -0
- package/{memberThunks-NEZRAW5K.js → chunk-5r1sq2gt.js} +299 -373
- package/chunk-648rq4np.js +255 -0
- package/{chunk-IYRZKHA6.js → chunk-666yjw5c.js} +63 -86
- package/{chunk-4O22PGNQ.js → chunk-6cdcbmtp.js} +19 -19
- package/chunk-6dbyqcf7.js +59 -0
- package/{agentProviderCommands-2W3VXDLV.js → chunk-6e8mgp1x.js} +82 -105
- package/chunk-6n0pw7sx.js +44 -0
- package/chunk-6q1b7381.js +361 -0
- package/chunk-6sj756ry.js +23 -0
- package/{chunk-4UNN45DS.js → chunk-6t7a7zck.js} +14785 -14454
- package/chunk-6yarwtxh.js +776 -0
- package/chunk-708h542p.js +18 -0
- package/chunk-76f076t8.js +266 -0
- package/chunk-782rrrwv.js +523 -0
- package/{workloadLifecycle-P2SJVV3S.js → chunk-7gk330wp.js} +77 -84
- package/{chunk-EZKIRVLJ.js → chunk-7ks60vxy.js} +146 -128
- package/{chunk-FI4DPLR7.js → chunk-7mrqbxe8.js} +342 -228
- package/chunk-7sztayrd.js +169 -0
- package/chunk-7vgt2mxz.js +15 -0
- package/{localFirstLog-OIETGK66.js → chunk-7z8y4k6y.js} +0 -2
- package/{chunk-KDDXC2IH.js → chunk-82htft2m.js} +49 -11
- package/{updateDialogTitleAction-XOSLNRT3.js → chunk-88vrtxxg.js} +65 -137
- package/{chunk-LS5KAVFQ.js → chunk-8dtjbp79.js} +293 -229
- package/chunk-8fajbkaz.js +50 -0
- package/chunk-8m1ebxpw.js +65 -0
- package/{accountResolver-JYG5L7YP.js → chunk-8mgfeg0w.js} +37 -30
- package/{chunk-LPXBBC32.js → chunk-8myksy35.js} +156 -160
- package/{chunk-BMQ2MJUK.js → chunk-8nrj7dc7.js} +75 -66
- package/{commandRegistry-ENNFT77C.js → chunk-8t8x64ec.js} +228 -286
- package/chunk-8yj4pq79.js +458 -0
- package/{chunk-5MKPNTJP.js → chunk-8z6pepcx.js} +43 -48
- package/{chunk-UYQILGDR.js → chunk-90egc9vb.js} +122 -102
- package/{chunk-EODBQPRM.js → chunk-91q5dc5r.js} +10 -14
- package/{chunk-U6VC4MU4.js → chunk-96jtrqk1.js} +2 -4
- package/{chunk-H57T64RA.js → chunk-996j61av.js} +28 -31
- package/{chunk-Q6FKWH66.js → chunk-9cxgb9jy.js} +137 -243
- package/{chunk-2ZBPWX7N.js → chunk-9q1gbmet.js} +62 -104
- package/chunk-9qtjh73q.js +344 -0
- package/{chunk-SR57FDTX.js → chunk-9raka469.js} +72 -155
- package/{chunk-V6K5U4YE.js → chunk-9vh4v046.js} +32 -41
- package/{chunk-AGIM7IMJ.js → chunk-9yr1fy7j.js} +14 -49
- package/{chunk-FGFJUFPS.js → chunk-a16x0wt6.js} +11 -18
- package/chunk-a5b2rvzs.js +131 -0
- package/{chunk-7DPNBQSV.js → chunk-a7bz6nc3.js} +3 -4
- package/chunk-ac85azv9.js +29 -0
- package/{chunk-VXL2FZTP.js → chunk-ahhbkad4.js} +16 -20
- package/{chunk-37DGW762.js → chunk-anhksj2j.js} +16 -29
- package/{cliAuthorityBrokerServer-27C5YBYP.js → chunk-atvmx76t.js} +180 -186
- package/{chunk-E6A5NHDH.js → chunk-av2mzeqz.js} +16 -17
- package/chunk-avbwrb0z.js +614 -0
- package/chunk-avr6rqe5.js +544 -0
- package/{workContextQueryProjection-CACY5VFE.js → chunk-axx60d5a.js} +7 -7
- package/{chunk-EWQ3HGNZ.js → chunk-b00vzjkb.js} +30 -23
- package/chunk-b0m6ezxr.js +132 -0
- package/chunk-bbd5mgdt.js +47 -0
- package/chunk-bcecft0r.js +28 -0
- package/chunk-beyr4pyp.js +33 -0
- package/{chunk-BR3GT6MR.js → chunk-bge0cagn.js} +7 -18
- package/{offlineMarxistsAgentCommand-MFURGWHL.js → chunk-bh53zg3t.js} +33 -43
- package/chunk-bmx1cw89.js +37 -0
- package/chunk-br2195h4.js +22 -0
- package/chunk-bsqkwveq.js +56 -0
- package/{chunk-QAU6KM2U.js → chunk-c09s2z1m.js} +139 -98
- package/chunk-c235kypv.js +24636 -0
- package/{chunk-2JMYAH5O.js → chunk-c30j6pyh.js} +213 -256
- package/chunk-c3v6r6sq.js +29 -0
- package/{chunk-PDSXYHNI.js → chunk-c5z7qspt.js} +1177 -1196
- package/{chunk-GWB6AGME.js → chunk-c6jvz0mp.js} +34 -50
- package/{chunk-PRJ473FK.js → chunk-cd6h9qqs.js} +14 -12
- package/chunk-cdt0amyy.js +37 -0
- package/{chunk-2AJLG6PY.js → chunk-cfh6tfc3.js} +73 -86
- package/{chunk-WIVVNJUS.js → chunk-ch4ck1yz.js} +38 -68
- package/chunk-chtvrtp5.js +55 -0
- package/{chunk-EYLGAEB4.js → chunk-ckvz7abv.js} +170 -165
- package/{chunk-YZMNK53S.js → chunk-csf18m5w.js} +32 -25
- package/{chunk-C36L6ZID.js → chunk-cwnvf8dt.js} +2 -10
- package/chunk-cy7thb6n.js +19877 -0
- package/{dialogPortabilityCommands-YQJNB2KL.js → chunk-d61q9nah.js} +439 -487
- package/chunk-d6xdy0gp.js +142 -0
- package/{chunk-EBH4RFJ6.js → chunk-dh69vqbd.js} +6390 -6496
- package/{chunk-KJ4J2XQB.js → chunk-dj4ggbc6.js} +17 -19
- package/{chunk-LISC7BD4.js → chunk-djrrhbk3.js} +29 -37
- package/chunk-drqzzzvr.js +822 -0
- package/chunk-e1n7edjk.js +33 -0
- package/chunk-e3atr4hk.js +59 -0
- package/chunk-e9bn2aav.js +13 -0
- package/chunk-ed396rfq.js +87 -0
- package/chunk-eha8ggh6.js +10 -0
- package/{chunk-MALPQFGT.js → chunk-ek122zzt.js} +893 -948
- package/chunk-epnmvek4.js +22 -0
- package/{chunk-S25VJYXV.js → chunk-eqzvk3xm.js} +69 -80
- package/chunk-ex34n71b.js +2874 -0
- package/{chunk-56OAS5RZ.js → chunk-f3ad6q4h.js} +7 -11
- package/{chunk-3PVYUPXK.js → chunk-f8jepva1.js} +6 -7
- package/{chunk-GH34JXNV.js → chunk-f9yvy9t9.js} +114 -92
- package/chunk-fbdz4f0j.js +90 -0
- package/{chunk-J44TXB4J.js → chunk-fcsc2day.js} +216 -164
- package/chunk-fevdhnbh.js +19 -0
- package/chunk-fkrgqq8w.js +3300 -0
- package/{chunk-TSBJVMNW.js → chunk-fs3bvh2p.js} +42 -57
- package/chunk-fvwzyhah.js +134 -0
- package/chunk-g0mpxdp9.js +101 -0
- package/{chunk-LTQ6ECCF.js → chunk-g35f20d1.js} +450 -414
- package/{chunk-3L2WKC3W.js → chunk-g5fhtjqg.js} +13 -16
- package/{chunk-DBEOW57U.js → chunk-gcq01td7.js} +270 -227
- package/{chunk-ADMRXWXJ.js → chunk-ge97b11r.js} +121 -42
- package/chunk-ghjtgbkw.js +180 -0
- package/chunk-gkra36c1.js +16 -0
- package/chunk-gmz86t60.js +1000 -0
- package/{localDialogRead-GWGWSL5K.js → chunk-gszpesze.js} +5 -12
- package/chunk-gvsfec9m.js +16536 -0
- package/{chunk-QSJ3HFEF.js → chunk-h1hzmqph.js} +1 -3
- package/chunk-h30dg154.js +17 -0
- package/chunk-h3hkb7cw.js +241 -0
- package/chunk-h40py996.js +28 -0
- package/{chunk-47T3QP4V.js → chunk-h60gnewh.js} +112 -116
- package/{agentPullCommand-XEGOUYQT.js → chunk-hkwsv9xf.js} +33 -45
- package/chunk-hnyg0gwj.js +28 -0
- package/{chunk-KSV6T4AH.js → chunk-hqqqph5w.js} +12 -4
- package/{chunk-YQJEXXDK.js → chunk-hrngs1wy.js} +157 -246
- package/{chunk-LRLLWD4P.js → chunk-htf69s94.js} +14 -12
- package/chunk-j0yxesh3.js +83 -0
- package/{chunk-VF4K2QE6.js → chunk-j22t9g05.js} +3 -6
- package/{chunk-3R4AYHJR.js → chunk-j4a8m2zn.js} +5 -34
- package/chunk-j9p4jnwg.js +27 -0
- package/{chunk-R72QWIFO.js → chunk-jdycmfsm.js} +9 -9
- package/chunk-jdyvrne0.js +52 -0
- package/{spacePruneCommand-YKIEUIDQ.js → chunk-je0b66qf.js} +44 -62
- package/{chunk-HNMXYYJR.js → chunk-jec44fkj.js} +3 -4
- package/{chunk-526GLZJE.js → chunk-jf1ex00r.js} +107 -73
- package/chunk-jgqdec9b.js +31 -0
- package/{chunk-56GBUMO5.js → chunk-jkw9n4h5.js} +16 -25
- package/{chunk-7422ZLGL.js → chunk-jmnzdwjt.js} +867 -965
- package/chunk-jqq57s0a.js +58 -0
- package/{chunk-OKUSDVRS.js → chunk-jtkn5aj6.js} +27 -38
- package/chunk-jwvzn9r0.js +316 -0
- package/chunk-k1re0fc7.js +107 -0
- package/chunk-k2ep3rb2.js +103 -0
- package/{chunk-JEXVIMYZ.js → chunk-k6ycb24w.js} +5 -8
- package/{chunk-RI7SXDJW.js → chunk-kawvydbk.js} +383 -195
- package/chunk-kf2ghpzh.js +10 -0
- package/{chunk-S6FAHQDH.js → chunk-kgah9e46.js} +28 -59
- package/{chunk-T3MWVUBE.js → chunk-kjjepkvc.js} +71 -82
- package/chunk-kn4dgg4j.js +4113 -0
- package/{chunk-2LFYMWM3.js → chunk-kn5p91n8.js} +43 -53
- package/{chunk-MVOZ22RZ.js → chunk-kntqrbwc.js} +8 -12
- package/{chunk-I6YIA2TY.js → chunk-kq3vr7mx.js} +25 -20
- package/chunk-kz1x1d8n.js +15 -0
- package/{mcpLocalAuthorizeCommand-IKOFKY5U.js → chunk-m22e7tt2.js} +53 -71
- package/{chunk-ZNFJWEN4.js → chunk-m32rwr4d.js} +11 -8
- package/chunk-m39e9m18.js +93 -0
- package/{chunk-4D4QD7FT.js → chunk-m5518371.js} +64 -56
- package/{chunk-LHTXSC2E.js → chunk-mb5hnfyp.js} +9 -11
- package/chunk-mexet11v.js +11 -0
- package/chunk-mg2hgfgh.js +185 -0
- package/chunk-mmdhm4kx.js +10317 -0
- package/chunk-mz002yz8.js +2821 -0
- package/chunk-mzadqnyq.js +56 -0
- package/{chunk-VIDPVFP3.js → chunk-n3r1ebdm.js} +5 -6
- package/chunk-n438qea7.js +33 -0
- package/chunk-n5ffnhnb.js +93 -0
- package/chunk-nbvd87fy.js +9 -0
- package/{chunk-E36V7MPY.js → chunk-ndej7jc9.js} +53 -43
- package/{chunk-B767MA64.js → chunk-nen6rwe4.js} +62 -22
- package/chunk-nf06tr3v.js +16 -0
- package/chunk-ng8z355q.js +16 -0
- package/{chunk-4MEKE5D3.js → chunk-nhtxfv8k.js} +78 -63
- package/{runAgentClientLoop-2SFASHDS.js → chunk-nj62jscj.js} +132 -214
- package/{chunk-GBWGPTA7.js → chunk-nkryrkyp.js} +16 -19
- package/chunk-nmesxem8.js +197 -0
- package/{chunk-YR4J7RFS.js → chunk-nmq0qwbn.js} +117 -164
- package/chunk-nph8brvw.js +7 -0
- package/chunk-nr8fees9.js +10 -0
- package/{chunk-DFI7MVCQ.js → chunk-nvewvf7h.js} +1441 -1427
- package/{chunk-G7Y4GXTY.js → chunk-nyamhphs.js} +70 -79
- package/chunk-nz1c8tcg.js +111 -0
- package/{chunk-GPLUFN2E.js → chunk-nzc5yffh.js} +176 -217
- package/{chunk-G3SUCT4W.js → chunk-p1vg4bx8.js} +2 -4
- package/chunk-p3k3abe8.js +202 -0
- package/chunk-p4zy30q5.js +8 -0
- package/{chunk-ZJACPM5O.js → chunk-p6se1rx0.js} +102 -102
- package/chunk-p9dpshev.js +6968 -0
- package/chunk-pa42wxr0.js +116 -0
- package/{chunk-TA5QI4MM.js → chunk-paxthgqp.js} +56 -107
- package/{readlineWorkspace-ZH5FGDMI.js → chunk-pb35s8d9.js} +5395 -5786
- package/{chunk-XT6C2QZW.js → chunk-pbebzbcq.js} +8 -8
- package/chunk-pbx7e1mb.js +11 -0
- package/chunk-pe5czfn9.js +8 -0
- package/chunk-pextk1j4.js +62 -0
- package/chunk-pf5rywc6.js +575 -0
- package/chunk-pjfhd3fz.js +136 -0
- package/{chunk-ZCMAKAZM.js → chunk-pkhqb0fs.js} +118 -59
- package/chunk-pm5xb9jh.js +26 -0
- package/{chunk-Y3KGWZKF.js → chunk-ppdmmdkx.js} +110 -97
- package/chunk-pqp6y2hs.js +9 -0
- package/{chunk-QHEN7NZ7.js → chunk-ptz8fm2n.js} +12 -17
- package/{chunk-EUHMI5KG.js → chunk-pwqnvbt7.js} +65 -46
- package/chunk-pzr31nz7.js +12 -0
- package/{chunk-WWC7I6TA.js → chunk-q3cx89sw.js} +2 -4
- package/chunk-q5pe7be3.js +78 -0
- package/{chunk-ZHWTBHT3.js → chunk-q6zqbxp2.js} +418 -409
- package/chunk-q7r0e1p3.js +15 -0
- package/chunk-q8t2fecd.js +6 -0
- package/{chunk-2QAZCYOM.js → chunk-q94zx4d0.js} +721 -753
- package/{runtimeDoctorCommands-52MBG5JN.js → chunk-qarz1az1.js} +65 -85
- package/{chunk-4INJGWE3.js → chunk-qdcvr25b.js} +72 -53
- package/{streamAgentChatTurn-KOUWITHH.js → chunk-qxs27wfg.js} +1079 -1475
- package/{chunk-GIXWVN2W.js → chunk-r06ycjjr.js} +50 -47
- package/{chunk-63W5N6P3.js → chunk-r20jw5hb.js} +57 -38
- package/{chunk-I5BYFTYK.js → chunk-r7sfwdka.js} +1201 -1142
- package/{chunk-UMADT6B2.js → chunk-r9sp1yyb.js} +6 -8
- package/{handleSendMessageAction-FHGUFT2X.js → chunk-rbd2vgb3.js} +627 -757
- package/chunk-rc37js46.js +12 -0
- package/{chunk-5YI447UL.js → chunk-rmngk6r3.js} +67 -76
- package/chunk-rnhbnbrq.js +15 -0
- package/{chunk-WRHVVIGI.js → chunk-rsfnmrt5.js} +111 -131
- package/{chunk-YFSM2366.js → chunk-rvvn2rhj.js} +28 -22
- package/{chunk-4Y6CZ2N4.js → chunk-s0fpz7ht.js} +37 -33
- package/{chunk-VI4SWTUO.js → chunk-s1cqzb2r.js} +77 -65
- package/{chunk-6QDYSCPW.js → chunk-s8q81tda.js} +73 -65
- package/chunk-s9hy639e.js +6 -0
- package/{chunk-R5GO3YZP.js → chunk-s9vbwme8.js} +115 -106
- package/chunk-sger1m1b.js +20 -0
- package/chunk-spe6crvk.js +60 -0
- package/chunk-spwsrvh9.js +70 -0
- package/chunk-sr05zpk7.js +573 -0
- package/{chunk-M2EJHDJP.js → chunk-srncrd3f.js} +1 -12
- package/{chunk-QXHFIX7W.js → chunk-sry80bpx.js} +71 -53
- package/{chunk-PSCNXBYA.js → chunk-t6q69p83.js} +3 -4
- package/{chunk-UAD2WT54.js → chunk-t714r4q0.js} +9 -28
- package/chunk-t7vbraqe.js +42 -0
- package/{chunk-CVMMWN6P.js → chunk-td7653rr.js} +10 -20
- package/{chunk-3BQDF4QB.js → chunk-tmytcetz.js} +17 -21
- package/{chunk-AMWMV56B.js → chunk-tta4prwg.js} +16 -15
- package/chunk-tvh8azgq.js +4829 -0
- package/{chunk-ID4G2MAR.js → chunk-v08kbfm8.js} +10 -11
- package/{chunk-OKPOQGQJ.js → chunk-v1x702q8.js} +801 -852
- package/{chunk-KHCLMKZZ.js → chunk-v39fea91.js} +576 -247
- package/{chunk-OW765XBU.js → chunk-vejtd8p2.js} +3 -4
- package/chunk-vep7zkha.js +368 -0
- package/chunk-vfwn1k7n.js +142 -0
- package/chunk-vg68vxhx.js +20 -0
- package/chunk-vgcqgnsm.js +31 -0
- package/{chunk-NF64D32W.js → chunk-vnzyjdea.js} +1 -3
- package/{chunk-ZCLSM5AK.js → chunk-vqgtw1px.js} +800 -717
- package/chunk-vv1gr5xz.js +76 -0
- package/{spaceCommands-Z2CTQD6G.js → chunk-w1qeadpq.js} +176 -242
- package/chunk-w468ez1p.js +13 -0
- package/chunk-w49s0t79.js +14 -0
- package/{mcpLocalManageCommands-KUDZQRM4.js → chunk-w58zhfbn.js} +91 -93
- package/chunk-w5b74aq6.js +11 -0
- package/chunk-w7y41qyw.js +117 -0
- package/chunk-w820gg1w.js +4165 -0
- package/{chunk-DBJAJ4UD.js → chunk-wdsmaqmt.js} +399 -453
- package/{chunk-3EUW3WEO.js → chunk-wfvvnmmj.js} +1 -3
- package/{chunk-QY4NZCDA.js → chunk-wkr04bhk.js} +432 -651
- package/{chunk-KUG52IAP.js → chunk-ws402twv.js} +1 -3
- package/chunk-wzwh311q.js +164 -0
- package/{runtimeModeArgs-X7DL7PUN.js → chunk-x5vtgvwn.js} +6 -5
- package/{agentMachineCommands-COJD2KPZ.js → chunk-x8h2csmq.js} +152 -195
- package/{chunk-BAZCS5XG.js → chunk-x9zfjnrc.js} +59 -47
- package/{chunk-WTIJKWCI.js → chunk-xcarc2rf.js} +50 -56
- package/chunk-xf33gz0a.js +8 -0
- package/{chunk-PVFYPUIM.js → chunk-y7b3gwx1.js} +78 -71
- package/{memoryCommands-SVLAVFCV.js → chunk-y7sphmnh.js} +119 -95
- package/{agentListCommands-436FHOIT.js → chunk-ycvaafhc.js} +260 -374
- package/chunk-yd7zprb0.js +9 -0
- package/chunk-yfz3d27k.js +40 -0
- package/{chunk-MKR6KDD3.js → chunk-ykv9g3m4.js} +141 -125
- package/chunk-ystjgb9e.js +544 -0
- package/chunk-yysxn7ep.js +12 -0
- package/{chunk-AL3TYDIF.js → chunk-z17eyawk.js} +18 -16
- package/{machineCommands-RVB5OG2X.js → chunk-z17q416p.js} +442 -563
- package/chunk-z1n98pcf.js +12 -0
- package/{dialogTraceCommand-HWXGIGZX.js → chunk-z566jx5r.js} +292 -397
- package/chunk-zjxd6942.js +6 -0
- package/{versionChangeNotice-RFABJGJE.js → chunk-zk11x9y5.js} +7 -9
- package/{chunk-TEFD5E2D.js → chunk-zt73yc33.js} +48 -51
- package/chunk-zvs2fra1.js +5 -0
- package/{chunk-SVFFKLMR.js → chunk-zwee84rh.js} +117 -141
- package/chunk-zxgfqv72.js +8 -0
- package/index.js +53 -69
- package/package.json +4 -4
- package/_executeModel-YQNZNR2Y.js +0 -341
- package/action-UK3HXGXF.js +0 -30
- package/addContentAction-CAKFVBDM.js +0 -38
- package/addDialogAgentAction-KLJ2YWWM.js +0 -77
- package/agentDeleteCommand-S5FVPYKT.js +0 -523
- package/agentEmailCommands-ZEFMGVKM.js +0 -742
- package/agentRecordCommands-JZ35AC5A.js +0 -211
- package/agentRun-UIO43TUG.js +0 -251
- package/agentRunCommand-ATLKKD6O.js +0 -249
- package/agentRunControl-U2MV74WR.js +0 -211
- package/agentRuntimeLocal-P4MMGIR6.js +0 -189
- package/agentSlice-HHNKNNYM.js +0 -52
- package/appConfigCommands-W4JQHMOJ.js +0 -417
- package/appDeleteCommands-IXR47IAV.js +0 -183
- package/appDeployCommands-LB6DHDF4.js +0 -232
- package/appDeployStatusCommands-UQ6MJL6D.js +0 -204
- package/appGetCommands-M5JCTDDQ.js +0 -185
- package/appListCommands-TE3ZHE3I.js +0 -186
- package/appMigrateCommands-FOXH6R4B.js +0 -230
- package/appSourceCommands-3ACYB6I7.js +0 -279
- package/authCommand-I5OBJP5S.js +0 -66
- package/authCommands-I6KCGOCN.js +0 -54
- package/builtinSkillRegistry-MIXYSZUU.js +0 -35
- package/chromeOpsCommands-IZRCYDSW.js +0 -579
- package/chunk-24BICQPB.js +0 -25
- package/chunk-2E4BYAUE.js +0 -69
- package/chunk-2O72G3U2.js +0 -17157
- package/chunk-2OROOEOQ.js +0 -229
- package/chunk-2R6M34JP.js +0 -27225
- package/chunk-2SXN7LAY.js +0 -15
- package/chunk-35JIFLIG.js +0 -30
- package/chunk-3VXVE2LF.js +0 -12
- package/chunk-4DBTBNTX.js +0 -477
- package/chunk-4JH2UMJR.js +0 -40
- package/chunk-4RUQ2PFX.js +0 -432
- package/chunk-4SN6J65J.js +0 -38
- package/chunk-5MMAK75Q.js +0 -15
- package/chunk-6NYQHXMV.js +0 -1737
- package/chunk-6R4IY46J.js +0 -14
- package/chunk-7E6YXSFZ.js +0 -441
- package/chunk-7K4J76JQ.js +0 -917
- package/chunk-7LR2IFUH.js +0 -100
- package/chunk-AETZ7AD6.js +0 -274
- package/chunk-ATNTHIZI.js +0 -13
- package/chunk-BPB3T5EU.js +0 -791
- package/chunk-BV3FLP2L.js +0 -133
- package/chunk-BVYHE6QD.js +0 -110
- package/chunk-BWJLEN6X.js +0 -1388
- package/chunk-CHOZJMJS.js +0 -78
- package/chunk-D2LTQAGN.js +0 -464
- package/chunk-DALXH7BG.js +0 -3392
- package/chunk-DBCWXGOC.js +0 -15210
- package/chunk-DLXL4NSL.js +0 -1179
- package/chunk-DSBRIUX5.js +0 -23
- package/chunk-DWLEOOGR.js +0 -8
- package/chunk-E2KZNP6C.js +0 -13
- package/chunk-E5JV4DCB.js +0 -272
- package/chunk-EUGTFFO6.js +0 -42
- package/chunk-FBNVJ2TO.js +0 -294
- package/chunk-FGXG6OLW.js +0 -34
- package/chunk-G22P2J7O.js +0 -1775
- package/chunk-HEVRQGGH.js +0 -106
- package/chunk-HHXF57CL.js +0 -180
- package/chunk-HI5RS2O4.js +0 -2109
- package/chunk-HJTI7RZV.js +0 -94
- package/chunk-HRWRIPTB.js +0 -531
- package/chunk-HYCVEESH.js +0 -2824
- package/chunk-I42VC5KR.js +0 -15
- package/chunk-IB5AR52X.js +0 -15
- package/chunk-IIRJ4P4I.js +0 -24
- package/chunk-IT3ZZRJE.js +0 -12
- package/chunk-IV6VUVLJ.js +0 -88
- package/chunk-J42X32PV.js +0 -472
- package/chunk-JDMWYVUF.js +0 -449
- package/chunk-JKVOKKMQ.js +0 -53
- package/chunk-JRTNUU5Z.js +0 -54
- package/chunk-K7HLFORE.js +0 -226
- package/chunk-KGBASAB5.js +0 -74
- package/chunk-KGKTN2NX.js +0 -25
- package/chunk-KX6YBIHG.js +0 -8
- package/chunk-KYHNSSL2.js +0 -62
- package/chunk-KZO2MTVM.js +0 -140
- package/chunk-LKZPX6YH.js +0 -0
- package/chunk-LLP2NDED.js +0 -201
- package/chunk-LOFRSJX2.js +0 -47
- package/chunk-M75RM77T.js +0 -3970
- package/chunk-MDAYRIP7.js +0 -1889
- package/chunk-MI6HRMCK.js +0 -25
- package/chunk-MTNQNLSE.js +0 -1029
- package/chunk-NH4PUEWK.js +0 -762
- package/chunk-NHLLXINQ.js +0 -8
- package/chunk-NTUNHTJV.js +0 -40
- package/chunk-OJKUU3LP.js +0 -67
- package/chunk-OQH3TAB7.js +0 -299
- package/chunk-P62DHV4F.js +0 -443
- package/chunk-PHIERFHT.js +0 -574
- package/chunk-PKDFU6MY.js +0 -102
- package/chunk-PL5RKESU.js +0 -40
- package/chunk-PSJJBBWV.js +0 -42
- package/chunk-QKM55LP2.js +0 -739
- package/chunk-QQ56R7KS.js +0 -88
- package/chunk-QYPE3TS3.js +0 -43
- package/chunk-REAE2SZK.js +0 -62
- package/chunk-RGQ4UUWZ.js +0 -208
- package/chunk-RIRFHJTW.js +0 -353
- package/chunk-RYMLMTPZ.js +0 -547
- package/chunk-SSGTV4FC.js +0 -303
- package/chunk-SVKWZ3EG.js +0 -607
- package/chunk-T7KODHYS.js +0 -317
- package/chunk-TGVVE5BA.js +0 -3085
- package/chunk-TKLBBR7P.js +0 -779
- package/chunk-TZXPT53C.js +0 -8
- package/chunk-U67V476Y.js +0 -35
- package/chunk-UEILX4EV.js +0 -15
- package/chunk-VIWDGTDA.js +0 -8
- package/chunk-VXUQWCEZ.js +0 -138
- package/chunk-W5GKF5ZW.js +0 -32
- package/chunk-WDWZPASX.js +0 -29
- package/chunk-WX266G2C.js +0 -9594
- package/chunk-YCITCYSJ.js +0 -356
- package/chunk-Z3KTXWWB.js +0 -76
- package/chunk-ZC3CMUKU.js +0 -322
- package/chunk-ZSZBHRLP.js +0 -1710
- package/chunk-ZV7ZY46L.js +0 -1343
- package/cliAgentConfigHelpers-WB2S7PDO.js +0 -47
- package/cliAuthorityBrokerClient-3SKOA7OZ.js +0 -23
- package/cliAuthorityBrokerProcess-BMBVXPKU.js +0 -24
- package/cliAuthorityStoreDriver-6FE3BJNB.js +0 -20
- package/cliEnvHelpers-7V5ZWUJA.js +0 -34
- package/cliExecutor-N3445G2Z.js +0 -45
- package/cliLocalAgentRecordReader-QKKRK53P.js +0 -113
- package/cloudAutomationCommands-S52NKCLL.js +0 -310
- package/contentThunks-ERA42OXW.js +0 -100
- package/cooldownCommands-ZFDAL4MR.js +0 -79
- package/createAgentAutomationAction-DMD2VDPI.js +0 -173
- package/createDialogAction-3SPOJQAK.js +0 -87
- package/createPageAction-AVXUMZVT.js +0 -91
- package/cursorProvider-2RACMEMF.js +0 -6123
- package/db-LTHLW7QA.js +0 -178
- package/dbSlice-WNUHTF4C.js +0 -76
- package/deleteDbKey-KV6MYBAI.js +0 -87
- package/desktopFolderProjects-4POAMVJN.js +0 -45
- package/dialogCommands-4MOLJW4G.js +0 -165
- package/dialogMessageRecord-2HJTEXQX.js +0 -7
- package/dialogNotifyCommand-YL2GFKLO.js +0 -45
- package/dialogSlice-Q7H2YVNO.js +0 -200
- package/dialogUsageCommand-IO2BQKL2.js +0 -31
- package/docCreateCommands-OYLRBK2M.js +0 -255
- package/docDeleteCommands-3NF6QPJU.js +0 -226
- package/docReadCommands-CBAERJAP.js +0 -184
- package/docStore-GWPFDV6Y.js +0 -89
- package/docUpdateCommands-BAMCGX6F.js +0 -326
- package/ebookDownloaderAgentCommand-NOIZ6U7Y.js +0 -675
- package/fetchMessages-P7FSCSXV.js +0 -19
- package/getPricing-KNXVEIUI.js +0 -40
- package/hostCredentialCreate-2VEYBXJV.js +0 -402
- package/i18n-SAK6DDY4.js +0 -51
- package/keys-FXEGMKSG.js +0 -183
- package/legacyMigration-TF4SYJCZ.js +0 -19
- package/levelAuthorityStore-L5SVDM5O.js +0 -10
- package/localAutomationCommands-XSK7SM7I.js +0 -199
- package/localAutomationRuntime-5WBO7HGQ.js +0 -61
- package/localRecall-BDYKXB46.js +0 -17
- package/localRuntimeAdapter-Y6H6XRIH.js +0 -310
- package/localRuntimeAuthority-Q5C2KWGF.js +0 -45
- package/localRuntimeDb-MM3DINZM.js +0 -12
- package/machineInfo-HNPJHQFU.js +0 -14
- package/machineWsRunDispatch-Y5SJGCEE.js +0 -228
- package/models-TOXYINNM.js +0 -10
- package/oauthTokenStore-RUYNYALS.js +0 -24
- package/overlay-JA3SPVUS.js +0 -15
- package/parityCommands-5OCBPVES.js +0 -613
- package/processSpawn-6GEO77KV.js +0 -11
- package/profileConfig-KOWK4HOG.js +0 -49
- package/projectArchive-WE3VVPZ2.js +0 -132
- package/providerPresetApply-YCVSP2WX.js +0 -235
- package/providerRegistry-26PAUYH2.js +0 -24
- package/read-D4WYJQJQ.js +0 -32
- package/readDocTool-3S3OQFOH.js +0 -22
- package/rememberExplicit-ZPI6KK5M.js +0 -16
- package/remove-AHRMUDMH.js +0 -32
- package/removeDialogAgentAction-AALRBFSA.js +0 -81
- package/secretCommands-2PSS3QNZ.js +0 -24
- package/setDialogExtraReferencesAction-SLHQ3GYL.js +0 -39
- package/setPrimaryDialogAgentAction-XKCSGJ7M.js +0 -96
- package/skillDiscovery-IUEZZG2B.js +0 -29
- package/skillSummaryMarker-62UW7HI7.js +0 -9
- package/slateToRenderMarkdown-R3X74MCX.js +0 -7
- package/slateUtils-ESQAJ6RN.js +0 -19
- package/store-WSAVTR32.js +0 -50
- package/switchDialogAgentAction-YJIWQGIR.js +0 -70
- package/tombstones-FQQMEDOW.js +0 -32
- package/toolApiClient-FVXTIIEN.js +0 -42
- package/tools-WN4AVSNS.js +0 -147
- package/tuiRestart-LU2BDLAW.js +0 -50
- package/tuiSummaryLlmCaller-Z2ZVBIGN.js +0 -53
- package/updateCommands-4QP7WJLA.js +0 -63
- package/usageCommand-AZX7D3LB.js +0 -31
- package/usageRebuildCommand-XV5QQCHK.js +0 -623
- package/userDataMerge-HT2ZVHBJ.js +0 -13
- package/windowsSelfUpdate-5OFKSW6Y.js +0 -14
- package/workContext-ZAW6VXT7.js +0 -18
- package/workContextAccess-VU5I4LKZ.js +0 -11
- package/workContextWriteNotice-YCSSMHN4.js +0 -7
- /package/{chunk-BYXBJQAS.js → chunk-0bcc25vg.js} +0 -0
|
@@ -1,141 +1,125 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
CONFIRMATION_INPUT_KEYS,
|
|
11
|
-
INVALID_TOOL_ARGS_REPLACEMENT,
|
|
12
|
-
buildInvalidToolCallSelfHealResult,
|
|
13
|
-
parseToolCallArguments,
|
|
14
|
-
performFetchRequest,
|
|
15
|
-
reportToolExecutionErrorInBackground,
|
|
16
|
-
sanitizeOutboundMessages,
|
|
17
|
-
stripModelToolArgs
|
|
18
|
-
} from "./chunk-PDSXYHNI.js";
|
|
19
|
-
import {
|
|
20
|
-
findToolExecutor,
|
|
21
|
-
toolDefinitionsByName
|
|
22
|
-
} from "./chunk-EBH4RFJ6.js";
|
|
23
|
-
import {
|
|
24
|
-
createSSEParser,
|
|
25
|
-
createToolRunId,
|
|
26
|
-
getToolResultErrorData,
|
|
27
|
-
toolRunFailed,
|
|
28
|
-
toolRunSetPending,
|
|
29
|
-
toolRunStarted,
|
|
30
|
-
toolRunSucceeded
|
|
31
|
-
} from "./chunk-ZSZBHRLP.js";
|
|
2
|
+
scrubSecrets,
|
|
3
|
+
sanitizeToolOutputText,
|
|
4
|
+
isCompleteInstructionOutput,
|
|
5
|
+
LIST_AGENTS_OUTPUT_BUDGET,
|
|
6
|
+
extractErrorDiagnostics,
|
|
7
|
+
classifyApiError,
|
|
8
|
+
classifyGenerationError
|
|
9
|
+
} from "./chunk-w820gg1w.js";
|
|
32
10
|
import {
|
|
33
|
-
|
|
34
|
-
} from "./chunk-
|
|
11
|
+
EMPTY_ASSISTANT_REPAIR_PROMPT
|
|
12
|
+
} from "./chunk-2ygg7azv.js";
|
|
35
13
|
import {
|
|
14
|
+
require_react,
|
|
15
|
+
getActiveDialogKey,
|
|
16
|
+
addActiveController2,
|
|
17
|
+
removeActiveController2,
|
|
18
|
+
tokenUsageLiveUpdate2,
|
|
19
|
+
selectIdentityToken,
|
|
20
|
+
write2,
|
|
21
|
+
createActionAsyncThunk,
|
|
22
|
+
toolResultNeedsUserConfirmation,
|
|
23
|
+
toast,
|
|
24
|
+
messageStreaming,
|
|
36
25
|
addToolMessage,
|
|
26
|
+
updateToolMessage,
|
|
37
27
|
messageStreamEnd,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
updateToolMessage
|
|
42
|
-
} from "./chunk-DBCWXGOC.js";
|
|
28
|
+
getCurrentSpaceId,
|
|
29
|
+
streamAgentChatTurn2
|
|
30
|
+
} from "./chunk-c235kypv.js";
|
|
43
31
|
import {
|
|
44
|
-
|
|
45
|
-
} from "./chunk-
|
|
32
|
+
splitDialogKeyIdentity
|
|
33
|
+
} from "./chunk-csf18m5w.js";
|
|
46
34
|
import {
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
dialogMessageKey2,
|
|
36
|
+
createDialogMessageKeyAndId2
|
|
37
|
+
} from "./chunk-mzadqnyq.js";
|
|
49
38
|
import {
|
|
50
|
-
|
|
51
|
-
} from "./chunk-
|
|
39
|
+
toTrimmedString
|
|
40
|
+
} from "./chunk-6yarwtxh.js";
|
|
52
41
|
import {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
removeActiveController,
|
|
56
|
-
tokenUsageLiveUpdate
|
|
57
|
-
} from "./chunk-SVKWZ3EG.js";
|
|
42
|
+
getApiEndpoint
|
|
43
|
+
} from "./chunk-kawvydbk.js";
|
|
58
44
|
import {
|
|
59
|
-
|
|
60
|
-
} from "./chunk-
|
|
45
|
+
getModelInfo
|
|
46
|
+
} from "./chunk-vqgtw1px.js";
|
|
61
47
|
import {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
48
|
+
getRequestConfig2,
|
|
49
|
+
createSSEParser,
|
|
50
|
+
getToolResultErrorData,
|
|
51
|
+
createToolRunId,
|
|
52
|
+
toolRunStarted,
|
|
53
|
+
toolRunSetPending,
|
|
54
|
+
toolRunSucceeded,
|
|
55
|
+
toolRunFailed
|
|
56
|
+
} from "./chunk-ex34n71b.js";
|
|
65
57
|
import {
|
|
66
|
-
|
|
67
|
-
|
|
58
|
+
toolDefinitionsByName2,
|
|
59
|
+
findToolExecutor2
|
|
60
|
+
} from "./chunk-dh69vqbd.js";
|
|
68
61
|
import {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
62
|
+
reportToolExecutionErrorInBackground,
|
|
63
|
+
CONFIRMATION_INPUT_KEYS,
|
|
64
|
+
stripModelToolArgs,
|
|
65
|
+
performFetchRequest,
|
|
66
|
+
INVALID_TOOL_ARGS_REPLACEMENT,
|
|
67
|
+
parseToolCallArguments,
|
|
68
|
+
buildInvalidToolCallSelfHealResult,
|
|
69
|
+
sanitizeOutboundMessages
|
|
70
|
+
} from "./chunk-c5z7qspt.js";
|
|
76
71
|
import {
|
|
77
|
-
accumulateToolCallDelta,
|
|
78
72
|
createThinkParserState,
|
|
79
|
-
|
|
73
|
+
processThinkChunk,
|
|
80
74
|
flushThinkParser,
|
|
81
|
-
|
|
75
|
+
createToolCallTextParserState,
|
|
82
76
|
processContentChunkWithToolCallStripping,
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
flushToolCallTextParserIntoCallback,
|
|
78
|
+
accumulateToolCallDelta
|
|
79
|
+
} from "./chunk-jkw9n4h5.js";
|
|
85
80
|
import {
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
projectUserPartForModel,
|
|
82
|
+
classifyOutboundErrorCategory,
|
|
83
|
+
deriveRequestFactsFromBody,
|
|
84
|
+
resolveOutboundWire,
|
|
85
|
+
resolveOutboundDiagnosticSink,
|
|
86
|
+
createOutboundDiagnosticCall
|
|
87
|
+
} from "./chunk-f9yvy9t9.js";
|
|
88
88
|
import {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
} from "./chunk-
|
|
89
|
+
shouldInlineImageUrlsForAgent,
|
|
90
|
+
inlineImageUrlsForCustomProvider,
|
|
91
|
+
prepareTools
|
|
92
|
+
} from "./chunk-gcq01td7.js";
|
|
93
93
|
import {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
sanitizeToolOutputText,
|
|
97
|
-
scrubSecrets
|
|
98
|
-
} from "./chunk-D2LTQAGN.js";
|
|
94
|
+
clipHeadAndTail
|
|
95
|
+
} from "./chunk-k6ycb24w.js";
|
|
99
96
|
import {
|
|
100
|
-
|
|
101
|
-
} from "./chunk-
|
|
97
|
+
__toESM
|
|
98
|
+
} from "./chunk-33405wtv.js";
|
|
102
99
|
import {
|
|
103
|
-
|
|
104
|
-
} from "./chunk-
|
|
100
|
+
getPublicImageAgentMode
|
|
101
|
+
} from "./chunk-n3r1ebdm.js";
|
|
102
|
+
import {
|
|
103
|
+
normalizeChatCompletionsBodyForProvider
|
|
104
|
+
} from "./chunk-nvewvf7h.js";
|
|
105
105
|
import {
|
|
106
106
|
isAbortError
|
|
107
|
-
} from "./chunk-
|
|
107
|
+
} from "./chunk-a7bz6nc3.js";
|
|
108
108
|
import {
|
|
109
109
|
extractCustomId
|
|
110
|
-
} from "./chunk-
|
|
111
|
-
import {
|
|
112
|
-
getApiEndpoint
|
|
113
|
-
} from "./chunk-RI7SXDJW.js";
|
|
110
|
+
} from "./chunk-srncrd3f.js";
|
|
114
111
|
import {
|
|
115
112
|
isRecord
|
|
116
|
-
} from "./chunk-
|
|
113
|
+
} from "./chunk-ws402twv.js";
|
|
117
114
|
import {
|
|
118
115
|
toErrorMessage
|
|
119
|
-
} from "./chunk-
|
|
120
|
-
import {
|
|
121
|
-
toTrimmedString
|
|
122
|
-
} from "./chunk-DLXL4NSL.js";
|
|
123
|
-
import {
|
|
124
|
-
createDialogMessageKeyAndId,
|
|
125
|
-
dialogMessageKey
|
|
126
|
-
} from "./chunk-OJKUU3LP.js";
|
|
127
|
-
import {
|
|
128
|
-
splitDialogKeyIdentity
|
|
129
|
-
} from "./chunk-YZMNK53S.js";
|
|
116
|
+
} from "./chunk-jec44fkj.js";
|
|
130
117
|
import {
|
|
131
118
|
asTrimmedString
|
|
132
|
-
} from "./chunk-
|
|
119
|
+
} from "./chunk-wfvvnmmj.js";
|
|
133
120
|
import {
|
|
134
121
|
asOptionalTrimmedString
|
|
135
|
-
} from "./chunk-
|
|
136
|
-
import {
|
|
137
|
-
__toESM
|
|
138
|
-
} from "./chunk-U67V476Y.js";
|
|
122
|
+
} from "./chunk-p1vg4bx8.js";
|
|
139
123
|
|
|
140
124
|
// packages/integrations/openai/filterAndCleanMessages.ts
|
|
141
125
|
function serializeAgentRunMessages(messages) {
|
|
@@ -145,8 +129,10 @@ function serializeAgentRunMessages(messages) {
|
|
|
145
129
|
});
|
|
146
130
|
}
|
|
147
131
|
var isValidMessagePart = (part) => {
|
|
148
|
-
if (!part || typeof part !== "object")
|
|
149
|
-
|
|
132
|
+
if (!part || typeof part !== "object")
|
|
133
|
+
return false;
|
|
134
|
+
if (part.type === "text")
|
|
135
|
+
return typeof part.text === "string";
|
|
150
136
|
if (part.type === "image_url") {
|
|
151
137
|
const img = part.image_url;
|
|
152
138
|
return img && typeof img === "object" && typeof img.url === "string" && img.url.length > 0;
|
|
@@ -155,22 +141,28 @@ var isValidMessagePart = (part) => {
|
|
|
155
141
|
};
|
|
156
142
|
var extractContent = (msg) => {
|
|
157
143
|
if (msg.role === "tool") {
|
|
158
|
-
const budget = (msg.name ?? msg.toolName ?? msg.toolPayload?.toolName) === "listAgents" ? LIST_AGENTS_OUTPUT_BUDGET :
|
|
144
|
+
const budget = (msg.name ?? msg.toolName ?? msg.toolPayload?.toolName) === "listAgents" ? LIST_AGENTS_OUTPUT_BUDGET : undefined;
|
|
159
145
|
const metadata = msg.tool_result_metadata ?? msg.metadata;
|
|
160
146
|
const llmContext = asTrimmedString(msg.toolPayload?.llmContext);
|
|
161
147
|
if (isCompleteInstructionOutput(extractName(msg), metadata, typeof msg.content === "string" ? msg.content : "")) {
|
|
162
148
|
const safe = scrubSecrets(sanitizeToolOutputText(llmContext || String(msg.content ?? ""))).cleaned;
|
|
163
|
-
if (isCompleteInstructionOutput(extractName(msg), metadata, safe))
|
|
164
|
-
|
|
149
|
+
if (isCompleteInstructionOutput(extractName(msg), metadata, safe))
|
|
150
|
+
return safe;
|
|
151
|
+
return clipHeadAndTail(safe, { toolCallId: extractToolCallId(msg) ?? undefined }).content;
|
|
165
152
|
}
|
|
166
|
-
if (llmContext)
|
|
153
|
+
if (llmContext)
|
|
154
|
+
return clipHeadAndTail(llmContext, { toolCallId: extractToolCallId(msg) ?? undefined, ...budget ? { maxTotalBytes: budget } : {} }).content;
|
|
167
155
|
const summary = asTrimmedString(msg.toolPayload?.summary);
|
|
168
|
-
if (summary)
|
|
169
|
-
|
|
170
|
-
if (
|
|
156
|
+
if (summary)
|
|
157
|
+
return clipHeadAndTail(summary, { toolCallId: extractToolCallId(msg) ?? undefined, ...budget ? { maxTotalBytes: budget } : {} }).content;
|
|
158
|
+
if (typeof msg.content === "string")
|
|
159
|
+
return clipHeadAndTail(msg.content, { toolCallId: extractToolCallId(msg) ?? undefined, ...budget ? { maxTotalBytes: budget } : {} }).content;
|
|
160
|
+
if (msg.content != null)
|
|
161
|
+
return clipHeadAndTail(JSON.stringify(msg.content), { toolCallId: extractToolCallId(msg) ?? undefined, ...budget ? { maxTotalBytes: budget } : {} }).content;
|
|
171
162
|
return null;
|
|
172
163
|
}
|
|
173
|
-
if (typeof msg.content === "string")
|
|
164
|
+
if (typeof msg.content === "string")
|
|
165
|
+
return msg.content;
|
|
174
166
|
if (Array.isArray(msg.content)) {
|
|
175
167
|
const parts = msg.role === "user" ? msg.content.flatMap((part) => projectUserPartForModel(part)) : msg.content.filter(isValidMessagePart);
|
|
176
168
|
return parts.length > 0 ? parts : null;
|
|
@@ -183,14 +175,17 @@ var extractContent = (msg) => {
|
|
|
183
175
|
};
|
|
184
176
|
var extractToolCalls = (msg) => {
|
|
185
177
|
const calls = msg.tool_calls ?? msg.toolCalls;
|
|
186
|
-
return Array.isArray(calls) && calls.length > 0 ? calls :
|
|
178
|
+
return Array.isArray(calls) && calls.length > 0 ? calls : undefined;
|
|
187
179
|
};
|
|
188
180
|
var extractToolCallId = (msg) => msg.tool_call_id ?? msg.toolCallId ?? msg.toolPayload?.rawToolCall?.id;
|
|
189
181
|
var extractName = (msg) => {
|
|
190
|
-
if (typeof msg.name === "string")
|
|
191
|
-
|
|
192
|
-
if (typeof msg.
|
|
193
|
-
|
|
182
|
+
if (typeof msg.name === "string")
|
|
183
|
+
return msg.name;
|
|
184
|
+
if (typeof msg.toolName === "string")
|
|
185
|
+
return msg.toolName;
|
|
186
|
+
if (typeof msg.toolPayload?.toolName === "string")
|
|
187
|
+
return msg.toolPayload.toolName;
|
|
188
|
+
return;
|
|
194
189
|
};
|
|
195
190
|
var getToolName = (msg) => msg?.toolName ?? msg?.toolPayload?.toolName;
|
|
196
191
|
var isHandoffToolMessage = (msg) => {
|
|
@@ -199,34 +194,40 @@ var isHandoffToolMessage = (msg) => {
|
|
|
199
194
|
};
|
|
200
195
|
var getToolMessageCallId = (msg) => msg?.tool_call_id ?? msg?.toolCallId ?? msg?.toolPayload?.rawToolCall?.id;
|
|
201
196
|
var collectHandoffToolCallIds = (msgs) => {
|
|
202
|
-
const ids =
|
|
197
|
+
const ids = new Set;
|
|
203
198
|
for (const msg of msgs) {
|
|
204
|
-
if (msg?.role !== "tool" || !isHandoffToolMessage(msg))
|
|
199
|
+
if (msg?.role !== "tool" || !isHandoffToolMessage(msg))
|
|
200
|
+
continue;
|
|
205
201
|
const id = getToolMessageCallId(msg);
|
|
206
|
-
if (id)
|
|
202
|
+
if (id)
|
|
203
|
+
ids.add(id);
|
|
207
204
|
}
|
|
208
205
|
return ids;
|
|
209
206
|
};
|
|
210
207
|
var stripHandoffToolMessage = (msg) => msg?.role === "tool" && isHandoffToolMessage(msg) ? null : msg;
|
|
211
208
|
var removeToolCallsById = (calls, ids) => calls?.filter((call) => !ids.has(call.id));
|
|
212
209
|
var stripHandoffToolCallsFromAssistant = (msg, handoffIds) => {
|
|
213
|
-
if (msg?.role !== "assistant")
|
|
210
|
+
if (msg?.role !== "assistant")
|
|
211
|
+
return msg;
|
|
214
212
|
const calls = msg.tool_calls ?? msg.toolCalls;
|
|
215
|
-
if (!calls?.some((call) => handoffIds.has(call.id)))
|
|
213
|
+
if (!calls?.some((call) => handoffIds.has(call.id)))
|
|
214
|
+
return msg;
|
|
216
215
|
const kept = removeToolCallsById(calls, handoffIds);
|
|
217
216
|
return {
|
|
218
217
|
...msg,
|
|
219
|
-
tool_calls: kept?.length ? kept :
|
|
220
|
-
toolCalls: kept?.length ? kept :
|
|
218
|
+
tool_calls: kept?.length ? kept : undefined,
|
|
219
|
+
toolCalls: kept?.length ? kept : undefined
|
|
221
220
|
};
|
|
222
221
|
};
|
|
223
222
|
var stripHandoffToolMessages = (msgs) => {
|
|
224
223
|
const handoffIds = collectHandoffToolCallIds(msgs);
|
|
225
|
-
if (handoffIds.size === 0)
|
|
224
|
+
if (handoffIds.size === 0)
|
|
225
|
+
return msgs;
|
|
226
226
|
const out = [];
|
|
227
227
|
for (const raw of msgs) {
|
|
228
228
|
const stripped = stripHandoffToolMessage(raw);
|
|
229
|
-
if (!stripped)
|
|
229
|
+
if (!stripped)
|
|
230
|
+
continue;
|
|
230
231
|
out.push(stripHandoffToolCallsFromAssistant(stripped, handoffIds));
|
|
231
232
|
}
|
|
232
233
|
return out;
|
|
@@ -234,23 +235,29 @@ var stripHandoffToolMessages = (msgs) => {
|
|
|
234
235
|
var toOpenAIMessage = (rawMsg) => {
|
|
235
236
|
const msg = rawMsg;
|
|
236
237
|
const { role, id } = msg;
|
|
237
|
-
if (!role || !["system", "user", "assistant", "tool"].includes(role))
|
|
238
|
+
if (!role || !["system", "user", "assistant", "tool"].includes(role))
|
|
239
|
+
return null;
|
|
238
240
|
const toolCalls = extractToolCalls(msg);
|
|
239
241
|
let content = extractContent(msg);
|
|
240
242
|
if (content === null) {
|
|
241
|
-
if (role === "assistant" && toolCalls)
|
|
242
|
-
|
|
243
|
+
if (role === "assistant" && toolCalls)
|
|
244
|
+
content = "";
|
|
245
|
+
else
|
|
246
|
+
return null;
|
|
243
247
|
}
|
|
244
248
|
const cleaned = { role, content };
|
|
245
|
-
if (id)
|
|
249
|
+
if (id)
|
|
250
|
+
cleaned.id = id;
|
|
246
251
|
const name = extractName(msg);
|
|
247
|
-
if (name)
|
|
252
|
+
if (name)
|
|
253
|
+
cleaned.name = name;
|
|
248
254
|
if (role === "assistant" && toolCalls) {
|
|
249
255
|
cleaned.tool_calls = toolCalls;
|
|
250
256
|
}
|
|
251
257
|
if (role === "assistant") {
|
|
252
258
|
const reasoningContent = typeof msg.reasoning_content === "string" ? msg.reasoning_content : typeof msg.thinkContent === "string" ? msg.thinkContent : "";
|
|
253
|
-
if (reasoningContent)
|
|
259
|
+
if (reasoningContent)
|
|
260
|
+
cleaned.reasoning_content = reasoningContent;
|
|
254
261
|
}
|
|
255
262
|
if (role === "tool") {
|
|
256
263
|
const metadata = msg.tool_result_metadata ?? msg.metadata;
|
|
@@ -258,62 +265,67 @@ var toOpenAIMessage = (rawMsg) => {
|
|
|
258
265
|
Object.defineProperty(cleaned, "tool_result_metadata", { value: metadata, enumerable: false });
|
|
259
266
|
}
|
|
260
267
|
const toolCallId = extractToolCallId(msg);
|
|
261
|
-
if (toolCallId)
|
|
268
|
+
if (toolCallId)
|
|
269
|
+
cleaned.tool_call_id = toolCallId;
|
|
262
270
|
if (!cleaned.tool_call_id) {
|
|
263
|
-
console.warn("[filterAndCleanMessages]
|
|
271
|
+
console.warn("[filterAndCleanMessages] 丢弃无效 tool 消息:缺少 tool_call_id", msg);
|
|
264
272
|
return null;
|
|
265
273
|
}
|
|
266
274
|
}
|
|
267
275
|
return cleaned;
|
|
268
276
|
};
|
|
269
277
|
var removeOrphanedToolPairs = (msgs) => {
|
|
270
|
-
const dropIndexes =
|
|
271
|
-
const toolToAssistant =
|
|
272
|
-
for (let i = 0;
|
|
273
|
-
if (msgs[i].role !== "tool")
|
|
274
|
-
|
|
278
|
+
const dropIndexes = new Set;
|
|
279
|
+
const toolToAssistant = new Map;
|
|
280
|
+
for (let i = 0;i < msgs.length; i++) {
|
|
281
|
+
if (msgs[i].role !== "tool")
|
|
282
|
+
continue;
|
|
283
|
+
for (let j = i - 1;j >= 0; j--) {
|
|
275
284
|
if (msgs[j].role === "assistant") {
|
|
276
285
|
toolToAssistant.set(i, j);
|
|
277
286
|
break;
|
|
278
287
|
}
|
|
279
288
|
}
|
|
280
289
|
}
|
|
281
|
-
for (let i = 0;
|
|
290
|
+
for (let i = 0;i < msgs.length; i++) {
|
|
282
291
|
if (msgs[i].role === "tool" && !toolToAssistant.has(i)) {
|
|
283
292
|
dropIndexes.add(i);
|
|
284
|
-
console.warn("[filterAndCleanMessages]
|
|
293
|
+
console.warn("[filterAndCleanMessages] 丢弃孤立 tool 消息:缺少前置 assistant", msgs[i].tool_call_id);
|
|
285
294
|
}
|
|
286
295
|
}
|
|
287
296
|
for (const [toolIdx, assistantIdx] of toolToAssistant) {
|
|
288
297
|
const toolMsg = msgs[toolIdx];
|
|
289
|
-
if (!toolMsg.tool_call_id)
|
|
298
|
+
if (!toolMsg.tool_call_id)
|
|
299
|
+
continue;
|
|
290
300
|
const knownIds = new Set((msgs[assistantIdx].tool_calls ?? []).map((tc) => tc.id));
|
|
291
301
|
if (!knownIds.has(toolMsg.tool_call_id)) {
|
|
292
302
|
dropIndexes.add(toolIdx);
|
|
293
|
-
console.warn("[filterAndCleanMessages]
|
|
303
|
+
console.warn("[filterAndCleanMessages] 丢弃孤立 tool 消息:", toolMsg.tool_call_id);
|
|
294
304
|
}
|
|
295
305
|
}
|
|
296
306
|
for (const assistantIdx of new Set(toolToAssistant.values())) {
|
|
297
|
-
if (dropIndexes.has(assistantIdx))
|
|
307
|
+
if (dropIndexes.has(assistantIdx))
|
|
308
|
+
continue;
|
|
298
309
|
const stub = msgs[assistantIdx];
|
|
299
310
|
const content = typeof stub.content === "string" ? stub.content.trim() : stub.content;
|
|
300
311
|
const isEmpty = content === "" || Array.isArray(content) && content.length === 0;
|
|
301
|
-
if (!isEmpty)
|
|
312
|
+
if (!isEmpty)
|
|
313
|
+
continue;
|
|
302
314
|
const allToolsDropped = (stub.tool_calls ?? []).every((tc) => {
|
|
303
|
-
return msgs.every(
|
|
304
|
-
(m, idx) => m.role !== "tool" || m.tool_call_id !== tc.id || dropIndexes.has(idx)
|
|
305
|
-
);
|
|
315
|
+
return msgs.every((m, idx) => m.role !== "tool" || m.tool_call_id !== tc.id || dropIndexes.has(idx));
|
|
306
316
|
});
|
|
307
317
|
if (allToolsDropped) {
|
|
308
318
|
dropIndexes.add(assistantIdx);
|
|
309
|
-
console.warn("[filterAndCleanMessages]
|
|
319
|
+
console.warn("[filterAndCleanMessages] 一并丢弃孤立 assistant stub(index:", assistantIdx, ")");
|
|
310
320
|
}
|
|
311
321
|
}
|
|
312
|
-
if (dropIndexes.size === 0)
|
|
322
|
+
if (dropIndexes.size === 0)
|
|
323
|
+
return msgs;
|
|
313
324
|
return msgs.filter((_, idx) => !dropIndexes.has(idx));
|
|
314
325
|
};
|
|
315
326
|
var filterAndCleanMessages = (msgs) => {
|
|
316
|
-
if (!Array.isArray(msgs))
|
|
327
|
+
if (!Array.isArray(msgs))
|
|
328
|
+
return [];
|
|
317
329
|
const flat = msgs.flat();
|
|
318
330
|
const preprocessed = stripHandoffToolMessages(flat);
|
|
319
331
|
const cleaned = preprocessed.map(toOpenAIMessage).filter((m) => m !== null);
|
|
@@ -325,9 +337,7 @@ async function persistToolMessage(dispatch, message, options = {}) {
|
|
|
325
337
|
const id = asOptionalTrimmedString(message?.id);
|
|
326
338
|
const dbKey = asOptionalTrimmedString(message?.dbKey);
|
|
327
339
|
if (!id || !dbKey) {
|
|
328
|
-
const err = new Error(
|
|
329
|
-
`[persistToolMessage] missing id/dbKey (id=${String(id)} dbKey=${String(dbKey)})`
|
|
330
|
-
);
|
|
340
|
+
const err = new Error(`[persistToolMessage] missing id/dbKey (id=${String(id)} dbKey=${String(dbKey)})`);
|
|
331
341
|
if (options.soft) {
|
|
332
342
|
console.error(err.message);
|
|
333
343
|
return;
|
|
@@ -335,21 +345,19 @@ async function persistToolMessage(dispatch, message, options = {}) {
|
|
|
335
345
|
throw err;
|
|
336
346
|
}
|
|
337
347
|
const { controller: _controller, dialogId: _dialogId, ...rest } = message;
|
|
338
|
-
const isStreaming = options.isStreaming !==
|
|
348
|
+
const isStreaming = options.isStreaming !== undefined ? options.isStreaming : Boolean(rest.isStreaming);
|
|
339
349
|
try {
|
|
340
|
-
const writeRequest = dispatch(
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
})
|
|
352
|
-
);
|
|
350
|
+
const writeRequest = dispatch(write2({
|
|
351
|
+
data: {
|
|
352
|
+
...rest,
|
|
353
|
+
id,
|
|
354
|
+
dbKey,
|
|
355
|
+
role: "tool",
|
|
356
|
+
isStreaming,
|
|
357
|
+
type: "msg" /* MSG */
|
|
358
|
+
},
|
|
359
|
+
customKey: dbKey
|
|
360
|
+
}));
|
|
353
361
|
if (writeRequest && typeof writeRequest.unwrap === "function") {
|
|
354
362
|
await writeRequest.unwrap();
|
|
355
363
|
return;
|
|
@@ -357,7 +365,8 @@ async function persistToolMessage(dispatch, message, options = {}) {
|
|
|
357
365
|
await writeRequest;
|
|
358
366
|
} catch (error) {
|
|
359
367
|
console.error("[persistToolMessage] write failed", { id, dbKey, error });
|
|
360
|
-
if (!options.soft)
|
|
368
|
+
if (!options.soft)
|
|
369
|
+
throw error;
|
|
361
370
|
}
|
|
362
371
|
}
|
|
363
372
|
async function persistToolMessages(dispatch, messages, options = {}) {
|
|
@@ -368,7 +377,7 @@ async function persistToolMessages(dispatch, messages, options = {}) {
|
|
|
368
377
|
|
|
369
378
|
// packages/app/appInspector/appInspectorStore.ts
|
|
370
379
|
var import_react = __toESM(require_react());
|
|
371
|
-
var listeners =
|
|
380
|
+
var listeners = new Set;
|
|
372
381
|
var version = 0;
|
|
373
382
|
var previewOpen = false;
|
|
374
383
|
var previewUrl = null;
|
|
@@ -377,8 +386,7 @@ var notify = () => {
|
|
|
377
386
|
for (const listener of listeners) {
|
|
378
387
|
try {
|
|
379
388
|
listener();
|
|
380
|
-
} catch {
|
|
381
|
-
}
|
|
389
|
+
} catch {}
|
|
382
390
|
}
|
|
383
391
|
};
|
|
384
392
|
var bump = () => {
|
|
@@ -401,7 +409,7 @@ function getPreviewTarget() {
|
|
|
401
409
|
|
|
402
410
|
// packages/app/appInspector/htmlArtifactClient.ts
|
|
403
411
|
async function readHtmlArtifact(id, options) {
|
|
404
|
-
const fetchFn = options?.fetchImpl ?? (typeof fetch !== "undefined" ? fetch :
|
|
412
|
+
const fetchFn = options?.fetchImpl ?? (typeof fetch !== "undefined" ? fetch : undefined);
|
|
405
413
|
if (!fetchFn) {
|
|
406
414
|
throw new Error("fetch is not available in current environment");
|
|
407
415
|
}
|
|
@@ -424,11 +432,11 @@ async function readHtmlArtifact(id, options) {
|
|
|
424
432
|
});
|
|
425
433
|
if (!response.ok) {
|
|
426
434
|
const errorText = await response.text().catch(() => "");
|
|
427
|
-
throw new Error(
|
|
435
|
+
throw new Error(`读取 HTML 成品失败 (${response.status}): ${errorText || response.statusText}`);
|
|
428
436
|
}
|
|
429
437
|
const data = await response.json();
|
|
430
438
|
if (!data?.artifact) {
|
|
431
|
-
throw new Error("
|
|
439
|
+
throw new Error("服务端未返回有效的 HTML 成品对象");
|
|
432
440
|
}
|
|
433
441
|
return data.artifact;
|
|
434
442
|
}
|
|
@@ -436,7 +444,8 @@ async function readHtmlArtifact(id, options) {
|
|
|
436
444
|
// packages/chat/messages/web/htmlArtifactEventChannel.ts
|
|
437
445
|
var latestExecution = 0;
|
|
438
446
|
async function receiveHtmlArtifactToolResult(toolName, result, dialogKey, isError = false) {
|
|
439
|
-
if (isError || toolName !== "createHtmlArtifact" && toolName !== "updateHtmlArtifact")
|
|
447
|
+
if (isError || toolName !== "createHtmlArtifact" && toolName !== "updateHtmlArtifact")
|
|
448
|
+
return;
|
|
440
449
|
let data = result;
|
|
441
450
|
if (typeof data === "string") {
|
|
442
451
|
try {
|
|
@@ -445,24 +454,30 @@ async function receiveHtmlArtifactToolResult(toolName, result, dialogKey, isErro
|
|
|
445
454
|
return;
|
|
446
455
|
}
|
|
447
456
|
}
|
|
448
|
-
if (!data || data.error)
|
|
457
|
+
if (!data || data.error)
|
|
458
|
+
return;
|
|
449
459
|
data = data.rawData ?? data;
|
|
450
|
-
if (!data || typeof data !== "object" || data.error)
|
|
460
|
+
if (!data || typeof data !== "object" || data.error)
|
|
461
|
+
return;
|
|
451
462
|
const artifact = data.artifact ?? data;
|
|
452
|
-
if (!artifact || typeof artifact !== "object")
|
|
463
|
+
if (!artifact || typeof artifact !== "object")
|
|
464
|
+
return;
|
|
453
465
|
const id = data.id ?? artifact.id;
|
|
454
466
|
const ownerDialog = data.dialogKey ?? artifact.dialogKey;
|
|
455
|
-
if (typeof id !== "string" || !id || ownerDialog !== dialogKey || getActiveDialogKey() !== dialogKey)
|
|
467
|
+
if (typeof id !== "string" || !id || ownerDialog !== dialogKey || getActiveDialogKey() !== dialogKey)
|
|
468
|
+
return;
|
|
456
469
|
const execution = ++latestExecution;
|
|
457
470
|
const targetBeforeRead = getPreviewTarget();
|
|
458
471
|
try {
|
|
459
472
|
const latest = await readHtmlArtifact(id);
|
|
460
|
-
if (execution !== latestExecution || getActiveDialogKey() !== dialogKey || getPreviewTarget() !== targetBeforeRead)
|
|
461
|
-
|
|
473
|
+
if (execution !== latestExecution || getActiveDialogKey() !== dialogKey || getPreviewTarget() !== targetBeforeRead)
|
|
474
|
+
return;
|
|
475
|
+
if (latest.id !== id || latest.dialogKey !== dialogKey || !latest.html)
|
|
476
|
+
throw new Error("成品读取结果不匹配");
|
|
462
477
|
openPreviewTarget({ kind: "artifact", artifactId: latest.id, dialogKey: latest.dialogKey, title: latest.title, html: latest.html });
|
|
463
478
|
} catch {
|
|
464
479
|
if (execution === latestExecution && getActiveDialogKey() === dialogKey) {
|
|
465
|
-
toast.error("
|
|
480
|
+
toast.error("网页已保存,但读取最新内容失败。请在结果卡片中重试打开。");
|
|
466
481
|
}
|
|
467
482
|
}
|
|
468
483
|
}
|
|
@@ -470,93 +485,7 @@ function deliverHtmlArtifactToolResult(toolName, content, dialogKey) {
|
|
|
470
485
|
if (!dialogKey || toolName !== "createHtmlArtifact" && toolName !== "updateHtmlArtifact") {
|
|
471
486
|
return;
|
|
472
487
|
}
|
|
473
|
-
|
|
474
|
-
(error) => console.error("[htmlArtifact] live result delivery failed", error)
|
|
475
|
-
);
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
// packages/ai/chat/updateTotalUsage.ts
|
|
479
|
-
function updateTotalUsage(currentUsage, newUsageChunk) {
|
|
480
|
-
if (!newUsageChunk) {
|
|
481
|
-
return currentUsage;
|
|
482
|
-
}
|
|
483
|
-
if (!currentUsage) {
|
|
484
|
-
const hasExplicitTokenField = [
|
|
485
|
-
"prompt_tokens",
|
|
486
|
-
"completion_tokens",
|
|
487
|
-
"total_tokens",
|
|
488
|
-
"input_tokens",
|
|
489
|
-
"output_tokens"
|
|
490
|
-
].some((field) => Object.prototype.hasOwnProperty.call(newUsageChunk, field));
|
|
491
|
-
const first = {
|
|
492
|
-
// Do not synthesize zero token fields for metadata-only events such as
|
|
493
|
-
// `{provider_call_id}`. Explicit provider zeros remain real reported
|
|
494
|
-
// usage; only pure metadata is eligible for estimated fallback.
|
|
495
|
-
...hasExplicitTokenField ? { completion_tokens: 0, prompt_tokens: 0, total_tokens: 0 } : {},
|
|
496
|
-
...newUsageChunk
|
|
497
|
-
};
|
|
498
|
-
applyResponsesUsageFields(first, newUsageChunk);
|
|
499
|
-
return first;
|
|
500
|
-
}
|
|
501
|
-
const updatedUsage = { ...currentUsage };
|
|
502
|
-
if (newUsageChunk.completion_tokens !== void 0) updatedUsage.completion_tokens = newUsageChunk.completion_tokens;
|
|
503
|
-
if (newUsageChunk.prompt_tokens !== void 0) updatedUsage.prompt_tokens = newUsageChunk.prompt_tokens;
|
|
504
|
-
if (newUsageChunk.total_tokens !== void 0) updatedUsage.total_tokens = newUsageChunk.total_tokens;
|
|
505
|
-
applyResponsesUsageFields(updatedUsage, newUsageChunk);
|
|
506
|
-
if (newUsageChunk.prompt_tokens_details) {
|
|
507
|
-
updatedUsage.prompt_tokens_details = {
|
|
508
|
-
...updatedUsage.prompt_tokens_details || {},
|
|
509
|
-
...newUsageChunk.prompt_tokens_details
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
if (newUsageChunk.completion_tokens_details) {
|
|
513
|
-
updatedUsage.completion_tokens_details = {
|
|
514
|
-
...updatedUsage.completion_tokens_details || {},
|
|
515
|
-
...newUsageChunk.completion_tokens_details
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
if (typeof newUsageChunk.cost === "number") {
|
|
519
|
-
updatedUsage.cost = newUsageChunk.cost;
|
|
520
|
-
}
|
|
521
|
-
if (newUsageChunk.cost_details) {
|
|
522
|
-
updatedUsage.cost_details = {
|
|
523
|
-
...updatedUsage.cost_details || {},
|
|
524
|
-
...newUsageChunk.cost_details
|
|
525
|
-
};
|
|
526
|
-
}
|
|
527
|
-
const billingProvider = asOptionalTrimmedString(newUsageChunk.billing_provider);
|
|
528
|
-
if (billingProvider) {
|
|
529
|
-
updatedUsage.billing_provider = billingProvider;
|
|
530
|
-
}
|
|
531
|
-
const billingModel = asOptionalTrimmedString(newUsageChunk.billing_model);
|
|
532
|
-
if (billingModel) {
|
|
533
|
-
updatedUsage.billing_model = billingModel;
|
|
534
|
-
}
|
|
535
|
-
const providerCallId = asOptionalTrimmedString(newUsageChunk.provider_call_id);
|
|
536
|
-
if (providerCallId) {
|
|
537
|
-
updatedUsage.provider_call_id = providerCallId;
|
|
538
|
-
}
|
|
539
|
-
return updatedUsage;
|
|
540
|
-
}
|
|
541
|
-
function applyResponsesUsageFields(target, chunk) {
|
|
542
|
-
if (chunk.input_tokens !== void 0) {
|
|
543
|
-
target.prompt_tokens = chunk.input_tokens;
|
|
544
|
-
}
|
|
545
|
-
if (chunk.output_tokens !== void 0) {
|
|
546
|
-
target.completion_tokens = chunk.output_tokens;
|
|
547
|
-
}
|
|
548
|
-
if (chunk.input_tokens_details) {
|
|
549
|
-
target.prompt_tokens_details = {
|
|
550
|
-
...target.prompt_tokens_details || {},
|
|
551
|
-
...chunk.input_tokens_details
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
if (chunk.output_tokens_details) {
|
|
555
|
-
target.completion_tokens_details = {
|
|
556
|
-
...target.completion_tokens_details || {},
|
|
557
|
-
...chunk.output_tokens_details
|
|
558
|
-
};
|
|
559
|
-
}
|
|
488
|
+
receiveHtmlArtifactToolResult(toolName, content, dialogKey).catch((error) => console.error("[htmlArtifact] live result delivery failed", error));
|
|
560
489
|
}
|
|
561
490
|
|
|
562
491
|
// packages/chat/messages/toolThunks.ts
|
|
@@ -566,7 +495,8 @@ var TOOL_ARGS_SENTINELS = [
|
|
|
566
495
|
"<|endofjson|>"
|
|
567
496
|
];
|
|
568
497
|
function cleanToolArguments(argStr) {
|
|
569
|
-
if (!argStr)
|
|
498
|
+
if (!argStr)
|
|
499
|
+
return argStr;
|
|
570
500
|
let cleaned = argStr;
|
|
571
501
|
for (const s of TOOL_ARGS_SENTINELS) {
|
|
572
502
|
const idx = cleaned.indexOf(s);
|
|
@@ -577,192 +507,91 @@ function cleanToolArguments(argStr) {
|
|
|
577
507
|
return cleaned.trim();
|
|
578
508
|
}
|
|
579
509
|
var defaultSummary = (toolName, status) => {
|
|
580
|
-
if (status === "pending")
|
|
581
|
-
|
|
582
|
-
if (status === "
|
|
583
|
-
|
|
510
|
+
if (status === "pending")
|
|
511
|
+
return `⏸️ ${toolName} 等待确认/授权`;
|
|
512
|
+
if (status === "running")
|
|
513
|
+
return `⏳ ${toolName} 执行中…`;
|
|
514
|
+
if (status === "failed")
|
|
515
|
+
return `❌ ${toolName} 执行失败`;
|
|
516
|
+
return `✅ ${toolName} 执行完成`;
|
|
584
517
|
};
|
|
585
|
-
var RAW_DATA_FALLBACK_MAX_TOTAL_BYTES =
|
|
586
|
-
var RAW_DATA_FALLBACK_MAX_HEAD_BYTES =
|
|
518
|
+
var RAW_DATA_FALLBACK_MAX_TOTAL_BYTES = 4000;
|
|
519
|
+
var RAW_DATA_FALLBACK_MAX_HEAD_BYTES = 1000;
|
|
587
520
|
var RAW_DATA_FALLBACK_MAX_TAIL_BYTES = 2500;
|
|
588
521
|
var buildRawDataLlmContextFallback = (rawData, toolCallId) => {
|
|
589
|
-
const serialized = typeof rawData === "string" ? rawData.trim() : rawData ===
|
|
590
|
-
if (!serialized)
|
|
522
|
+
const serialized = typeof rawData === "string" ? rawData.trim() : rawData === undefined ? "" : JSON.stringify(rawData);
|
|
523
|
+
if (!serialized)
|
|
524
|
+
return;
|
|
591
525
|
const clipped = clipHeadAndTail(serialized, {
|
|
592
526
|
maxHeadBytes: RAW_DATA_FALLBACK_MAX_HEAD_BYTES,
|
|
593
527
|
maxTailBytes: RAW_DATA_FALLBACK_MAX_TAIL_BYTES,
|
|
594
528
|
maxTotalBytes: RAW_DATA_FALLBACK_MAX_TOTAL_BYTES,
|
|
595
|
-
// 完整 rawData 已随 tool message content 原样落盘,无需另写临时日志;
|
|
596
|
-
// 浏览器 stub 本就忽略该选项。
|
|
597
529
|
saveTempLog: false,
|
|
598
530
|
...toolCallId ? { toolCallId } : {}
|
|
599
531
|
});
|
|
600
532
|
return asOptionalTrimmedString(clipped.content);
|
|
601
533
|
};
|
|
602
|
-
var processToolData = createActionAsyncThunk(
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
const
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
toolArgs = JSON.parse(cleaned);
|
|
626
|
-
} catch (e) {
|
|
627
|
-
console.error(
|
|
628
|
-
"[ToolThunks/processToolData] toolArgs JSON.parse failed:",
|
|
629
|
-
toolArgs
|
|
630
|
-
);
|
|
631
|
-
throw new Error(`Failed to parse tool arguments JSON: ${e}`);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
const activity = isRecord(toolArgs) && isRecord(toolArgs._activity) ? toolArgs._activity : void 0;
|
|
635
|
-
const withoutActivity = isRecord(toolArgs) && Object.prototype.hasOwnProperty.call(toolArgs, "_activity") ? (({ _activity: _ignored, ...rest }) => rest)(toolArgs) : toolArgs;
|
|
636
|
-
const executionToolArgs = stripModelToolArgs(canonicalName, withoutActivity);
|
|
637
|
-
const inputSummary = JSON.stringify(executionToolArgs).slice(0, 400);
|
|
638
|
-
toolRunStarted({
|
|
639
|
-
id: toolRunId,
|
|
640
|
-
messageId: parentMessageId,
|
|
641
|
-
toolName: canonicalName,
|
|
642
|
-
behavior,
|
|
643
|
-
inputSummary,
|
|
644
|
-
interaction,
|
|
645
|
-
input: executionToolArgs
|
|
646
|
-
});
|
|
647
|
-
if (interaction === "confirm" || interaction === "authorize") {
|
|
648
|
-
try {
|
|
649
|
-
toolRunSetPending({ id: toolRunId });
|
|
650
|
-
const previewExecutor = def?.previewExecutor;
|
|
651
|
-
const previewResult = previewExecutor ? await previewExecutor(executionToolArgs, toolThunkApi, { parentMessageId }) : {
|
|
652
|
-
rawData: {
|
|
653
|
-
previewOnly: true,
|
|
654
|
-
toolName: canonicalName,
|
|
655
|
-
interaction
|
|
656
|
-
}
|
|
657
|
-
};
|
|
658
|
-
const rawData = previewResult?.rawData ?? previewResult;
|
|
659
|
-
const summary = typeof previewResult?.displayData === "string" && previewResult.displayData.trim() || (interaction === "authorize" ? `\u{1F510} ${canonicalName} \u9700\u8981\u6388\u6743\u540E\u6267\u884C` : `\u26A0\uFE0F ${canonicalName} \u9700\u8981\u786E\u8BA4\u540E\u6267\u884C`);
|
|
660
|
-
const toolPayload = {
|
|
661
|
-
toolName: canonicalName,
|
|
662
|
-
status: "pending",
|
|
663
|
-
interaction,
|
|
664
|
-
input: executionToolArgs,
|
|
665
|
-
rawToolCall: toolCall,
|
|
666
|
-
toolRunId,
|
|
667
|
-
summary,
|
|
668
|
-
...activity ? { activity } : {}
|
|
669
|
-
};
|
|
670
|
-
return {
|
|
671
|
-
toolCallId,
|
|
672
|
-
rawResult: rawData,
|
|
673
|
-
summary,
|
|
674
|
-
toolName: canonicalName,
|
|
675
|
-
toolRunId,
|
|
676
|
-
toolPayload,
|
|
677
|
-
hasPendingInteraction: true
|
|
678
|
-
// ✅ 暂停点
|
|
679
|
-
};
|
|
680
|
-
} catch (e) {
|
|
681
|
-
const errorMessage = toErrorMessage(e);
|
|
682
|
-
const structured = getToolResultErrorData(e);
|
|
683
|
-
const rawErrorResult = structured?.rawData !== void 0 ? structured.rawData : { error: errorMessage };
|
|
684
|
-
const summary = asOptionalTrimmedString(structured?.displayData) || `\u274C ${canonicalName} \u9884\u89C8\u5931\u8D25: ${errorMessage}`;
|
|
685
|
-
toolRunFailed({
|
|
686
|
-
id: toolRunId,
|
|
687
|
-
error: errorMessage,
|
|
688
|
-
outputSummary: summary
|
|
689
|
-
});
|
|
690
|
-
const errorPayload = {
|
|
691
|
-
type: e?.name || "Error",
|
|
692
|
-
message: errorMessage,
|
|
693
|
-
code: structured?.code ?? e?.code,
|
|
694
|
-
retryable: structured?.retryable ?? e?.retryable ?? true
|
|
695
|
-
};
|
|
696
|
-
const toolPayload = {
|
|
697
|
-
toolName: canonicalName,
|
|
698
|
-
status: "failed",
|
|
699
|
-
input: executionToolArgs,
|
|
700
|
-
rawToolCall: toolCall,
|
|
701
|
-
error: errorPayload,
|
|
702
|
-
toolRunId,
|
|
703
|
-
summary,
|
|
704
|
-
...activity ? { activity } : {}
|
|
705
|
-
};
|
|
706
|
-
return rejectWithValue({
|
|
707
|
-
toolCallId,
|
|
708
|
-
rawResult: rawErrorResult,
|
|
709
|
-
summary,
|
|
710
|
-
toolName: canonicalName,
|
|
711
|
-
toolRunId,
|
|
712
|
-
toolPayload,
|
|
713
|
-
hasPendingInteraction: true
|
|
714
|
-
});
|
|
715
|
-
}
|
|
534
|
+
var processToolData = createActionAsyncThunk("message/processToolData", async (args, thunkApi) => {
|
|
535
|
+
const { toolCall, parentMessageId, toolRunId, agentKey } = args;
|
|
536
|
+
const { dispatch, rejectWithValue } = thunkApi;
|
|
537
|
+
const toolThunkApi = { ...thunkApi, serverBase: args.serverBase, runtimeServers: args.runtimeServers };
|
|
538
|
+
const func = toolCall.function;
|
|
539
|
+
if (!func || !func.name) {
|
|
540
|
+
throw new Error("Invalid tool call data: missing function or function.name");
|
|
541
|
+
}
|
|
542
|
+
const toolCallId = toolCall.id || `call_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
543
|
+
const rawToolName = func.name;
|
|
544
|
+
let toolArgs = func.arguments;
|
|
545
|
+
const found = findToolExecutor2(rawToolName);
|
|
546
|
+
const canonicalName = found.canonicalName;
|
|
547
|
+
const def = toolDefinitionsByName2[canonicalName];
|
|
548
|
+
const behavior = def?.behavior;
|
|
549
|
+
const interaction = def?.interaction ?? "auto";
|
|
550
|
+
if (typeof toolArgs === "string") {
|
|
551
|
+
const cleaned = cleanToolArguments(toolArgs);
|
|
552
|
+
try {
|
|
553
|
+
toolArgs = JSON.parse(cleaned);
|
|
554
|
+
} catch (e) {
|
|
555
|
+
console.error("[ToolThunks/processToolData] toolArgs JSON.parse failed:", toolArgs);
|
|
556
|
+
throw new Error(`Failed to parse tool arguments JSON: ${e}`);
|
|
716
557
|
}
|
|
717
|
-
|
|
718
|
-
|
|
558
|
+
}
|
|
559
|
+
const activity = isRecord(toolArgs) && isRecord(toolArgs._activity) ? toolArgs._activity : undefined;
|
|
560
|
+
const withoutActivity = isRecord(toolArgs) && Object.prototype.hasOwnProperty.call(toolArgs, "_activity") ? (({ _activity: _ignored, ...rest }) => rest)(toolArgs) : toolArgs;
|
|
561
|
+
const executionToolArgs = stripModelToolArgs(canonicalName, withoutActivity);
|
|
562
|
+
const inputSummary = JSON.stringify(executionToolArgs).slice(0, 400);
|
|
563
|
+
toolRunStarted({
|
|
564
|
+
id: toolRunId,
|
|
565
|
+
messageId: parentMessageId,
|
|
566
|
+
toolName: canonicalName,
|
|
567
|
+
behavior,
|
|
568
|
+
inputSummary,
|
|
569
|
+
interaction,
|
|
570
|
+
input: executionToolArgs
|
|
571
|
+
});
|
|
572
|
+
if (interaction === "confirm" || interaction === "authorize") {
|
|
719
573
|
try {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
origin: "chat"
|
|
732
|
-
});
|
|
733
|
-
} catch (executorError) {
|
|
734
|
-
executorThrew = true;
|
|
735
|
-
throw executorError;
|
|
736
|
-
}
|
|
737
|
-
const rawData = toolResult?.rawData ?? toolResult;
|
|
738
|
-
const llmContext = asOptionalTrimmedString(toolResult?.llmContext);
|
|
739
|
-
const displayData = asOptionalTrimmedString(toolResult?.displayData);
|
|
740
|
-
const awaitingUserConfirmation = toolResultNeedsUserConfirmation(canonicalName, rawData);
|
|
741
|
-
const summary = displayData || defaultSummary(canonicalName, awaitingUserConfirmation ? "pending" : "succeeded");
|
|
742
|
-
const llmContextFallback = llmContext || displayData || awaitingUserConfirmation ? void 0 : buildRawDataLlmContextFallback(rawData, toolCallId);
|
|
743
|
-
const effectiveLlmContext = llmContext ?? llmContextFallback;
|
|
744
|
-
if (!awaitingUserConfirmation) {
|
|
745
|
-
toolRunSucceeded({
|
|
746
|
-
id: toolRunId,
|
|
747
|
-
outputSummary: summary
|
|
748
|
-
});
|
|
749
|
-
} else {
|
|
750
|
-
toolRunSetPending({ id: toolRunId });
|
|
751
|
-
}
|
|
574
|
+
toolRunSetPending({ id: toolRunId });
|
|
575
|
+
const previewExecutor = def?.previewExecutor;
|
|
576
|
+
const previewResult = previewExecutor ? await previewExecutor(executionToolArgs, toolThunkApi, { parentMessageId }) : {
|
|
577
|
+
rawData: {
|
|
578
|
+
previewOnly: true,
|
|
579
|
+
toolName: canonicalName,
|
|
580
|
+
interaction
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
const rawData = previewResult?.rawData ?? previewResult;
|
|
584
|
+
const summary = typeof previewResult?.displayData === "string" && previewResult.displayData.trim() || (interaction === "authorize" ? `\uD83D\uDD10 ${canonicalName} 需要授权后执行` : `⚠️ ${canonicalName} 需要确认后执行`);
|
|
752
585
|
const toolPayload = {
|
|
753
586
|
toolName: canonicalName,
|
|
754
|
-
status:
|
|
587
|
+
status: "pending",
|
|
755
588
|
interaction,
|
|
756
589
|
input: executionToolArgs,
|
|
757
590
|
rawToolCall: toolCall,
|
|
758
591
|
toolRunId,
|
|
759
592
|
summary,
|
|
760
|
-
...effectiveLlmContext ? { llmContext: effectiveLlmContext } : {},
|
|
761
593
|
...activity ? { activity } : {}
|
|
762
594
|
};
|
|
763
|
-
const isUiAskChoice = canonicalName === "ask_user";
|
|
764
|
-
const blocking = typeof executionToolArgs?.blocking === "boolean" ? executionToolArgs.blocking : true;
|
|
765
|
-
const hasPendingInteraction = isUiAskChoice && blocking === true;
|
|
766
595
|
return {
|
|
767
596
|
toolCallId,
|
|
768
597
|
rawResult: rawData,
|
|
@@ -770,61 +599,13 @@ var processToolData = createActionAsyncThunk(
|
|
|
770
599
|
toolName: canonicalName,
|
|
771
600
|
toolRunId,
|
|
772
601
|
toolPayload,
|
|
773
|
-
hasPendingInteraction
|
|
602
|
+
hasPendingInteraction: true
|
|
774
603
|
};
|
|
775
604
|
} catch (e) {
|
|
776
605
|
const errorMessage = toErrorMessage(e);
|
|
777
606
|
const structured = getToolResultErrorData(e);
|
|
778
|
-
const
|
|
779
|
-
|
|
780
|
-
const confirmedInput = structured?.code === "knowledge_capture_requires_confirmation" ? structured?.rawData?.confirmationInput : { ...executionToolArgs ?? {}, [confirmationKey]: true };
|
|
781
|
-
if (!confirmedInput) throw e;
|
|
782
|
-
const summary2 = typeof structured?.displayData === "string" && structured.displayData.trim() || `\u26A0\uFE0F ${canonicalName} \u9700\u8981\u786E\u8BA4\u540E\u6267\u884C`;
|
|
783
|
-
toolRunStarted({
|
|
784
|
-
id: toolRunId,
|
|
785
|
-
messageId: parentMessageId,
|
|
786
|
-
toolName: canonicalName,
|
|
787
|
-
behavior,
|
|
788
|
-
inputSummary: JSON.stringify(confirmedInput).slice(0, 400),
|
|
789
|
-
interaction: "confirm",
|
|
790
|
-
input: confirmedInput
|
|
791
|
-
});
|
|
792
|
-
toolRunSetPending({ id: toolRunId });
|
|
793
|
-
const toolPayload2 = {
|
|
794
|
-
toolName: canonicalName,
|
|
795
|
-
status: "pending",
|
|
796
|
-
interaction: "confirm",
|
|
797
|
-
input: confirmedInput,
|
|
798
|
-
rawToolCall: toolCall,
|
|
799
|
-
toolRunId,
|
|
800
|
-
summary: summary2,
|
|
801
|
-
...activity ? { activity } : {}
|
|
802
|
-
};
|
|
803
|
-
return {
|
|
804
|
-
toolCallId,
|
|
805
|
-
rawResult: structured?.rawData !== void 0 ? structured.rawData : (
|
|
806
|
-
// 按实际确认码回填(此分支内 code 必在 CONFIRMATION_INPUT_KEYS 中),
|
|
807
|
-
// 不再对所有工具写死 self_evolution 文案。
|
|
808
|
-
{ error: structured?.code }
|
|
809
|
-
),
|
|
810
|
-
summary: summary2,
|
|
811
|
-
toolName: canonicalName,
|
|
812
|
-
toolRunId,
|
|
813
|
-
toolPayload: toolPayload2,
|
|
814
|
-
hasPendingInteraction: true
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
if (executorThrew) {
|
|
818
|
-
reportToolExecutionErrorInBackground({
|
|
819
|
-
thunkApi: toolThunkApi,
|
|
820
|
-
dialogId: args.dialogId,
|
|
821
|
-
callId: toolCallId,
|
|
822
|
-
toolName: canonicalName,
|
|
823
|
-
error: e
|
|
824
|
-
});
|
|
825
|
-
}
|
|
826
|
-
const rawErrorResult = structured?.rawData !== void 0 ? structured.rawData : { error: errorMessage };
|
|
827
|
-
const summary = asOptionalTrimmedString(structured?.displayData) || `\u274C ${canonicalName} \u6267\u884C\u5931\u8D25: ${errorMessage}`;
|
|
607
|
+
const rawErrorResult = structured?.rawData !== undefined ? structured.rawData : { error: errorMessage };
|
|
608
|
+
const summary = asOptionalTrimmedString(structured?.displayData) || `❌ ${canonicalName} 预览失败: ${errorMessage}`;
|
|
828
609
|
toolRunFailed({
|
|
829
610
|
id: toolRunId,
|
|
830
611
|
error: errorMessage,
|
|
@@ -853,194 +634,397 @@ var processToolData = createActionAsyncThunk(
|
|
|
853
634
|
toolName: canonicalName,
|
|
854
635
|
toolRunId,
|
|
855
636
|
toolPayload,
|
|
856
|
-
hasPendingInteraction:
|
|
637
|
+
hasPendingInteraction: true
|
|
857
638
|
});
|
|
858
639
|
}
|
|
859
640
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
641
|
+
let toolResult;
|
|
642
|
+
let executorThrew = false;
|
|
643
|
+
try {
|
|
644
|
+
try {
|
|
645
|
+
toolResult = await found.executor(executionToolArgs, toolThunkApi, {
|
|
646
|
+
parentMessageId,
|
|
647
|
+
toolRunId,
|
|
648
|
+
agentKey,
|
|
649
|
+
effectiveModel: args.effectiveModel,
|
|
650
|
+
runKind: "interactive",
|
|
651
|
+
...args.dialogId ? { dialogId: args.dialogId } : {},
|
|
652
|
+
...args.userMessageId ? { userMessageId: args.userMessageId } : {},
|
|
653
|
+
...canonicalName === "openAIGptImageGenerate" ? { currentReferenceImageUrls: args.currentReferenceImageUrls } : {},
|
|
654
|
+
origin: "chat"
|
|
655
|
+
});
|
|
656
|
+
} catch (executorError) {
|
|
657
|
+
executorThrew = true;
|
|
658
|
+
throw executorError;
|
|
659
|
+
}
|
|
660
|
+
const rawData = toolResult?.rawData ?? toolResult;
|
|
661
|
+
const llmContext = asOptionalTrimmedString(toolResult?.llmContext);
|
|
662
|
+
const displayData = asOptionalTrimmedString(toolResult?.displayData);
|
|
663
|
+
const awaitingUserConfirmation = toolResultNeedsUserConfirmation(canonicalName, rawData);
|
|
664
|
+
const summary = displayData || defaultSummary(canonicalName, awaitingUserConfirmation ? "pending" : "succeeded");
|
|
665
|
+
const llmContextFallback = llmContext || displayData || awaitingUserConfirmation ? undefined : buildRawDataLlmContextFallback(rawData, toolCallId);
|
|
666
|
+
const effectiveLlmContext = llmContext ?? llmContextFallback;
|
|
667
|
+
if (!awaitingUserConfirmation) {
|
|
668
|
+
toolRunSucceeded({
|
|
669
|
+
id: toolRunId,
|
|
670
|
+
outputSummary: summary
|
|
671
|
+
});
|
|
672
|
+
} else {
|
|
673
|
+
toolRunSetPending({ id: toolRunId });
|
|
674
|
+
}
|
|
675
|
+
const toolPayload = {
|
|
676
|
+
toolName: canonicalName,
|
|
677
|
+
status: awaitingUserConfirmation ? "pending" : "succeeded",
|
|
678
|
+
interaction,
|
|
679
|
+
input: executionToolArgs,
|
|
680
|
+
rawToolCall: toolCall,
|
|
681
|
+
toolRunId,
|
|
682
|
+
summary,
|
|
683
|
+
...effectiveLlmContext ? { llmContext: effectiveLlmContext } : {},
|
|
684
|
+
...activity ? { activity } : {}
|
|
685
|
+
};
|
|
686
|
+
const isUiAskChoice = canonicalName === "ask_user";
|
|
687
|
+
const blocking = typeof executionToolArgs?.blocking === "boolean" ? executionToolArgs.blocking : true;
|
|
688
|
+
const hasPendingInteraction = isUiAskChoice && blocking === true;
|
|
689
|
+
return {
|
|
690
|
+
toolCallId,
|
|
691
|
+
rawResult: rawData,
|
|
692
|
+
summary,
|
|
693
|
+
toolName: canonicalName,
|
|
694
|
+
toolRunId,
|
|
695
|
+
toolPayload,
|
|
696
|
+
hasPendingInteraction
|
|
697
|
+
};
|
|
698
|
+
} catch (e) {
|
|
699
|
+
const errorMessage = toErrorMessage(e);
|
|
700
|
+
const structured = getToolResultErrorData(e);
|
|
701
|
+
const confirmationKey = structured?.code ? CONFIRMATION_INPUT_KEYS[structured.code] : undefined;
|
|
702
|
+
if (confirmationKey) {
|
|
703
|
+
const confirmedInput = structured?.code === "knowledge_capture_requires_confirmation" ? structured?.rawData?.confirmationInput : { ...executionToolArgs ?? {}, [confirmationKey]: true };
|
|
704
|
+
if (!confirmedInput)
|
|
705
|
+
throw e;
|
|
706
|
+
const summary = typeof structured?.displayData === "string" && structured.displayData.trim() || `⚠️ ${canonicalName} 需要确认后执行`;
|
|
707
|
+
toolRunStarted({
|
|
708
|
+
id: toolRunId,
|
|
709
|
+
messageId: parentMessageId,
|
|
710
|
+
toolName: canonicalName,
|
|
711
|
+
behavior,
|
|
712
|
+
inputSummary: JSON.stringify(confirmedInput).slice(0, 400),
|
|
713
|
+
interaction: "confirm",
|
|
714
|
+
input: confirmedInput
|
|
715
|
+
});
|
|
716
|
+
toolRunSetPending({ id: toolRunId });
|
|
717
|
+
const toolPayload = {
|
|
718
|
+
toolName: canonicalName,
|
|
719
|
+
status: "pending",
|
|
720
|
+
interaction: "confirm",
|
|
721
|
+
input: confirmedInput,
|
|
722
|
+
rawToolCall: toolCall,
|
|
723
|
+
toolRunId,
|
|
724
|
+
summary,
|
|
725
|
+
...activity ? { activity } : {}
|
|
726
|
+
};
|
|
727
|
+
return {
|
|
892
728
|
toolCallId,
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
toolName: canonicalToolName,
|
|
897
|
-
parentMessageId: messageId,
|
|
729
|
+
rawResult: structured?.rawData !== undefined ? structured.rawData : { error: structured?.code },
|
|
730
|
+
summary,
|
|
731
|
+
toolName: canonicalName,
|
|
898
732
|
toolRunId,
|
|
899
|
-
toolPayload
|
|
900
|
-
|
|
901
|
-
status: "running",
|
|
902
|
-
input: {},
|
|
903
|
-
rawToolCall: toolCall,
|
|
904
|
-
toolRunId,
|
|
905
|
-
summary: defaultSummary(canonicalToolName, "running")
|
|
906
|
-
}
|
|
733
|
+
toolPayload,
|
|
734
|
+
hasPendingInteraction: true
|
|
907
735
|
};
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
736
|
+
}
|
|
737
|
+
if (executorThrew) {
|
|
738
|
+
reportToolExecutionErrorInBackground({
|
|
739
|
+
thunkApi: toolThunkApi,
|
|
740
|
+
dialogId: args.dialogId,
|
|
741
|
+
callId: toolCallId,
|
|
742
|
+
toolName: canonicalName,
|
|
743
|
+
error: e
|
|
912
744
|
});
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
745
|
+
}
|
|
746
|
+
const rawErrorResult = structured?.rawData !== undefined ? structured.rawData : { error: errorMessage };
|
|
747
|
+
const summary = asOptionalTrimmedString(structured?.displayData) || `❌ ${canonicalName} 执行失败: ${errorMessage}`;
|
|
748
|
+
toolRunFailed({
|
|
749
|
+
id: toolRunId,
|
|
750
|
+
error: errorMessage,
|
|
751
|
+
outputSummary: summary
|
|
752
|
+
});
|
|
753
|
+
const errorPayload = {
|
|
754
|
+
type: e?.name || "Error",
|
|
755
|
+
message: errorMessage,
|
|
756
|
+
code: structured?.code ?? e?.code,
|
|
757
|
+
retryable: structured?.retryable ?? e?.retryable ?? true
|
|
758
|
+
};
|
|
759
|
+
const toolPayload = {
|
|
760
|
+
toolName: canonicalName,
|
|
761
|
+
status: "failed",
|
|
762
|
+
input: executionToolArgs,
|
|
763
|
+
rawToolCall: toolCall,
|
|
764
|
+
error: errorPayload,
|
|
765
|
+
toolRunId,
|
|
766
|
+
summary,
|
|
767
|
+
...activity ? { activity } : {}
|
|
768
|
+
};
|
|
769
|
+
return rejectWithValue({
|
|
770
|
+
toolCallId,
|
|
771
|
+
rawResult: rawErrorResult,
|
|
772
|
+
summary,
|
|
773
|
+
toolName: canonicalName,
|
|
774
|
+
toolRunId,
|
|
775
|
+
toolPayload,
|
|
776
|
+
hasPendingInteraction: false
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
var handleToolCalls = createActionAsyncThunk("message/handleToolCalls", async (args, thunkApi) => {
|
|
781
|
+
const {
|
|
782
|
+
accumulatedCalls,
|
|
783
|
+
currentContentBuffer,
|
|
784
|
+
agentConfig,
|
|
785
|
+
messageId,
|
|
786
|
+
dialogId,
|
|
787
|
+
dialogKey
|
|
788
|
+
} = args;
|
|
789
|
+
const { dispatch } = thunkApi;
|
|
790
|
+
const updatedContentBuffer = [...currentContentBuffer];
|
|
791
|
+
let hasHandedOff = false;
|
|
792
|
+
let hasPendingInteraction = false;
|
|
793
|
+
for (let toolIndex = 0;toolIndex < accumulatedCalls.length; toolIndex++) {
|
|
794
|
+
const toolCall = accumulatedCalls[toolIndex];
|
|
795
|
+
if (!toolCall.function?.name)
|
|
796
|
+
continue;
|
|
797
|
+
const toolCallId = toolCall.id || `call_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
798
|
+
const toolRunId = createToolRunId();
|
|
799
|
+
const canonicalToolName = findToolExecutor2(toolCall.function.name).canonicalName;
|
|
800
|
+
const runningToolMessageId = `${messageId}-t${String(toolIndex).padStart(3, "0")}`;
|
|
801
|
+
const runningToolDbKey = dialogMessageKey2(dialogId, runningToolMessageId);
|
|
802
|
+
const runningToolMessage = {
|
|
803
|
+
id: runningToolMessageId,
|
|
804
|
+
dbKey: runningToolDbKey,
|
|
805
|
+
dialogId,
|
|
806
|
+
role: "tool",
|
|
807
|
+
content: JSON.stringify({ pending: true }),
|
|
808
|
+
toolCallId,
|
|
809
|
+
thinkContent: "",
|
|
810
|
+
cybotKey: agentConfig.dbKey,
|
|
811
|
+
isStreaming: true,
|
|
812
|
+
toolName: canonicalToolName,
|
|
813
|
+
parentMessageId: messageId,
|
|
814
|
+
toolRunId,
|
|
815
|
+
toolPayload: {
|
|
816
|
+
toolName: canonicalToolName,
|
|
817
|
+
status: "running",
|
|
818
|
+
input: {},
|
|
819
|
+
rawToolCall: toolCall,
|
|
820
|
+
toolRunId,
|
|
821
|
+
summary: defaultSummary(canonicalToolName, "running")
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
dispatch(addToolMessage(runningToolMessage));
|
|
825
|
+
await persistToolMessage(dispatch, runningToolMessage, {
|
|
826
|
+
isStreaming: true,
|
|
827
|
+
soft: true
|
|
828
|
+
});
|
|
829
|
+
try {
|
|
830
|
+
const result = await dispatch(processToolData({
|
|
831
|
+
toolCall: { ...toolCall, id: toolCallId },
|
|
832
|
+
parentMessageId: messageId,
|
|
833
|
+
toolRunId,
|
|
834
|
+
agentKey: agentConfig.dbKey,
|
|
835
|
+
effectiveModel: agentConfig.model,
|
|
836
|
+
dialogId,
|
|
837
|
+
userMessageId: args.userMessageId,
|
|
838
|
+
currentReferenceImageUrls: args.currentReferenceImageUrls,
|
|
839
|
+
serverBase: args.serverBase,
|
|
840
|
+
runtimeServers: args.runtimeServers
|
|
841
|
+
})).unwrap();
|
|
842
|
+
const toolName = result.toolName;
|
|
843
|
+
let rawResult = result.rawResult;
|
|
844
|
+
let toolPayload = result.toolPayload;
|
|
845
|
+
if (toolPayload?.status === "succeeded") {
|
|
846
|
+
deliverHtmlArtifactToolResult(toolName, rawResult, dialogKey);
|
|
847
|
+
}
|
|
848
|
+
if (toolName) {
|
|
849
|
+
const completedToolMessage = {
|
|
850
|
+
...runningToolMessage,
|
|
851
|
+
content: JSON.stringify(rawResult),
|
|
852
|
+
toolCallId: result.toolCallId,
|
|
853
|
+
isStreaming: false,
|
|
854
|
+
toolName,
|
|
855
|
+
toolRunId: result.toolRunId,
|
|
856
|
+
toolPayload
|
|
857
|
+
};
|
|
858
|
+
dispatch(updateToolMessage({
|
|
859
|
+
id: runningToolMessageId,
|
|
860
|
+
changes: {
|
|
861
|
+
content: completedToolMessage.content,
|
|
862
|
+
toolCallId: completedToolMessage.toolCallId,
|
|
939
863
|
isStreaming: false,
|
|
940
864
|
toolName,
|
|
941
865
|
toolRunId: result.toolRunId,
|
|
942
866
|
toolPayload
|
|
943
|
-
};
|
|
944
|
-
dispatch(
|
|
945
|
-
updateToolMessage({
|
|
946
|
-
id: runningToolMessageId,
|
|
947
|
-
changes: {
|
|
948
|
-
content: completedToolMessage.content,
|
|
949
|
-
toolCallId: completedToolMessage.toolCallId,
|
|
950
|
-
isStreaming: false,
|
|
951
|
-
toolName,
|
|
952
|
-
toolRunId: result.toolRunId,
|
|
953
|
-
toolPayload
|
|
954
|
-
}
|
|
955
|
-
})
|
|
956
|
-
);
|
|
957
|
-
await persistToolMessage(dispatch, completedToolMessage, {
|
|
958
|
-
isStreaming: false,
|
|
959
|
-
soft: true
|
|
960
|
-
});
|
|
961
|
-
if (result.hasPendingInteraction) {
|
|
962
|
-
hasPendingInteraction = true;
|
|
963
867
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
868
|
+
}));
|
|
869
|
+
await persistToolMessage(dispatch, completedToolMessage, {
|
|
870
|
+
isStreaming: false,
|
|
871
|
+
soft: true
|
|
872
|
+
});
|
|
873
|
+
if (result.hasPendingInteraction) {
|
|
874
|
+
hasPendingInteraction = true;
|
|
875
|
+
}
|
|
876
|
+
if (toolName === "runStreamingAgent") {
|
|
877
|
+
const raw = result.rawResult ?? {};
|
|
878
|
+
const agentKey = raw.agentKey;
|
|
879
|
+
const userInput = raw.userInput;
|
|
880
|
+
const serverBase = asOptionalTrimmedString(raw.serverBase);
|
|
881
|
+
if (agentKey && userInput) {
|
|
882
|
+
hasHandedOff = true;
|
|
883
|
+
dispatch(streamAgentChatTurn2({
|
|
884
|
+
agentKey,
|
|
885
|
+
userInput,
|
|
886
|
+
...dialogKey ? { dialogKey } : {},
|
|
887
|
+
...serverBase ? { serverBase } : {}
|
|
888
|
+
}));
|
|
980
889
|
}
|
|
981
890
|
}
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
891
|
+
}
|
|
892
|
+
} catch (rejectedValue) {
|
|
893
|
+
console.error("[ToolThunks/handleToolCalls] processToolData rejected:", rejectedValue);
|
|
894
|
+
if (rejectedValue.toolName) {
|
|
895
|
+
const errorResult = {
|
|
896
|
+
error: true,
|
|
897
|
+
message: rejectedValue.toolPayload?.error?.message || "未知错误"
|
|
898
|
+
};
|
|
899
|
+
const failedToolMessage = {
|
|
900
|
+
...runningToolMessage,
|
|
901
|
+
content: JSON.stringify(errorResult),
|
|
902
|
+
toolCallId: rejectedValue.toolCallId,
|
|
903
|
+
isStreaming: false,
|
|
904
|
+
toolName: rejectedValue.toolName,
|
|
905
|
+
toolRunId: rejectedValue.toolRunId,
|
|
906
|
+
toolPayload: rejectedValue.toolPayload
|
|
907
|
+
};
|
|
908
|
+
dispatch(updateToolMessage({
|
|
909
|
+
id: runningToolMessageId,
|
|
910
|
+
changes: {
|
|
911
|
+
content: failedToolMessage.content,
|
|
912
|
+
toolCallId: failedToolMessage.toolCallId,
|
|
996
913
|
isStreaming: false,
|
|
997
914
|
toolName: rejectedValue.toolName,
|
|
998
915
|
toolRunId: rejectedValue.toolRunId,
|
|
999
916
|
toolPayload: rejectedValue.toolPayload
|
|
1000
|
-
};
|
|
1001
|
-
dispatch(
|
|
1002
|
-
updateToolMessage({
|
|
1003
|
-
id: runningToolMessageId,
|
|
1004
|
-
changes: {
|
|
1005
|
-
content: failedToolMessage.content,
|
|
1006
|
-
toolCallId: failedToolMessage.toolCallId,
|
|
1007
|
-
isStreaming: false,
|
|
1008
|
-
toolName: rejectedValue.toolName,
|
|
1009
|
-
toolRunId: rejectedValue.toolRunId,
|
|
1010
|
-
toolPayload: rejectedValue.toolPayload
|
|
1011
|
-
}
|
|
1012
|
-
})
|
|
1013
|
-
);
|
|
1014
|
-
await persistToolMessage(dispatch, failedToolMessage, {
|
|
1015
|
-
isStreaming: false,
|
|
1016
|
-
soft: true
|
|
1017
|
-
});
|
|
1018
|
-
if (rejectedValue.hasPendingInteraction) {
|
|
1019
|
-
hasPendingInteraction = true;
|
|
1020
917
|
}
|
|
918
|
+
}));
|
|
919
|
+
await persistToolMessage(dispatch, failedToolMessage, {
|
|
920
|
+
isStreaming: false,
|
|
921
|
+
soft: true
|
|
922
|
+
});
|
|
923
|
+
if (rejectedValue.hasPendingInteraction) {
|
|
924
|
+
hasPendingInteraction = true;
|
|
1021
925
|
}
|
|
1022
926
|
}
|
|
1023
927
|
}
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
928
|
+
}
|
|
929
|
+
return {
|
|
930
|
+
finalContentBuffer: updatedContentBuffer,
|
|
931
|
+
hasHandedOff,
|
|
932
|
+
hasPendingInteraction
|
|
933
|
+
};
|
|
934
|
+
});
|
|
935
|
+
|
|
936
|
+
// packages/ai/chat/updateTotalUsage.ts
|
|
937
|
+
function updateTotalUsage(currentUsage, newUsageChunk) {
|
|
938
|
+
if (!newUsageChunk) {
|
|
939
|
+
return currentUsage;
|
|
940
|
+
}
|
|
941
|
+
if (!currentUsage) {
|
|
942
|
+
const hasExplicitTokenField = [
|
|
943
|
+
"prompt_tokens",
|
|
944
|
+
"completion_tokens",
|
|
945
|
+
"total_tokens",
|
|
946
|
+
"input_tokens",
|
|
947
|
+
"output_tokens"
|
|
948
|
+
].some((field) => Object.prototype.hasOwnProperty.call(newUsageChunk, field));
|
|
949
|
+
const first = {
|
|
950
|
+
...hasExplicitTokenField ? { completion_tokens: 0, prompt_tokens: 0, total_tokens: 0 } : {},
|
|
951
|
+
...newUsageChunk
|
|
952
|
+
};
|
|
953
|
+
applyResponsesUsageFields(first, newUsageChunk);
|
|
954
|
+
return first;
|
|
955
|
+
}
|
|
956
|
+
const updatedUsage = { ...currentUsage };
|
|
957
|
+
if (newUsageChunk.completion_tokens !== undefined)
|
|
958
|
+
updatedUsage.completion_tokens = newUsageChunk.completion_tokens;
|
|
959
|
+
if (newUsageChunk.prompt_tokens !== undefined)
|
|
960
|
+
updatedUsage.prompt_tokens = newUsageChunk.prompt_tokens;
|
|
961
|
+
if (newUsageChunk.total_tokens !== undefined)
|
|
962
|
+
updatedUsage.total_tokens = newUsageChunk.total_tokens;
|
|
963
|
+
applyResponsesUsageFields(updatedUsage, newUsageChunk);
|
|
964
|
+
if (newUsageChunk.prompt_tokens_details) {
|
|
965
|
+
updatedUsage.prompt_tokens_details = {
|
|
966
|
+
...updatedUsage.prompt_tokens_details || {},
|
|
967
|
+
...newUsageChunk.prompt_tokens_details
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
if (newUsageChunk.completion_tokens_details) {
|
|
971
|
+
updatedUsage.completion_tokens_details = {
|
|
972
|
+
...updatedUsage.completion_tokens_details || {},
|
|
973
|
+
...newUsageChunk.completion_tokens_details
|
|
1028
974
|
};
|
|
1029
975
|
}
|
|
1030
|
-
)
|
|
976
|
+
if (typeof newUsageChunk.cost === "number") {
|
|
977
|
+
updatedUsage.cost = newUsageChunk.cost;
|
|
978
|
+
}
|
|
979
|
+
if (newUsageChunk.cost_details) {
|
|
980
|
+
updatedUsage.cost_details = {
|
|
981
|
+
...updatedUsage.cost_details || {},
|
|
982
|
+
...newUsageChunk.cost_details
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
const billingProvider = asOptionalTrimmedString(newUsageChunk.billing_provider);
|
|
986
|
+
if (billingProvider) {
|
|
987
|
+
updatedUsage.billing_provider = billingProvider;
|
|
988
|
+
}
|
|
989
|
+
const billingModel = asOptionalTrimmedString(newUsageChunk.billing_model);
|
|
990
|
+
if (billingModel) {
|
|
991
|
+
updatedUsage.billing_model = billingModel;
|
|
992
|
+
}
|
|
993
|
+
const providerCallId = asOptionalTrimmedString(newUsageChunk.provider_call_id);
|
|
994
|
+
if (providerCallId) {
|
|
995
|
+
updatedUsage.provider_call_id = providerCallId;
|
|
996
|
+
}
|
|
997
|
+
return updatedUsage;
|
|
998
|
+
}
|
|
999
|
+
function applyResponsesUsageFields(target, chunk) {
|
|
1000
|
+
if (chunk.input_tokens !== undefined) {
|
|
1001
|
+
target.prompt_tokens = chunk.input_tokens;
|
|
1002
|
+
}
|
|
1003
|
+
if (chunk.output_tokens !== undefined) {
|
|
1004
|
+
target.completion_tokens = chunk.output_tokens;
|
|
1005
|
+
}
|
|
1006
|
+
if (chunk.input_tokens_details) {
|
|
1007
|
+
target.prompt_tokens_details = {
|
|
1008
|
+
...target.prompt_tokens_details || {},
|
|
1009
|
+
...chunk.input_tokens_details
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
if (chunk.output_tokens_details) {
|
|
1013
|
+
target.completion_tokens_details = {
|
|
1014
|
+
...target.completion_tokens_details || {},
|
|
1015
|
+
...chunk.output_tokens_details
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1031
1019
|
|
|
1032
1020
|
// packages/ai/chat/accumulateToolCallChunks.ts
|
|
1033
1021
|
function accumulateToolCallChunks(currentAccumulatedCalls, toolCallChunks) {
|
|
1034
1022
|
const accumulator = {
|
|
1035
|
-
slots: currentAccumulatedCalls.map(
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
function: { ...call.function },
|
|
1041
|
-
wireIndex: call.index ?? position
|
|
1042
|
-
})
|
|
1043
|
-
)
|
|
1023
|
+
slots: currentAccumulatedCalls.map((call, position) => ({
|
|
1024
|
+
...call,
|
|
1025
|
+
function: { ...call.function },
|
|
1026
|
+
wireIndex: call.index ?? position
|
|
1027
|
+
}))
|
|
1044
1028
|
};
|
|
1045
1029
|
accumulateToolCallDelta(accumulator, toolCallChunks);
|
|
1046
1030
|
return accumulator.slots.map(({ wireIndex, ...call }) => ({
|
|
@@ -1067,60 +1051,60 @@ async function readStreamChunk(reader, options) {
|
|
|
1067
1051
|
let onAbort;
|
|
1068
1052
|
return new Promise((resolve, reject) => {
|
|
1069
1053
|
const finish = (cb) => {
|
|
1070
|
-
if (settled)
|
|
1054
|
+
if (settled)
|
|
1055
|
+
return;
|
|
1071
1056
|
settled = true;
|
|
1072
|
-
if (timeoutId)
|
|
1073
|
-
|
|
1057
|
+
if (timeoutId)
|
|
1058
|
+
clearTimeout(timeoutId);
|
|
1059
|
+
if (onAbort && signal)
|
|
1060
|
+
signal.removeEventListener("abort", onAbort);
|
|
1074
1061
|
cb();
|
|
1075
1062
|
};
|
|
1076
1063
|
onAbort = () => {
|
|
1077
|
-
|
|
1078
|
-
});
|
|
1064
|
+
reader.cancel().catch(() => {});
|
|
1079
1065
|
finish(() => reject(createAbortError()));
|
|
1080
1066
|
};
|
|
1081
1067
|
signal?.addEventListener("abort", onAbort);
|
|
1082
1068
|
if (timeoutMs && timeoutMs > 0) {
|
|
1083
1069
|
timeoutId = setTimeout(() => {
|
|
1084
|
-
finish(
|
|
1085
|
-
() => reject(
|
|
1086
|
-
new Error(
|
|
1087
|
-
options?.timeoutErrorMessage ?? `Stream stalled for ${Math.round(timeoutMs / 1e3)}s`
|
|
1088
|
-
)
|
|
1089
|
-
)
|
|
1090
|
-
);
|
|
1070
|
+
finish(() => reject(new Error(options?.timeoutErrorMessage ?? `Stream stalled for ${Math.round(timeoutMs / 1000)}s`)));
|
|
1091
1071
|
}, timeoutMs);
|
|
1092
1072
|
}
|
|
1093
|
-
reader.read().then(
|
|
1094
|
-
(result) => finish(() => resolve(result)),
|
|
1095
|
-
(err) => finish(() => reject(err))
|
|
1096
|
-
);
|
|
1073
|
+
reader.read().then((result) => finish(() => resolve(result)), (err) => finish(() => reject(err)));
|
|
1097
1074
|
});
|
|
1098
1075
|
}
|
|
1099
1076
|
|
|
1100
1077
|
// packages/ai/agent/utils/imageOutput.ts
|
|
1101
|
-
var LEGACY_IMAGE_MODELS =
|
|
1078
|
+
var LEGACY_IMAGE_MODELS = new Set([
|
|
1102
1079
|
"google/gemini-3-pro-image",
|
|
1103
1080
|
"google/gemini-nano-banana-2.1"
|
|
1104
1081
|
]);
|
|
1105
1082
|
function supportsImageGeneration(agent) {
|
|
1106
|
-
if (agent.hasImageOutput === true)
|
|
1107
|
-
|
|
1083
|
+
if (agent.hasImageOutput === true)
|
|
1084
|
+
return true;
|
|
1085
|
+
if (getPublicImageAgentMode(agent) === "continuous")
|
|
1086
|
+
return true;
|
|
1108
1087
|
const modelName = toTrimmedString(agent.model);
|
|
1109
|
-
if (!modelName)
|
|
1088
|
+
if (!modelName)
|
|
1089
|
+
return false;
|
|
1110
1090
|
const modelInfo = getModelInfo(modelName);
|
|
1111
1091
|
if (modelInfo) {
|
|
1112
1092
|
return !!(modelInfo.hasImageOutput ?? modelInfo.supportsImageOutput);
|
|
1113
1093
|
}
|
|
1114
1094
|
const normalized = modelName.toLowerCase();
|
|
1115
|
-
if (LEGACY_IMAGE_MODELS.has(normalized))
|
|
1116
|
-
|
|
1117
|
-
if (
|
|
1095
|
+
if (LEGACY_IMAGE_MODELS.has(normalized))
|
|
1096
|
+
return true;
|
|
1097
|
+
if (agent.imageConfig?.enabled && agent.hasVision)
|
|
1098
|
+
return true;
|
|
1099
|
+
if (getPublicImageAgentMode(agent) === "continuous")
|
|
1100
|
+
return true;
|
|
1118
1101
|
return normalized.includes("image-preview") || normalized.includes("flash-image") || normalized.includes("seedream") || normalized.includes("flux.");
|
|
1119
1102
|
}
|
|
1120
1103
|
|
|
1121
1104
|
// packages/ai/chat/sendOpenAICompletionsRequest.ts
|
|
1122
1105
|
function appendTextChunk(currentContentBuffer, textChunk) {
|
|
1123
|
-
if (!textChunk)
|
|
1106
|
+
if (!textChunk)
|
|
1107
|
+
return currentContentBuffer;
|
|
1124
1108
|
const updatedContentBuffer = [...currentContentBuffer];
|
|
1125
1109
|
const lastIndex = updatedContentBuffer.length - 1;
|
|
1126
1110
|
if (lastIndex >= 0 && updatedContentBuffer[lastIndex].type === "text") {
|
|
@@ -1134,7 +1118,7 @@ function appendTextChunk(currentContentBuffer, textChunk) {
|
|
|
1134
1118
|
}
|
|
1135
1119
|
return updatedContentBuffer;
|
|
1136
1120
|
}
|
|
1137
|
-
var EXPLICIT_IMAGE_TOOL_NAMES =
|
|
1121
|
+
var EXPLICIT_IMAGE_TOOL_NAMES = new Set([
|
|
1138
1122
|
"openAIGptImage",
|
|
1139
1123
|
"openAIGptImageGenerate",
|
|
1140
1124
|
"chatgptWebImageGenerate",
|
|
@@ -1143,31 +1127,34 @@ var EXPLICIT_IMAGE_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
|
1143
1127
|
]);
|
|
1144
1128
|
function getStreamErrorMessage(data) {
|
|
1145
1129
|
const message = asOptionalTrimmedString(data?.error?.message) ?? asOptionalTrimmedString(data?.error?.msg) ?? asOptionalTrimmedString(data?.message);
|
|
1146
|
-
if (message)
|
|
1130
|
+
if (message)
|
|
1131
|
+
return message;
|
|
1147
1132
|
const code = asOptionalTrimmedString(data?.error?.code) ?? asOptionalTrimmedString(data?.code);
|
|
1148
|
-
if (code)
|
|
1133
|
+
if (code)
|
|
1134
|
+
return code;
|
|
1149
1135
|
return "Unknown error";
|
|
1150
1136
|
}
|
|
1151
1137
|
function formatStreamErrorMessage(data) {
|
|
1152
1138
|
const rawMessage = getStreamErrorMessage(data);
|
|
1153
|
-
if (/prohibited|violation|terms\s+of\s+service|content\s+policy|safety/i.test(
|
|
1154
|
-
|
|
1155
|
-
)) {
|
|
1156
|
-
return "\u5F53\u524D\u6A21\u578B\u670D\u52A1\u5546\u62D2\u7EDD\u4E86\u8FD9\u6B21\u8BF7\u6C42\u3002\u4F60\u53EF\u4EE5\u7A0D\u540E\u91CD\u8BD5\uFF0C\u6216\u5207\u6362\u5230\u5176\u4ED6\u6A21\u578B\u7EE7\u7EED\u3002";
|
|
1139
|
+
if (/prohibited|violation|terms\s+of\s+service|content\s+policy|safety/i.test(rawMessage)) {
|
|
1140
|
+
return "当前模型服务商拒绝了这次请求。你可以稍后重试,或切换到其他模型继续。";
|
|
1157
1141
|
}
|
|
1158
1142
|
return rawMessage;
|
|
1159
1143
|
}
|
|
1160
1144
|
function getChoiceFinishErrorMessage(data, choice) {
|
|
1161
1145
|
if (choice?.error || choice?.message || choice?.code) {
|
|
1162
1146
|
const message = formatStreamErrorMessage(choice);
|
|
1163
|
-
if (message && message !== "Unknown error")
|
|
1147
|
+
if (message && message !== "Unknown error")
|
|
1148
|
+
return message;
|
|
1164
1149
|
}
|
|
1165
1150
|
if (data?.error || data?.message || data?.code) {
|
|
1166
1151
|
const message = formatStreamErrorMessage(data);
|
|
1167
|
-
if (message && message !== "Unknown error")
|
|
1152
|
+
if (message && message !== "Unknown error")
|
|
1153
|
+
return message;
|
|
1168
1154
|
}
|
|
1169
1155
|
const messageContent = asOptionalTrimmedString(choice?.message?.content);
|
|
1170
|
-
if (messageContent)
|
|
1156
|
+
if (messageContent)
|
|
1157
|
+
return messageContent;
|
|
1171
1158
|
return null;
|
|
1172
1159
|
}
|
|
1173
1160
|
var withImageGenerationStage = (messageMetadata, stage) => {
|
|
@@ -1183,12 +1170,11 @@ var withImageGenerationStage = (messageMetadata, stage) => {
|
|
|
1183
1170
|
}
|
|
1184
1171
|
};
|
|
1185
1172
|
};
|
|
1186
|
-
var shouldShowImageSavingState = (contentBuffer) => contentBuffer.some((part) => part?.type === "image_url") && !contentBuffer.some(
|
|
1187
|
-
|
|
1188
|
-
);
|
|
1189
|
-
var STREAM_READ_TIMEOUT_MS = 45e3;
|
|
1173
|
+
var shouldShowImageSavingState = (contentBuffer) => contentBuffer.some((part) => part?.type === "image_url") && !contentBuffer.some((part) => part?.type === "text" && typeof part.text === "string" && part.text.trim().length > 0);
|
|
1174
|
+
var STREAM_READ_TIMEOUT_MS = 45000;
|
|
1190
1175
|
var logQuickChatPerfStage = (startedAt, stage, details) => {
|
|
1191
|
-
if (!startedAt)
|
|
1176
|
+
if (!startedAt)
|
|
1177
|
+
return;
|
|
1192
1178
|
const now = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
1193
1179
|
console.info("[QuickChatPerf]", {
|
|
1194
1180
|
stage,
|
|
@@ -1205,7 +1191,7 @@ function createInitialStreamState() {
|
|
|
1205
1191
|
reasoningBuffer: "",
|
|
1206
1192
|
thinkState: createThinkParserState(),
|
|
1207
1193
|
toolCallTextState: createToolCallTextParserState(),
|
|
1208
|
-
assistantToolCalls:
|
|
1194
|
+
assistantToolCalls: undefined,
|
|
1209
1195
|
hasHandedOff: false,
|
|
1210
1196
|
hasProcessedToolCalls: false,
|
|
1211
1197
|
alreadyFinalized: false,
|
|
@@ -1215,8 +1201,10 @@ function createInitialStreamState() {
|
|
|
1215
1201
|
};
|
|
1216
1202
|
}
|
|
1217
1203
|
function shouldSkipBillingForUserAbort(error, totalUsage) {
|
|
1218
|
-
if (!isAbortError(error))
|
|
1219
|
-
|
|
1204
|
+
if (!isAbortError(error))
|
|
1205
|
+
return false;
|
|
1206
|
+
if (!totalUsage || typeof totalUsage !== "object")
|
|
1207
|
+
return true;
|
|
1220
1208
|
const hasTokenField = [
|
|
1221
1209
|
"prompt_tokens",
|
|
1222
1210
|
"completion_tokens",
|
|
@@ -1240,69 +1228,64 @@ function buildEmptyCompletionRepairBody(body) {
|
|
|
1240
1228
|
function buildRequestBodyWithTools(bodyData, agentConfig, disableToolsForThisRequest) {
|
|
1241
1229
|
const messagesForBody = Array.isArray(bodyData?.messages) ? sanitizeOutboundMessages(bodyData.messages) : bodyData?.messages;
|
|
1242
1230
|
const baseBody = messagesForBody !== bodyData?.messages ? { ...bodyData, messages: messagesForBody } : bodyData;
|
|
1243
|
-
if (disableToolsForThisRequest)
|
|
1231
|
+
if (disableToolsForThisRequest)
|
|
1232
|
+
return baseBody;
|
|
1244
1233
|
const modelInfo = getModelInfo(agentConfig.model);
|
|
1245
1234
|
if (modelInfo?.hasImageOutput) {
|
|
1246
1235
|
return baseBody;
|
|
1247
1236
|
}
|
|
1248
1237
|
const rawTools = agentConfig.tools;
|
|
1249
|
-
if (!Array.isArray(rawTools) || rawTools.length === 0)
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
);
|
|
1238
|
+
if (!Array.isArray(rawTools) || rawTools.length === 0)
|
|
1239
|
+
return baseBody;
|
|
1240
|
+
const hasExplicitImageTool = rawTools.some((toolName) => typeof toolName === "string" && EXPLICIT_IMAGE_TOOL_NAMES.has(toolName));
|
|
1253
1241
|
if (supportsImageGeneration(agentConfig) && !hasExplicitImageTool) {
|
|
1254
1242
|
return baseBody;
|
|
1255
1243
|
}
|
|
1256
1244
|
const tools = prepareTools(rawTools, { provider: agentConfig.provider });
|
|
1257
|
-
if (!tools.length)
|
|
1245
|
+
if (!tools.length)
|
|
1246
|
+
return baseBody;
|
|
1258
1247
|
return { ...baseBody, tools, tool_choice: baseBody.tool_choice ?? "auto" };
|
|
1259
1248
|
}
|
|
1260
1249
|
async function finalizeStream(state, ctx) {
|
|
1261
|
-
if (state.hasHandedOff || state.alreadyFinalized)
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
"saving"
|
|
1265
|
-
);
|
|
1250
|
+
if (state.hasHandedOff || state.alreadyFinalized)
|
|
1251
|
+
return state;
|
|
1252
|
+
const savingMetadata = withImageGenerationStage(ctx.messageMetadata, "saving");
|
|
1266
1253
|
if (savingMetadata && shouldShowImageSavingState(state.contentBuffer)) {
|
|
1267
|
-
ctx.dispatch(
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
})
|
|
1280
|
-
);
|
|
1254
|
+
ctx.dispatch(messageStreaming({
|
|
1255
|
+
id: ctx.messageId,
|
|
1256
|
+
dialogId: ctx.dialogId,
|
|
1257
|
+
dbKey: ctx.msgKey,
|
|
1258
|
+
content: "",
|
|
1259
|
+
thinkContent: state.reasoningBuffer,
|
|
1260
|
+
role: "assistant",
|
|
1261
|
+
agentKey: ctx.agentConfig.dbKey,
|
|
1262
|
+
cybotKey: ctx.agentConfig.dbKey,
|
|
1263
|
+
...asOptionalTrimmedString(ctx.agentConfig?.name) ? { agentName: asOptionalTrimmedString(ctx.agentConfig?.name) } : {},
|
|
1264
|
+
...savingMetadata ?? {}
|
|
1265
|
+
}));
|
|
1281
1266
|
ctx.messageMetadata = savingMetadata;
|
|
1282
1267
|
}
|
|
1283
|
-
await ctx.dispatch(
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
})
|
|
1299
|
-
);
|
|
1268
|
+
await ctx.dispatch(messageStreamEnd({
|
|
1269
|
+
finalContentBuffer: state.contentBuffer,
|
|
1270
|
+
totalUsage: state.totalUsage,
|
|
1271
|
+
msgKey: ctx.msgKey,
|
|
1272
|
+
agentConfig: ctx.agentConfig,
|
|
1273
|
+
dialogId: ctx.dialogId,
|
|
1274
|
+
dialogKey: ctx.dialogKey,
|
|
1275
|
+
messageId: ctx.messageId,
|
|
1276
|
+
reasoningBuffer: state.reasoningBuffer,
|
|
1277
|
+
messageMetadata: ctx.messageMetadata,
|
|
1278
|
+
toolCalls: state.assistantToolCalls,
|
|
1279
|
+
spaceId: ctx.spaceId,
|
|
1280
|
+
billingFailed: state.billingFailed,
|
|
1281
|
+
skipBilling: state.skipBilling
|
|
1282
|
+
}));
|
|
1300
1283
|
return {
|
|
1301
1284
|
...state,
|
|
1302
1285
|
alreadyFinalized: true
|
|
1303
1286
|
};
|
|
1304
1287
|
}
|
|
1305
|
-
var EMPTY_UPSTREAM_STREAM_MESSAGE = "
|
|
1288
|
+
var EMPTY_UPSTREAM_STREAM_MESSAGE = "模型返回了空响应,请联系管理员检查服务响应。";
|
|
1306
1289
|
function markEmptyCompletionAsError(state, ctx) {
|
|
1307
1290
|
const producedNothing = state.contentBuffer.length === 0 && !state.reasoningBuffer.trim() && (state.assistantToolCalls?.length ?? 0) === 0;
|
|
1308
1291
|
if (!producedNothing || state.hasHandedOff || state.alreadyFinalized) {
|
|
@@ -1311,10 +1294,7 @@ function markEmptyCompletionAsError(state, ctx) {
|
|
|
1311
1294
|
markStreamMessageAborted(ctx, EMPTY_UPSTREAM_STREAM_MESSAGE);
|
|
1312
1295
|
return {
|
|
1313
1296
|
...state,
|
|
1314
|
-
contentBuffer: appendTextChunk(
|
|
1315
|
-
state.contentBuffer,
|
|
1316
|
-
`[\u9519\u8BEF: ${EMPTY_UPSTREAM_STREAM_MESSAGE}]`
|
|
1317
|
-
),
|
|
1297
|
+
contentBuffer: appendTextChunk(state.contentBuffer, `[错误: ${EMPTY_UPSTREAM_STREAM_MESSAGE}]`),
|
|
1318
1298
|
billingFailed: true
|
|
1319
1299
|
};
|
|
1320
1300
|
}
|
|
@@ -1338,7 +1318,8 @@ function markStreamMessageAborted(ctx, errorMessage, classification = classifyGe
|
|
|
1338
1318
|
};
|
|
1339
1319
|
}
|
|
1340
1320
|
function applyUsage(state, data) {
|
|
1341
|
-
if (!data.usage)
|
|
1321
|
+
if (!data.usage)
|
|
1322
|
+
return state;
|
|
1342
1323
|
return {
|
|
1343
1324
|
...state,
|
|
1344
1325
|
totalUsage: updateTotalUsage(state.totalUsage, data.usage)
|
|
@@ -1353,15 +1334,12 @@ function applyDelta(state, delta) {
|
|
|
1353
1334
|
hasNewVisibleContent = true;
|
|
1354
1335
|
}
|
|
1355
1336
|
if (Array.isArray(delta.tool_calls) && delta.tool_calls.length > 0) {
|
|
1356
|
-
const accumulated = accumulateToolCallChunks(
|
|
1357
|
-
next.accumulatedToolCalls,
|
|
1358
|
-
delta.tool_calls
|
|
1359
|
-
);
|
|
1337
|
+
const accumulated = accumulateToolCallChunks(next.accumulatedToolCalls, delta.tool_calls);
|
|
1360
1338
|
next = {
|
|
1361
1339
|
...next,
|
|
1362
1340
|
accumulatedToolCalls: accumulated,
|
|
1363
1341
|
assistantToolCalls: accumulated.map((call) => ({
|
|
1364
|
-
...call.thought_signature !==
|
|
1342
|
+
...call.thought_signature !== undefined ? { thought_signature: call.thought_signature } : {},
|
|
1365
1343
|
...call.extra_content ? { extra_content: call.extra_content } : {},
|
|
1366
1344
|
id: call.id,
|
|
1367
1345
|
type: "function",
|
|
@@ -1382,18 +1360,12 @@ function applyDelta(state, delta) {
|
|
|
1382
1360
|
}
|
|
1383
1361
|
const contentChunk = delta.content || "";
|
|
1384
1362
|
if (contentChunk) {
|
|
1385
|
-
const { cleanedContent, state: tcState } = processContentChunkWithToolCallStripping(
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
(name, arguments_) => {
|
|
1389
|
-
next.accumulatedToolCalls = accumulateToolCallChunks(
|
|
1390
|
-
next.accumulatedToolCalls ?? [],
|
|
1391
|
-
[{ index: next.accumulatedToolCalls.length, type: "function", function: { name, arguments: arguments_ } }]
|
|
1392
|
-
);
|
|
1393
|
-
}
|
|
1394
|
-
);
|
|
1363
|
+
const { cleanedContent, state: tcState } = processContentChunkWithToolCallStripping(contentChunk, next.toolCallTextState, (name, arguments_) => {
|
|
1364
|
+
next.accumulatedToolCalls = accumulateToolCallChunks(next.accumulatedToolCalls ?? [], [{ index: next.accumulatedToolCalls.length, type: "function", function: { name, arguments: arguments_ } }]);
|
|
1365
|
+
});
|
|
1395
1366
|
next.toolCallTextState = tcState;
|
|
1396
|
-
if (!cleanedContent)
|
|
1367
|
+
if (!cleanedContent)
|
|
1368
|
+
return { state: next, hasNewVisibleContent };
|
|
1397
1369
|
const parsed = processThinkChunk(cleanedContent, next.thinkState);
|
|
1398
1370
|
next.thinkState = parsed.state;
|
|
1399
1371
|
if (parsed.reasoning) {
|
|
@@ -1411,21 +1383,20 @@ function applyDelta(state, delta) {
|
|
|
1411
1383
|
return { state: next, hasNewVisibleContent };
|
|
1412
1384
|
}
|
|
1413
1385
|
function emitStreamingUpdate(hasNewVisibleContent, state, ctx) {
|
|
1414
|
-
if (!hasNewVisibleContent)
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
);
|
|
1386
|
+
if (!hasNewVisibleContent)
|
|
1387
|
+
return;
|
|
1388
|
+
ctx.dispatch(messageStreaming({
|
|
1389
|
+
id: ctx.messageId,
|
|
1390
|
+
dialogId: ctx.dialogId,
|
|
1391
|
+
dbKey: ctx.msgKey,
|
|
1392
|
+
content: state.contentBuffer,
|
|
1393
|
+
thinkContent: state.reasoningBuffer,
|
|
1394
|
+
role: "assistant",
|
|
1395
|
+
agentKey: ctx.agentConfig.dbKey,
|
|
1396
|
+
cybotKey: ctx.agentConfig.dbKey,
|
|
1397
|
+
...asOptionalTrimmedString(ctx.agentConfig?.name) ? { agentName: asOptionalTrimmedString(ctx.agentConfig?.name) } : {},
|
|
1398
|
+
...ctx.messageMetadata ?? {}
|
|
1399
|
+
}));
|
|
1429
1400
|
}
|
|
1430
1401
|
function createStreamThrottler(emitUpdate, options) {
|
|
1431
1402
|
let pendingState = null;
|
|
@@ -1483,7 +1454,8 @@ function validateAndPartitionToolCalls(state) {
|
|
|
1483
1454
|
const validCalls = [];
|
|
1484
1455
|
const invalidCalls = [];
|
|
1485
1456
|
for (const call of state.accumulatedToolCalls) {
|
|
1486
|
-
if (!call)
|
|
1457
|
+
if (!call)
|
|
1458
|
+
continue;
|
|
1487
1459
|
const argsValid = parseToolCallArguments(call?.function?.arguments).valid;
|
|
1488
1460
|
if (argsValid) {
|
|
1489
1461
|
validCalls.push(call);
|
|
@@ -1502,13 +1474,15 @@ function validateAndPartitionToolCalls(state) {
|
|
|
1502
1474
|
return { validCalls, invalidCalls };
|
|
1503
1475
|
}
|
|
1504
1476
|
function syncAssistantToolCallsAfterSanitize(state, invalidCalls) {
|
|
1505
|
-
if (!invalidCalls.length)
|
|
1506
|
-
|
|
1477
|
+
if (!invalidCalls.length)
|
|
1478
|
+
return state.assistantToolCalls ?? [];
|
|
1479
|
+
const invalidById = new Map;
|
|
1507
1480
|
for (const call of invalidCalls) {
|
|
1508
|
-
if (call?.id)
|
|
1481
|
+
if (call?.id)
|
|
1482
|
+
invalidById.set(call.id, call);
|
|
1509
1483
|
}
|
|
1510
1484
|
const base = Array.isArray(state.assistantToolCalls) ? state.assistantToolCalls : state.accumulatedToolCalls.map((call) => ({
|
|
1511
|
-
...call.thought_signature !==
|
|
1485
|
+
...call.thought_signature !== undefined ? { thought_signature: call.thought_signature } : {},
|
|
1512
1486
|
...call.extra_content ? { extra_content: call.extra_content } : {},
|
|
1513
1487
|
id: call.id,
|
|
1514
1488
|
type: "function",
|
|
@@ -1518,9 +1492,11 @@ function syncAssistantToolCallsAfterSanitize(state, invalidCalls) {
|
|
|
1518
1492
|
}
|
|
1519
1493
|
}));
|
|
1520
1494
|
return base.map((call) => {
|
|
1521
|
-
if (!call?.id)
|
|
1495
|
+
if (!call?.id)
|
|
1496
|
+
return call;
|
|
1522
1497
|
const invalid = invalidById.get(call.id);
|
|
1523
|
-
if (!invalid)
|
|
1498
|
+
if (!invalid)
|
|
1499
|
+
return call;
|
|
1524
1500
|
return {
|
|
1525
1501
|
...call,
|
|
1526
1502
|
type: "function",
|
|
@@ -1532,12 +1508,12 @@ function syncAssistantToolCallsAfterSanitize(state, invalidCalls) {
|
|
|
1532
1508
|
});
|
|
1533
1509
|
}
|
|
1534
1510
|
async function persistInvalidToolCallResults(invalidCalls, ctx, startIndex) {
|
|
1535
|
-
for (let i = 0;
|
|
1511
|
+
for (let i = 0;i < invalidCalls.length; i++) {
|
|
1536
1512
|
const call = invalidCalls[i];
|
|
1537
1513
|
const callId = call?.id || `call_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
1538
1514
|
const toolIndex = startIndex + i;
|
|
1539
1515
|
const runningToolMessageId = `${ctx.messageId}-t${String(toolIndex).padStart(3, "0")}`;
|
|
1540
|
-
const runningToolDbKey =
|
|
1516
|
+
const runningToolDbKey = dialogMessageKey2(ctx.dialogId, runningToolMessageId);
|
|
1541
1517
|
const toolName = call?.function?.name || "unknown";
|
|
1542
1518
|
const selfHealContent = buildInvalidToolCallSelfHealResult(callId, toolName);
|
|
1543
1519
|
const toolMessage = {
|
|
@@ -1559,10 +1535,10 @@ async function persistInvalidToolCallResults(invalidCalls, ctx, startIndex) {
|
|
|
1559
1535
|
rawToolCall: call,
|
|
1560
1536
|
error: {
|
|
1561
1537
|
type: "InvalidToolCallArguments",
|
|
1562
|
-
message: "
|
|
1538
|
+
message: "工具参数 JSON 被截断或非法,已跳过执行并替换为占位 arguments。",
|
|
1563
1539
|
retryable: true
|
|
1564
1540
|
},
|
|
1565
|
-
summary:
|
|
1541
|
+
summary: `❌ ${toolName} 参数被截断,已跳过`
|
|
1566
1542
|
}
|
|
1567
1543
|
};
|
|
1568
1544
|
ctx.dispatch(addToolMessage(toolMessage));
|
|
@@ -1581,19 +1557,12 @@ async function processAccumulatedToolCalls(state, ctx) {
|
|
|
1581
1557
|
};
|
|
1582
1558
|
}
|
|
1583
1559
|
const { validCalls, invalidCalls } = validateAndPartitionToolCalls(state);
|
|
1584
|
-
const sanitizedAssistantToolCalls = syncAssistantToolCallsAfterSanitize(
|
|
1585
|
-
state,
|
|
1586
|
-
invalidCalls
|
|
1587
|
-
);
|
|
1560
|
+
const sanitizedAssistantToolCalls = syncAssistantToolCallsAfterSanitize(state, invalidCalls);
|
|
1588
1561
|
if (invalidCalls.length > 0) {
|
|
1589
|
-
await persistInvalidToolCallResults(
|
|
1590
|
-
invalidCalls,
|
|
1591
|
-
ctx,
|
|
1592
|
-
validCalls.length
|
|
1593
|
-
);
|
|
1562
|
+
await persistInvalidToolCallResults(invalidCalls, ctx, validCalls.length);
|
|
1594
1563
|
}
|
|
1595
1564
|
if (!validCalls.length) {
|
|
1596
|
-
const
|
|
1565
|
+
const nextState = {
|
|
1597
1566
|
...state,
|
|
1598
1567
|
accumulatedToolCalls: [],
|
|
1599
1568
|
assistantToolCalls: sanitizedAssistantToolCalls,
|
|
@@ -1601,24 +1570,22 @@ async function processAccumulatedToolCalls(state, ctx) {
|
|
|
1601
1570
|
hasHandedOff: false
|
|
1602
1571
|
};
|
|
1603
1572
|
return {
|
|
1604
|
-
state:
|
|
1573
|
+
state: nextState,
|
|
1605
1574
|
hasHandedOff: false,
|
|
1606
1575
|
hasPendingInteraction: false
|
|
1607
1576
|
};
|
|
1608
1577
|
}
|
|
1609
|
-
const result = await ctx.dispatch(
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
})
|
|
1621
|
-
).unwrap();
|
|
1578
|
+
const result = await ctx.dispatch(handleToolCalls({
|
|
1579
|
+
accumulatedCalls: validCalls,
|
|
1580
|
+
currentContentBuffer: state.contentBuffer,
|
|
1581
|
+
agentConfig: ctx.agentConfig,
|
|
1582
|
+
messageId: ctx.messageId,
|
|
1583
|
+
dialogId: ctx.dialogId,
|
|
1584
|
+
dialogKey: ctx.dialogKey,
|
|
1585
|
+
userMessageId: ctx.userMessageId,
|
|
1586
|
+
serverBase: ctx.serverBase,
|
|
1587
|
+
runtimeServers: ctx.runtimeServers
|
|
1588
|
+
})).unwrap();
|
|
1622
1589
|
const nextState = {
|
|
1623
1590
|
...state,
|
|
1624
1591
|
contentBuffer: result.finalContentBuffer,
|
|
@@ -1637,21 +1604,15 @@ async function readStreamChunkWithTimeout(reader, signal) {
|
|
|
1637
1604
|
return readStreamChunk(reader, {
|
|
1638
1605
|
signal,
|
|
1639
1606
|
timeoutMs: STREAM_READ_TIMEOUT_MS,
|
|
1640
|
-
timeoutErrorMessage:
|
|
1607
|
+
timeoutErrorMessage: `模型响应流 ${Math.round(STREAM_READ_TIMEOUT_MS / 1000)} 秒内没有返回新内容`
|
|
1641
1608
|
});
|
|
1642
1609
|
}
|
|
1643
1610
|
async function handleStreamCompletion(state, ctx, finalizeCtx) {
|
|
1644
1611
|
let hasHandedOff = false;
|
|
1645
1612
|
let hasPendingInteraction = false;
|
|
1646
|
-
const { residualContent, state: tcFlushState } = flushToolCallTextParserIntoCallback(
|
|
1647
|
-
state.
|
|
1648
|
-
|
|
1649
|
-
state.accumulatedToolCalls = accumulateToolCallChunks(
|
|
1650
|
-
state.accumulatedToolCalls ?? [],
|
|
1651
|
-
[{ index: state.accumulatedToolCalls.length, type: "function", function: { name, arguments: arguments_ } }]
|
|
1652
|
-
);
|
|
1653
|
-
}
|
|
1654
|
-
);
|
|
1613
|
+
const { residualContent, state: tcFlushState } = flushToolCallTextParserIntoCallback(state.toolCallTextState, (name, arguments_) => {
|
|
1614
|
+
state.accumulatedToolCalls = accumulateToolCallChunks(state.accumulatedToolCalls ?? [], [{ index: state.accumulatedToolCalls.length, type: "function", function: { name, arguments: arguments_ } }]);
|
|
1615
|
+
});
|
|
1655
1616
|
state.toolCallTextState = tcFlushState;
|
|
1656
1617
|
const flushed = flushThinkParser(state.thinkState);
|
|
1657
1618
|
state.thinkState = flushed.state;
|
|
@@ -1667,7 +1628,7 @@ async function handleStreamCompletion(state, ctx, finalizeCtx) {
|
|
|
1667
1628
|
}
|
|
1668
1629
|
if (!state.hasProcessedToolCalls && state.accumulatedToolCalls.length > 0) {
|
|
1669
1630
|
if (state.totalUsage && !state.billingFailed) {
|
|
1670
|
-
ctx.dispatch(
|
|
1631
|
+
ctx.dispatch(tokenUsageLiveUpdate2({
|
|
1671
1632
|
input_tokens: state.totalUsage.prompt_tokens ?? state.totalUsage.input_tokens,
|
|
1672
1633
|
output_tokens: state.totalUsage.completion_tokens ?? state.totalUsage.output_tokens,
|
|
1673
1634
|
cost: state.totalUsage.cost,
|
|
@@ -1709,29 +1670,26 @@ var sendOpenAICompletionsRequest = async ({
|
|
|
1709
1670
|
}) => {
|
|
1710
1671
|
const { dispatch, getState, signal: thunkSignal } = thunkApi;
|
|
1711
1672
|
const dialogId = splitDialogKeyIdentity(dialogKey)?.dialogId ?? extractCustomId(dialogKey);
|
|
1712
|
-
const controller = new AbortController
|
|
1673
|
+
const controller = new AbortController;
|
|
1713
1674
|
thunkSignal.addEventListener("abort", () => controller.abort());
|
|
1714
1675
|
const signal = controller.signal;
|
|
1715
|
-
const streamSpaceId = getCurrentSpaceId() ||
|
|
1676
|
+
const streamSpaceId = getCurrentSpaceId() || undefined;
|
|
1716
1677
|
let messageId;
|
|
1717
1678
|
let msgKey;
|
|
1718
1679
|
if (parentMessageId) {
|
|
1719
1680
|
messageId = parentMessageId;
|
|
1720
1681
|
msgKey = `msg:${dialogId}:${messageId}`;
|
|
1721
1682
|
} else {
|
|
1722
|
-
const newIds =
|
|
1683
|
+
const newIds = createDialogMessageKeyAndId2(dialogId);
|
|
1723
1684
|
messageId = newIds.messageId;
|
|
1724
1685
|
msgKey = newIds.key;
|
|
1725
1686
|
}
|
|
1726
|
-
dispatch(
|
|
1727
|
-
const requestBody = await inlineImageUrlsForCustomProvider(
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
signal
|
|
1733
|
-
}
|
|
1734
|
-
);
|
|
1687
|
+
dispatch(addActiveController2({ messageId, controller, dialogKey }));
|
|
1688
|
+
const requestBody = await inlineImageUrlsForCustomProvider(buildFinalCompletionsRequestBody(bodyData, agentConfig, disableToolsForThisRequest), {
|
|
1689
|
+
shouldInline: shouldInlineImageUrlsForAgent(agentConfig),
|
|
1690
|
+
serverUrl: getRequestConfig2(thunkApi).currentServer,
|
|
1691
|
+
signal
|
|
1692
|
+
});
|
|
1735
1693
|
let streamState = createInitialStreamState();
|
|
1736
1694
|
let parseSSE = createSSEParser();
|
|
1737
1695
|
let reader;
|
|
@@ -1766,7 +1724,7 @@ var sendOpenAICompletionsRequest = async ({
|
|
|
1766
1724
|
hasHandedOff: hasHandedOffOverall,
|
|
1767
1725
|
finishReason: lastFinishReason,
|
|
1768
1726
|
messageId,
|
|
1769
|
-
usage: streamState.totalUsage ??
|
|
1727
|
+
usage: streamState.totalUsage ?? undefined,
|
|
1770
1728
|
billingFailed: streamState.billingFailed
|
|
1771
1729
|
});
|
|
1772
1730
|
const diagnosticSink = resolveOutboundDiagnosticSink(outboundDiagnostics);
|
|
@@ -1777,39 +1735,37 @@ var sendOpenAICompletionsRequest = async ({
|
|
|
1777
1735
|
let diagnosticCurrentAttempt = 0;
|
|
1778
1736
|
let diagnosticCurrentAttemptClosed = false;
|
|
1779
1737
|
const beginDiagnosticAttempt = (attemptBody) => {
|
|
1780
|
-
if (!diagnosticCall)
|
|
1738
|
+
if (!diagnosticCall)
|
|
1739
|
+
return 0;
|
|
1781
1740
|
diagnosticAttemptCount += 1;
|
|
1782
1741
|
diagnosticCurrentAttempt = diagnosticAttemptCount;
|
|
1783
1742
|
diagnosticCurrentAttemptClosed = false;
|
|
1784
1743
|
diagnosticStreamStarted = false;
|
|
1785
1744
|
diagnosticOutcome = "completed";
|
|
1786
|
-
diagnosticCall.dispatch(
|
|
1787
|
-
diagnosticCurrentAttempt,
|
|
1788
|
-
deriveRequestFactsFromBody(attemptBody)
|
|
1789
|
-
);
|
|
1745
|
+
diagnosticCall.dispatch(diagnosticCurrentAttempt, deriveRequestFactsFromBody(attemptBody));
|
|
1790
1746
|
return diagnosticCurrentAttempt;
|
|
1791
1747
|
};
|
|
1792
1748
|
const closeDiagnosticAttempt = (attempt, outcome) => {
|
|
1793
|
-
if (!diagnosticCall || attempt <= 0)
|
|
1749
|
+
if (!diagnosticCall || attempt <= 0)
|
|
1750
|
+
return;
|
|
1794
1751
|
diagnosticCall.terminal(attempt, outcome);
|
|
1795
|
-
if (attempt === diagnosticCurrentAttempt)
|
|
1752
|
+
if (attempt === diagnosticCurrentAttempt)
|
|
1753
|
+
diagnosticCurrentAttemptClosed = true;
|
|
1796
1754
|
};
|
|
1797
1755
|
try {
|
|
1798
1756
|
if (!parentMessageId) {
|
|
1799
|
-
dispatch(
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
})
|
|
1812
|
-
);
|
|
1757
|
+
dispatch(messageStreaming({
|
|
1758
|
+
id: messageId,
|
|
1759
|
+
dialogId,
|
|
1760
|
+
dbKey: msgKey,
|
|
1761
|
+
content: "",
|
|
1762
|
+
role: "assistant",
|
|
1763
|
+
agentKey: agentConfig.dbKey,
|
|
1764
|
+
cybotKey: agentConfig.dbKey,
|
|
1765
|
+
...asOptionalTrimmedString(agentConfig?.name) ? { agentName: asOptionalTrimmedString(agentConfig?.name) } : {},
|
|
1766
|
+
...activeMessageMetadata ?? {},
|
|
1767
|
+
isStreaming: true
|
|
1768
|
+
}));
|
|
1813
1769
|
}
|
|
1814
1770
|
const api = getApiEndpoint(agentConfig);
|
|
1815
1771
|
diagnosticCall = diagnosticSink ? createOutboundDiagnosticCall({
|
|
@@ -1820,7 +1776,7 @@ var sendOpenAICompletionsRequest = async ({
|
|
|
1820
1776
|
provider: agentConfig?.provider,
|
|
1821
1777
|
model: agentConfig?.model,
|
|
1822
1778
|
callId: outboundDiagnostics?.callId
|
|
1823
|
-
}) :
|
|
1779
|
+
}) : undefined;
|
|
1824
1780
|
if (diagnosticCall) {
|
|
1825
1781
|
beginDiagnosticAttempt(requestBody);
|
|
1826
1782
|
}
|
|
@@ -1833,25 +1789,23 @@ var sendOpenAICompletionsRequest = async ({
|
|
|
1833
1789
|
agentConfig,
|
|
1834
1790
|
api,
|
|
1835
1791
|
bodyData: requestBody,
|
|
1836
|
-
currentServer:
|
|
1792
|
+
currentServer: getRequestConfig2(thunkApi).currentServer,
|
|
1837
1793
|
signal,
|
|
1838
1794
|
token,
|
|
1839
1795
|
dialogId,
|
|
1840
1796
|
onRetry: (info) => {
|
|
1841
|
-
dispatch(
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
})
|
|
1854
|
-
);
|
|
1797
|
+
dispatch(messageStreaming({
|
|
1798
|
+
id: messageId,
|
|
1799
|
+
dialogId,
|
|
1800
|
+
dbKey: msgKey,
|
|
1801
|
+
content: "",
|
|
1802
|
+
role: "assistant",
|
|
1803
|
+
agentKey: agentConfig.dbKey,
|
|
1804
|
+
cybotKey: agentConfig.dbKey,
|
|
1805
|
+
...activeMessageMetadata ?? {},
|
|
1806
|
+
isStreaming: true,
|
|
1807
|
+
retryProgress: info
|
|
1808
|
+
}));
|
|
1855
1809
|
}
|
|
1856
1810
|
});
|
|
1857
1811
|
logQuickChatPerfStage(quickChatPerfStartedAt, "openai-completions-fetch-response", {
|
|
@@ -1859,26 +1813,21 @@ var sendOpenAICompletionsRequest = async ({
|
|
|
1859
1813
|
status: response.status,
|
|
1860
1814
|
dialogKey
|
|
1861
1815
|
});
|
|
1862
|
-
activeMessageMetadata = withImageGenerationStage(
|
|
1863
|
-
activeMessageMetadata,
|
|
1864
|
-
"generating"
|
|
1865
|
-
);
|
|
1816
|
+
activeMessageMetadata = withImageGenerationStage(activeMessageMetadata, "generating");
|
|
1866
1817
|
finalizeCtx.messageMetadata = activeMessageMetadata;
|
|
1867
1818
|
if (!parentMessageId && activeMessageMetadata?.imageGenerationState) {
|
|
1868
|
-
dispatch(
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
})
|
|
1881
|
-
);
|
|
1819
|
+
dispatch(messageStreaming({
|
|
1820
|
+
id: messageId,
|
|
1821
|
+
dialogId,
|
|
1822
|
+
dbKey: msgKey,
|
|
1823
|
+
content: "",
|
|
1824
|
+
role: "assistant",
|
|
1825
|
+
agentKey: agentConfig.dbKey,
|
|
1826
|
+
cybotKey: agentConfig.dbKey,
|
|
1827
|
+
...asOptionalTrimmedString(agentConfig?.name) ? { agentName: asOptionalTrimmedString(agentConfig?.name) } : {},
|
|
1828
|
+
...activeMessageMetadata ?? {},
|
|
1829
|
+
isStreaming: true
|
|
1830
|
+
}));
|
|
1882
1831
|
}
|
|
1883
1832
|
if (!response.ok) {
|
|
1884
1833
|
const rawBody = await response.text();
|
|
@@ -1895,7 +1844,7 @@ var sendOpenAICompletionsRequest = async ({
|
|
|
1895
1844
|
errorCategory: classifyOutboundErrorCategory(response.status, rawBody)
|
|
1896
1845
|
});
|
|
1897
1846
|
const errorJson = errorData?.error ?? errorData;
|
|
1898
|
-
const apiErrorMessage = errorJson?.message || errorJson?.msg || (typeof rawBody === "string" ? rawBody : "") ||
|
|
1847
|
+
const apiErrorMessage = errorJson?.message || errorJson?.msg || (typeof rawBody === "string" ? rawBody : "") || `状态码 ${response.status} ${response.statusText}`;
|
|
1899
1848
|
const apiErrorCode = errorJson?.code || `E${response.status}`;
|
|
1900
1849
|
const legacyClassified = classifyApiError({
|
|
1901
1850
|
status: response.status,
|
|
@@ -1924,10 +1873,7 @@ var sendOpenAICompletionsRequest = async ({
|
|
|
1924
1873
|
markStreamMessageAborted(finalizeCtx, errorMessage, classified);
|
|
1925
1874
|
streamState = {
|
|
1926
1875
|
...streamState,
|
|
1927
|
-
contentBuffer: appendTextChunk(
|
|
1928
|
-
streamState.contentBuffer,
|
|
1929
|
-
`[\u9519\u8BEF: ${errorMessage}]`
|
|
1930
|
-
),
|
|
1876
|
+
contentBuffer: appendTextChunk(streamState.contentBuffer, `[错误: ${errorMessage}]`),
|
|
1931
1877
|
billingFailed: true
|
|
1932
1878
|
};
|
|
1933
1879
|
streamState = await finalizeStream(streamState, finalizeCtx);
|
|
@@ -1945,7 +1891,7 @@ var sendOpenAICompletionsRequest = async ({
|
|
|
1945
1891
|
streamState = await finalizeStream(streamState, finalizeCtx);
|
|
1946
1892
|
return buildMeta();
|
|
1947
1893
|
}
|
|
1948
|
-
let decoder = new TextDecoder
|
|
1894
|
+
let decoder = new TextDecoder;
|
|
1949
1895
|
let loggedFirstStreamChunk = false;
|
|
1950
1896
|
let loggedFirstParsedEvent = false;
|
|
1951
1897
|
let loggedFirstVisibleDelta = false;
|
|
@@ -1963,7 +1909,7 @@ var sendOpenAICompletionsRequest = async ({
|
|
|
1963
1909
|
agentConfig,
|
|
1964
1910
|
api,
|
|
1965
1911
|
bodyData: repairRequestBody,
|
|
1966
|
-
currentServer:
|
|
1912
|
+
currentServer: getRequestConfig2(thunkApi).currentServer,
|
|
1967
1913
|
signal,
|
|
1968
1914
|
token,
|
|
1969
1915
|
dialogId
|
|
@@ -1978,7 +1924,7 @@ var sendOpenAICompletionsRequest = async ({
|
|
|
1978
1924
|
throttler.cancel();
|
|
1979
1925
|
streamState = createInitialStreamState();
|
|
1980
1926
|
parseSSE = createSSEParser();
|
|
1981
|
-
decoder = new TextDecoder
|
|
1927
|
+
decoder = new TextDecoder;
|
|
1982
1928
|
reader = retryResponse.body.getReader();
|
|
1983
1929
|
continue;
|
|
1984
1930
|
}
|
|
@@ -1986,20 +1932,16 @@ var sendOpenAICompletionsRequest = async ({
|
|
|
1986
1932
|
} else if (producedNothing && !signal.aborted && !streamState.hasHandedOff && !streamState.alreadyFinalized) {
|
|
1987
1933
|
diagnosticOutcome = "stream-error";
|
|
1988
1934
|
}
|
|
1989
|
-
const completion = await handleStreamCompletion(
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
runtimeServers: thunkApi.runtimeServers
|
|
2000
|
-
},
|
|
2001
|
-
finalizeCtx
|
|
2002
|
-
);
|
|
1935
|
+
const completion = await handleStreamCompletion(streamState, {
|
|
1936
|
+
dispatch,
|
|
1937
|
+
dialogId,
|
|
1938
|
+
dialogKey: finalizeCtx.dialogKey,
|
|
1939
|
+
messageId,
|
|
1940
|
+
agentConfig,
|
|
1941
|
+
userMessageId,
|
|
1942
|
+
serverBase: thunkApi.serverBase,
|
|
1943
|
+
runtimeServers: thunkApi.runtimeServers
|
|
1944
|
+
}, finalizeCtx);
|
|
2003
1945
|
streamState = completion.state;
|
|
2004
1946
|
hasHandedOffOverall ||= completion.hasHandedOff;
|
|
2005
1947
|
hasPendingInteractionOverall ||= completion.hasPendingInteraction;
|
|
@@ -2007,21 +1949,13 @@ var sendOpenAICompletionsRequest = async ({
|
|
|
2007
1949
|
}
|
|
2008
1950
|
if (!loggedFirstStreamChunk) {
|
|
2009
1951
|
loggedFirstStreamChunk = true;
|
|
2010
|
-
logQuickChatPerfStage(
|
|
2011
|
-
quickChatPerfStartedAt,
|
|
2012
|
-
"openai-completions-first-stream-chunk",
|
|
2013
|
-
{ dialogKey, byteLength: value.byteLength }
|
|
2014
|
-
);
|
|
1952
|
+
logQuickChatPerfStage(quickChatPerfStartedAt, "openai-completions-first-stream-chunk", { dialogKey, byteLength: value.byteLength });
|
|
2015
1953
|
}
|
|
2016
1954
|
const chunk = decoder.decode(value, { stream: true });
|
|
2017
1955
|
const parsedResults = parseSSE(chunk);
|
|
2018
1956
|
if (parsedResults.length > 0 && !loggedFirstParsedEvent) {
|
|
2019
1957
|
loggedFirstParsedEvent = true;
|
|
2020
|
-
logQuickChatPerfStage(
|
|
2021
|
-
quickChatPerfStartedAt,
|
|
2022
|
-
"openai-completions-first-sse-event",
|
|
2023
|
-
{ dialogKey, eventCount: parsedResults.length }
|
|
2024
|
-
);
|
|
1958
|
+
logQuickChatPerfStage(quickChatPerfStartedAt, "openai-completions-first-sse-event", { dialogKey, eventCount: parsedResults.length });
|
|
2025
1959
|
}
|
|
2026
1960
|
for (const parsedData of parsedResults) {
|
|
2027
1961
|
const dataList = Array.isArray(parsedData) ? parsedData : [parsedData];
|
|
@@ -2038,31 +1972,22 @@ var sendOpenAICompletionsRequest = async ({
|
|
|
2038
1972
|
const errorMsg = classified.message;
|
|
2039
1973
|
streamState = {
|
|
2040
1974
|
...streamState,
|
|
2041
|
-
contentBuffer: appendTextChunk(
|
|
2042
|
-
|
|
2043
|
-
`
|
|
2044
|
-
[API Error] ${errorMsg}`
|
|
2045
|
-
),
|
|
1975
|
+
contentBuffer: appendTextChunk(streamState.contentBuffer, `
|
|
1976
|
+
[API Error] ${errorMsg}`),
|
|
2046
1977
|
billingFailed: true
|
|
2047
1978
|
};
|
|
2048
1979
|
await reader.cancel();
|
|
2049
1980
|
break;
|
|
2050
1981
|
}
|
|
2051
1982
|
const choice = data.choices?.[0];
|
|
2052
|
-
if (!choice)
|
|
1983
|
+
if (!choice)
|
|
1984
|
+
continue;
|
|
2053
1985
|
const delta = choice.delta || {};
|
|
2054
|
-
const { state: updatedState, hasNewVisibleContent } = applyDelta(
|
|
2055
|
-
streamState,
|
|
2056
|
-
delta
|
|
2057
|
-
);
|
|
1986
|
+
const { state: updatedState, hasNewVisibleContent } = applyDelta(streamState, delta);
|
|
2058
1987
|
streamState = updatedState;
|
|
2059
1988
|
if (hasNewVisibleContent && !loggedFirstVisibleDelta) {
|
|
2060
1989
|
loggedFirstVisibleDelta = true;
|
|
2061
|
-
logQuickChatPerfStage(
|
|
2062
|
-
quickChatPerfStartedAt,
|
|
2063
|
-
"openai-completions-first-visible-delta",
|
|
2064
|
-
{ dialogKey }
|
|
2065
|
-
);
|
|
1990
|
+
logQuickChatPerfStage(quickChatPerfStartedAt, "openai-completions-first-visible-delta", { dialogKey });
|
|
2066
1991
|
}
|
|
2067
1992
|
if (hasNewVisibleContent) {
|
|
2068
1993
|
throttler.push(streamState);
|
|
@@ -2079,29 +2004,21 @@ var sendOpenAICompletionsRequest = async ({
|
|
|
2079
2004
|
} else if (finishReason !== "stop") {
|
|
2080
2005
|
if (finishReason === "error") {
|
|
2081
2006
|
const finishErrorMessage = getChoiceFinishErrorMessage(data, choice);
|
|
2082
|
-
const errorText = finishErrorMessage ? `[API Error] Error: ${finishErrorMessage}` : "[API Error] Error:
|
|
2083
|
-
const classified = classifyGenerationError(
|
|
2084
|
-
choice.error ? choice : data.error ? data : { code: "UPSTREAM_FINISH_ERROR" }
|
|
2085
|
-
);
|
|
2007
|
+
const errorText = finishErrorMessage ? `[API Error] Error: ${finishErrorMessage}` : "[API Error] Error: 模型响应以 error 结束,但上游未返回具体错误。请重试,或切换到其他支持图片输入的模型。";
|
|
2008
|
+
const classified = classifyGenerationError(choice.error ? choice : data.error ? data : { code: "UPSTREAM_FINISH_ERROR" });
|
|
2086
2009
|
markStreamMessageAborted(finalizeCtx, errorText, classified);
|
|
2087
2010
|
diagnosticOutcome = "stream-error";
|
|
2088
2011
|
streamState = {
|
|
2089
2012
|
...streamState,
|
|
2090
|
-
contentBuffer: appendTextChunk(
|
|
2091
|
-
|
|
2092
|
-
`
|
|
2093
|
-
${errorText}`
|
|
2094
|
-
),
|
|
2013
|
+
contentBuffer: appendTextChunk(streamState.contentBuffer, `
|
|
2014
|
+
${errorText}`),
|
|
2095
2015
|
billingFailed: true
|
|
2096
2016
|
};
|
|
2097
2017
|
} else {
|
|
2098
2018
|
streamState = {
|
|
2099
2019
|
...streamState,
|
|
2100
|
-
contentBuffer: appendTextChunk(
|
|
2101
|
-
|
|
2102
|
-
`
|
|
2103
|
-
[\u6D41\u7ED3\u675F\u539F\u56E0: ${finishReason}]`
|
|
2104
|
-
)
|
|
2020
|
+
contentBuffer: appendTextChunk(streamState.contentBuffer, `
|
|
2021
|
+
[流结束原因: ${finishReason}]`)
|
|
2105
2022
|
};
|
|
2106
2023
|
}
|
|
2107
2024
|
}
|
|
@@ -2116,10 +2033,11 @@ ${errorText}`
|
|
|
2116
2033
|
diagnosticOutcome = isAbort ? "aborted" : diagnosticStreamStarted ? "stream-error" : "network-error";
|
|
2117
2034
|
const skipBilling = shouldSkipBillingForUserAbort(error, streamState.totalUsage);
|
|
2118
2035
|
if (isAbort) {
|
|
2119
|
-
errorText =
|
|
2036
|
+
errorText = `
|
|
2037
|
+
[用户中断]`;
|
|
2120
2038
|
} else {
|
|
2121
2039
|
errorText = `
|
|
2122
|
-
[
|
|
2040
|
+
[错误: ${classifyGenerationError(toErrorMessage(error)).message}]`;
|
|
2123
2041
|
}
|
|
2124
2042
|
console.error("[SSE] sendOpenAICompletionsRequest error:", error);
|
|
2125
2043
|
streamState = {
|
|
@@ -2129,11 +2047,7 @@ ${errorText}`
|
|
|
2129
2047
|
skipBilling: streamState.skipBilling || skipBilling
|
|
2130
2048
|
};
|
|
2131
2049
|
if (!isAbort) {
|
|
2132
|
-
markStreamMessageAborted(
|
|
2133
|
-
finalizeCtx,
|
|
2134
|
-
classifyGenerationError(toErrorMessage(error)).message,
|
|
2135
|
-
classifyGenerationError(toErrorMessage(error))
|
|
2136
|
-
);
|
|
2050
|
+
markStreamMessageAborted(finalizeCtx, classifyGenerationError(toErrorMessage(error)).message, classifyGenerationError(toErrorMessage(error)));
|
|
2137
2051
|
}
|
|
2138
2052
|
streamState = await finalizeStream(streamState, finalizeCtx);
|
|
2139
2053
|
} finally {
|
|
@@ -2141,11 +2055,10 @@ ${errorText}`
|
|
|
2141
2055
|
logQuickChatPerfStage(quickChatPerfStartedAt, "openai-completions-stream-finished", {
|
|
2142
2056
|
dialogKey
|
|
2143
2057
|
});
|
|
2144
|
-
dispatch(
|
|
2058
|
+
dispatch(removeActiveController2({ messageId, dialogKey }));
|
|
2145
2059
|
try {
|
|
2146
2060
|
await reader?.cancel();
|
|
2147
|
-
} catch (_e) {
|
|
2148
|
-
}
|
|
2061
|
+
} catch (_e) {}
|
|
2149
2062
|
if (diagnosticCall && diagnosticCurrentAttempt > 0 && !diagnosticCurrentAttemptClosed) {
|
|
2150
2063
|
closeDiagnosticAttempt(diagnosticCurrentAttempt, diagnosticOutcome);
|
|
2151
2064
|
}
|
|
@@ -2153,15 +2066,4 @@ ${errorText}`
|
|
|
2153
2066
|
return buildMeta();
|
|
2154
2067
|
};
|
|
2155
2068
|
|
|
2156
|
-
export {
|
|
2157
|
-
serializeAgentRunMessages,
|
|
2158
|
-
filterAndCleanMessages,
|
|
2159
|
-
persistToolMessages,
|
|
2160
|
-
deliverHtmlArtifactToolResult,
|
|
2161
|
-
handleToolCalls,
|
|
2162
|
-
updateTotalUsage,
|
|
2163
|
-
readStreamChunk,
|
|
2164
|
-
buildFinalCompletionsRequestBody,
|
|
2165
|
-
buildEmptyCompletionRepairBody,
|
|
2166
|
-
sendOpenAICompletionsRequest
|
|
2167
|
-
};
|
|
2069
|
+
export { serializeAgentRunMessages, filterAndCleanMessages, persistToolMessages, deliverHtmlArtifactToolResult, handleToolCalls, updateTotalUsage, readStreamChunk, buildFinalCompletionsRequestBody, buildEmptyCompletionRepairBody, sendOpenAICompletionsRequest };
|