@zyycn/claudex 1.0.3-fork.2a74621
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/LICENSE.md +5 -0
- package/README.md +489 -0
- package/bin/claudex.js +40 -0
- package/dist/chunk-00xcm9ma.js +21933 -0
- package/dist/chunk-0503mmvy.js +153 -0
- package/dist/chunk-06saje2v.js +39 -0
- package/dist/chunk-0731m51q.js +8 -0
- package/dist/chunk-0htr6ryz.js +208 -0
- package/dist/chunk-0hw5q246.js +59 -0
- package/dist/chunk-0na45fm9.js +93 -0
- package/dist/chunk-0paqc2yw.js +15 -0
- package/dist/chunk-0q2xkmse.js +58 -0
- package/dist/chunk-0rvxx6st.js +195 -0
- package/dist/chunk-0vkfrmqm.js +690 -0
- package/dist/chunk-0xjaqda8.js +1124 -0
- package/dist/chunk-0xpb84zw.js +105 -0
- package/dist/chunk-1141xmr4.js +8 -0
- package/dist/chunk-14jv3jm7.js +17 -0
- package/dist/chunk-19vtvtzg.js +496 -0
- package/dist/chunk-1cbn5kxf.js +7 -0
- package/dist/chunk-1gj0rhkf.js +92 -0
- package/dist/chunk-1h2famwb.js +49 -0
- package/dist/chunk-1m68rrvt.js +173649 -0
- package/dist/chunk-1ss7dnmq.js +104 -0
- package/dist/chunk-1v6e40p8.js +160 -0
- package/dist/chunk-1vh98qr0.js +4521 -0
- package/dist/chunk-1xkekb9y.js +19 -0
- package/dist/chunk-1ydzf04y.js +713 -0
- package/dist/chunk-238g70xa.js +36 -0
- package/dist/chunk-27xc1csx.js +104 -0
- package/dist/chunk-297y1tw3.js +789 -0
- package/dist/chunk-2a42s11t.js +412 -0
- package/dist/chunk-2bpfbf16.js +998 -0
- package/dist/chunk-2eykm0j0.js +20 -0
- package/dist/chunk-2fwze72g.js +24 -0
- package/dist/chunk-2ge9kmgv.js +28 -0
- package/dist/chunk-2gzv8nrw.js +205 -0
- package/dist/chunk-2k995y2x.js +880 -0
- package/dist/chunk-2nayx6q1.js +63 -0
- package/dist/chunk-2qk1898r.js +74 -0
- package/dist/chunk-2qp0vrvd.js +83 -0
- package/dist/chunk-2sndq2nq.js +644 -0
- package/dist/chunk-2t1frg13.js +716 -0
- package/dist/chunk-2t3vw4tx.js +22820 -0
- package/dist/chunk-2ybjg7pc.js +432 -0
- package/dist/chunk-302gxdf9.js +161 -0
- package/dist/chunk-30rst83v.js +168 -0
- package/dist/chunk-33mdt86j.js +42 -0
- package/dist/chunk-33pgf56v.js +32 -0
- package/dist/chunk-36k7h1v1.js +372 -0
- package/dist/chunk-36zyyac9.js +41654 -0
- package/dist/chunk-37dbhqqr.js +1920 -0
- package/dist/chunk-37dydh7h.js +642 -0
- package/dist/chunk-38700exh.js +42 -0
- package/dist/chunk-3c25bcsw.js +17 -0
- package/dist/chunk-3h8a89gy.js +46 -0
- package/dist/chunk-3nk79af8.js +8 -0
- package/dist/chunk-3peatsdv.js +41 -0
- package/dist/chunk-3rd46sc5.js +221 -0
- package/dist/chunk-3s498jy8.js +1014 -0
- package/dist/chunk-3vs3nm7w.js +31 -0
- package/dist/chunk-3w6s9m5w.js +16 -0
- package/dist/chunk-3yccyqwm.js +692 -0
- package/dist/chunk-3zjjk0am.js +56 -0
- package/dist/chunk-3zzszjst.js +16415 -0
- package/dist/chunk-41m5za5y.js +154 -0
- package/dist/chunk-44fpr6jq.js +434 -0
- package/dist/chunk-48gwzq50.js +154 -0
- package/dist/chunk-495d85x1.js +8066 -0
- package/dist/chunk-4cse1nz6.js +98 -0
- package/dist/chunk-4f1wn74p.js +106 -0
- package/dist/chunk-4f9taz3j.js +86 -0
- package/dist/chunk-4g3v8y12.js +23 -0
- package/dist/chunk-4hh97qpv.js +765 -0
- package/dist/chunk-4jm600zv.js +13 -0
- package/dist/chunk-4jzv26gg.js +62 -0
- package/dist/chunk-4qgbmcm7.js +9193 -0
- package/dist/chunk-4qz9vbs1.js +349 -0
- package/dist/chunk-4tyttyn2.js +373 -0
- package/dist/chunk-4v0qvahs.js +89 -0
- package/dist/chunk-4zfkzkt6.js +37 -0
- package/dist/chunk-51xw8dbm.js +339 -0
- package/dist/chunk-525vnqc3.js +247 -0
- package/dist/chunk-557wwsxe.js +533 -0
- package/dist/chunk-55hj5hhv.js +84 -0
- package/dist/chunk-55wgxwa9.js +13877 -0
- package/dist/chunk-56jgazae.js +28 -0
- package/dist/chunk-58xxf3tz.js +521 -0
- package/dist/chunk-5c2m9q8v.js +109 -0
- package/dist/chunk-5fpcmgh8.js +348 -0
- package/dist/chunk-5gmd05y0.js +1153 -0
- package/dist/chunk-5gvng4zv.js +122 -0
- package/dist/chunk-5k5a32tj.js +537 -0
- package/dist/chunk-5md3w36r.js +275 -0
- package/dist/chunk-5z1vph5s.js +127 -0
- package/dist/chunk-5z78246t.js +54 -0
- package/dist/chunk-65s8h28p.js +123 -0
- package/dist/chunk-66qbb491.js +90 -0
- package/dist/chunk-693w4qr8.js +300 -0
- package/dist/chunk-6azerawy.js +2335 -0
- package/dist/chunk-6bd8brc4.js +48 -0
- package/dist/chunk-6d8k2crm.js +101 -0
- package/dist/chunk-6dj5t602.js +341 -0
- package/dist/chunk-6em0h8b4.js +88 -0
- package/dist/chunk-6gr3c3w9.js +378 -0
- package/dist/chunk-6gzakvec.js +87 -0
- package/dist/chunk-6hy71770.js +96 -0
- package/dist/chunk-6mtk8975.js +117 -0
- package/dist/chunk-6n2qgm9v.js +8 -0
- package/dist/chunk-6n7gewz2.js +253 -0
- package/dist/chunk-6r1112vx.js +469 -0
- package/dist/chunk-6r9v2rce.js +229 -0
- package/dist/chunk-6tq2v3rk.js +186 -0
- package/dist/chunk-70spdapk.js +79 -0
- package/dist/chunk-73rpbt04.js +1947 -0
- package/dist/chunk-760252na.js +101 -0
- package/dist/chunk-761tmgwx.js +6108 -0
- package/dist/chunk-76dy674m.js +648 -0
- package/dist/chunk-7739pg2c.js +4261 -0
- package/dist/chunk-78cznbzh.js +756 -0
- package/dist/chunk-78vqjj7t.js +1317 -0
- package/dist/chunk-79tame2q.js +280 -0
- package/dist/chunk-7aw745vx.js +40175 -0
- package/dist/chunk-7e6ahfxz.js +61 -0
- package/dist/chunk-7gd593wb.js +438 -0
- package/dist/chunk-7m2nd8da.js +110 -0
- package/dist/chunk-7pqesh1s.js +184 -0
- package/dist/chunk-7q237ftq.js +1585 -0
- package/dist/chunk-7vbxp63m.js +100 -0
- package/dist/chunk-7wm5s02e.js +216 -0
- package/dist/chunk-7xyswgjh.js +8 -0
- package/dist/chunk-7zaxrfnt.js +42 -0
- package/dist/chunk-83hfzbx3.js +10 -0
- package/dist/chunk-8bedvdm1.js +32 -0
- package/dist/chunk-8hq5kk3y.js +44 -0
- package/dist/chunk-8k0y8sk2.js +165 -0
- package/dist/chunk-8pb038eb.js +44 -0
- package/dist/chunk-8smr33wf.js +287 -0
- package/dist/chunk-8tnsngw2.js +31 -0
- package/dist/chunk-8vcz9eks.js +443 -0
- package/dist/chunk-8y12jxg8.js +10 -0
- package/dist/chunk-8ymf4e6z.js +48 -0
- package/dist/chunk-90wp6wez.js +10510 -0
- package/dist/chunk-9f9p2b84.js +848 -0
- package/dist/chunk-9gbamk79.js +93 -0
- package/dist/chunk-9k27xdmg.js +542 -0
- package/dist/chunk-9k2drwej.js +106 -0
- package/dist/chunk-9x5zgy22.js +12 -0
- package/dist/chunk-a5wwqn08.js +725 -0
- package/dist/chunk-a8ejc632.js +3094 -0
- package/dist/chunk-a9nr12c7.js +272 -0
- package/dist/chunk-a9vdeb6y.js +258 -0
- package/dist/chunk-a9zh40sj.js +48 -0
- package/dist/chunk-aberf6bd.js +282 -0
- package/dist/chunk-ada32h8c.js +40 -0
- package/dist/chunk-adg4351g.js +26840 -0
- package/dist/chunk-ae7s1rks.js +93 -0
- package/dist/chunk-agnasrp3.js +128 -0
- package/dist/chunk-akp4x1ve.js +93 -0
- package/dist/chunk-akyzxxs1.js +109 -0
- package/dist/chunk-ar08wx1s.js +468 -0
- package/dist/chunk-ar1vk71q.js +220 -0
- package/dist/chunk-arnhbg3z.js +87 -0
- package/dist/chunk-azk47w50.js +306 -0
- package/dist/chunk-b11e166f.js +173 -0
- package/dist/chunk-b292a9es.js +91 -0
- package/dist/chunk-b4v0varz.js +89 -0
- package/dist/chunk-b4wg70y1.js +54 -0
- package/dist/chunk-b75fzr8e.js +969 -0
- package/dist/chunk-b7cywkg9.js +908 -0
- package/dist/chunk-b80rg7hy.js +565 -0
- package/dist/chunk-b8x1gk3y.js +1299 -0
- package/dist/chunk-b9kme9pv.js +38 -0
- package/dist/chunk-bah68pmm.js +47 -0
- package/dist/chunk-bbxjktbd.js +69 -0
- package/dist/chunk-bc035ncb.js +153 -0
- package/dist/chunk-bedw0ft1.js +198 -0
- package/dist/chunk-bjqw6798.js +328 -0
- package/dist/chunk-bm1qb16p.js +17 -0
- package/dist/chunk-bqfnp99q.js +477 -0
- package/dist/chunk-bvp4dgm4.js +182 -0
- package/dist/chunk-c1k5g6t4.js +115 -0
- package/dist/chunk-c3r27fmp.js +73 -0
- package/dist/chunk-c9xk7hme.js +106 -0
- package/dist/chunk-cd155fv3.js +87 -0
- package/dist/chunk-cdz5yb0r.js +57 -0
- package/dist/chunk-cfv996bs.js +22 -0
- package/dist/chunk-cg606wr4.js +110 -0
- package/dist/chunk-cgfdkzhb.js +12 -0
- package/dist/chunk-chy5zbax.js +701 -0
- package/dist/chunk-ctkn4y2r.js +317 -0
- package/dist/chunk-czensfac.js +476 -0
- package/dist/chunk-d28x64s9.js +38 -0
- package/dist/chunk-d9kz373t.js +122 -0
- package/dist/chunk-dgqrcy74.js +48 -0
- package/dist/chunk-dnh7jtpb.js +37 -0
- package/dist/chunk-dnqqes3z.js +216 -0
- package/dist/chunk-dphmfzrv.js +250 -0
- package/dist/chunk-drzegvt5.js +86 -0
- package/dist/chunk-ds5nkfg0.js +1095 -0
- package/dist/chunk-dsf70j2y.js +1550 -0
- package/dist/chunk-dstxhxsx.js +121 -0
- package/dist/chunk-dv1wfr85.js +6373 -0
- package/dist/chunk-dxfhv5da.js +500 -0
- package/dist/chunk-e5pntxye.js +37 -0
- package/dist/chunk-e6q1y5gb.js +419 -0
- package/dist/chunk-e8bd8nfv.js +697 -0
- package/dist/chunk-e8d2zjs1.js +338 -0
- package/dist/chunk-e9aevcts.js +87 -0
- package/dist/chunk-eebcvtbb.js +1646 -0
- package/dist/chunk-egmp9ajp.js +144 -0
- package/dist/chunk-ehtwnxpg.js +1591 -0
- package/dist/chunk-eqp1rfft.js +17 -0
- package/dist/chunk-ewadzrm8.js +103 -0
- package/dist/chunk-eynjr6k5.js +169 -0
- package/dist/chunk-ezf1ppbj.js +208 -0
- package/dist/chunk-f4407gzr.js +129 -0
- package/dist/chunk-f5ma3nh5.js +3436 -0
- package/dist/chunk-fbpftpf0.js +69 -0
- package/dist/chunk-fbv4apne.js +51 -0
- package/dist/chunk-ffk6brrm.js +386 -0
- package/dist/chunk-fgebtwax.js +1872 -0
- package/dist/chunk-fkcn5zhs.js +40 -0
- package/dist/chunk-fm8gm3cm.js +120 -0
- package/dist/chunk-fw5ev6dp.js +458 -0
- package/dist/chunk-fyc5fepv.js +10 -0
- package/dist/chunk-fzj4am93.js +1493 -0
- package/dist/chunk-g0j0t6qk.js +26 -0
- package/dist/chunk-g338npwr.js +1061 -0
- package/dist/chunk-g3t0act8.js +8 -0
- package/dist/chunk-geyx5ybh.js +375 -0
- package/dist/chunk-gg3j3nv0.js +212 -0
- package/dist/chunk-gmaybtrd.js +726 -0
- package/dist/chunk-gqmkgbfr.js +256 -0
- package/dist/chunk-gv0tqhg0.js +118 -0
- package/dist/chunk-gyj242zr.js +20 -0
- package/dist/chunk-gz457zg6.js +463 -0
- package/dist/chunk-gzaaa3ex.js +166 -0
- package/dist/chunk-gzct9dkr.js +2057 -0
- package/dist/chunk-gzzfhtdv.js +7189 -0
- package/dist/chunk-h0qngp9w.js +157 -0
- package/dist/chunk-h0rbjg6x.js +55 -0
- package/dist/chunk-h4qh9a0e.js +3444 -0
- package/dist/chunk-hakdhagh.js +16606 -0
- package/dist/chunk-hazazgk5.js +3205 -0
- package/dist/chunk-hb7k1x8f.js +745 -0
- package/dist/chunk-hh7cmy4k.js +20 -0
- package/dist/chunk-hj4vr9dm.js +102 -0
- package/dist/chunk-hk90mbpv.js +3418 -0
- package/dist/chunk-hk9xz7gk.js +118 -0
- package/dist/chunk-hmtttwpt.js +132 -0
- package/dist/chunk-hqmz36b3.js +552 -0
- package/dist/chunk-hvm6gcy9.js +584 -0
- package/dist/chunk-hzhe8ygc.js +547 -0
- package/dist/chunk-j2k4p94p.js +55 -0
- package/dist/chunk-j2rbx1ej.js +96 -0
- package/dist/chunk-j3a4p81y.js +184 -0
- package/dist/chunk-j5hc27hv.js +444 -0
- package/dist/chunk-j64ga6ta.js +8035 -0
- package/dist/chunk-j84fcssx.js +54 -0
- package/dist/chunk-jce5r25x.js +18 -0
- package/dist/chunk-jd32zbps.js +15 -0
- package/dist/chunk-jdgeec04.js +4249 -0
- package/dist/chunk-jj0m6fr0.js +247 -0
- package/dist/chunk-jnhkref0.js +30 -0
- package/dist/chunk-jpp9dqv4.js +6956 -0
- package/dist/chunk-jr58a333.js +113 -0
- package/dist/chunk-jx817w05.js +11 -0
- package/dist/chunk-jxnvvps7.js +328 -0
- package/dist/chunk-jzmz18nn.js +65 -0
- package/dist/chunk-k0p9w03v.js +4957 -0
- package/dist/chunk-k2aj61ee.js +27 -0
- package/dist/chunk-kcv00nmk.js +849 -0
- package/dist/chunk-kecf7c6t.js +10476 -0
- package/dist/chunk-kffz0vxg.js +92 -0
- package/dist/chunk-kge53wbt.js +674 -0
- package/dist/chunk-khscb4ge.js +99 -0
- package/dist/chunk-kk4h10r3.js +3058 -0
- package/dist/chunk-kq0n3myz.js +71 -0
- package/dist/chunk-kwekc97v.js +18 -0
- package/dist/chunk-m44gmqd1.js +258 -0
- package/dist/chunk-m4kphr9e.js +71 -0
- package/dist/chunk-mbrkqdrq.js +155 -0
- package/dist/chunk-mt25echc.js +6157 -0
- package/dist/chunk-mvrpg273.js +89 -0
- package/dist/chunk-mzfgg9ne.js +275 -0
- package/dist/chunk-n0qaeaa5.js +256 -0
- package/dist/chunk-n0x2db3y.js +84 -0
- package/dist/chunk-n18sq04t.js +603 -0
- package/dist/chunk-n6qhan3n.js +243 -0
- package/dist/chunk-n7ttdtk0.js +641 -0
- package/dist/chunk-ncxetb9w.js +130 -0
- package/dist/chunk-ne67h2hc.js +277 -0
- package/dist/chunk-nfv508k1.js +306 -0
- package/dist/chunk-nj17bhkh.js +125 -0
- package/dist/chunk-nka1g8f4.js +773 -0
- package/dist/chunk-nma79c3w.js +281 -0
- package/dist/chunk-nq0fxyxh.js +752 -0
- package/dist/chunk-nt837qt9.js +21 -0
- package/dist/chunk-nwsmn6zm.js +15 -0
- package/dist/chunk-nypgx8vs.js +63 -0
- package/dist/chunk-p2816w9z.js +1486 -0
- package/dist/chunk-p2d5nh3g.js +342 -0
- package/dist/chunk-p331ghzg.js +391 -0
- package/dist/chunk-p3g43fdn.js +61 -0
- package/dist/chunk-p87jnvhk.js +97 -0
- package/dist/chunk-pb04jxp7.js +158 -0
- package/dist/chunk-pd6ph5ep.js +176 -0
- package/dist/chunk-pe0s50gj.js +32 -0
- package/dist/chunk-pe6w0anj.js +780 -0
- package/dist/chunk-ph936yc1.js +99 -0
- package/dist/chunk-pmsp9ed2.js +34 -0
- package/dist/chunk-ppwjyveh.js +8 -0
- package/dist/chunk-ps49ymvj.js +43 -0
- package/dist/chunk-pwwa7s62.js +11 -0
- package/dist/chunk-pxv7ggmm.js +1580 -0
- package/dist/chunk-py5y9jh1.js +38 -0
- package/dist/chunk-q0sq5qtt.js +606 -0
- package/dist/chunk-q1mq6fj3.js +118 -0
- package/dist/chunk-q25bjaev.js +15 -0
- package/dist/chunk-q55nn3jr.js +5018 -0
- package/dist/chunk-q6na5mcw.js +268 -0
- package/dist/chunk-q6wc9j6e.js +1556 -0
- package/dist/chunk-q7bxdsfd.js +22 -0
- package/dist/chunk-q82jz4qn.js +2838 -0
- package/dist/chunk-qbt1tq74.js +145 -0
- package/dist/chunk-qfzfjrk3.js +439 -0
- package/dist/chunk-qjg7a3vk.js +246 -0
- package/dist/chunk-qnfx3qtx.js +617 -0
- package/dist/chunk-qp2qdcda.js +100 -0
- package/dist/chunk-qpa4edje.js +95 -0
- package/dist/chunk-qqfa0dqg.js +2343 -0
- package/dist/chunk-qqfvrtr3.js +99 -0
- package/dist/chunk-qrqenkjd.js +140 -0
- package/dist/chunk-qrv8taxy.js +229 -0
- package/dist/chunk-qypqtrgp.js +176 -0
- package/dist/chunk-qywdhw43.js +89 -0
- package/dist/chunk-qz2x630m.js +49145 -0
- package/dist/chunk-r0v9bxma.js +83 -0
- package/dist/chunk-r6b58y3x.js +17 -0
- package/dist/chunk-r9madq2h.js +71 -0
- package/dist/chunk-raqgs410.js +116 -0
- package/dist/chunk-rc28tav4.js +202 -0
- package/dist/chunk-re1t10ba.js +5954 -0
- package/dist/chunk-res15ktd.js +18 -0
- package/dist/chunk-rkb7mqj8.js +603 -0
- package/dist/chunk-rn0v1hk8.js +34 -0
- package/dist/chunk-rrb8682q.js +120 -0
- package/dist/chunk-rs9gw711.js +115 -0
- package/dist/chunk-rtgznsee.js +43 -0
- package/dist/chunk-s2341895.js +24 -0
- package/dist/chunk-s2gr7ese.js +106 -0
- package/dist/chunk-s2t8vg8q.js +26 -0
- package/dist/chunk-s3pzvdss.js +50 -0
- package/dist/chunk-s56m7vrp.js +66 -0
- package/dist/chunk-s5dg9njs.js +826 -0
- package/dist/chunk-s7mpvz9v.js +811 -0
- package/dist/chunk-sbbj6ta3.js +1711 -0
- package/dist/chunk-sd36yzx8.js +954 -0
- package/dist/chunk-sdj9b9wh.js +782 -0
- package/dist/chunk-sdxgmmma.js +224 -0
- package/dist/chunk-sgrc7rmx.js +471 -0
- package/dist/chunk-shb6nvk6.js +27 -0
- package/dist/chunk-smtr0ngp.js +98 -0
- package/dist/chunk-sn55zm52.js +267 -0
- package/dist/chunk-ss4r21gw.js +61 -0
- package/dist/chunk-sv3cz176.js +400 -0
- package/dist/chunk-sy4rdq5h.js +116 -0
- package/dist/chunk-szj5wvdy.js +28 -0
- package/dist/chunk-t0rgmccj.js +39 -0
- package/dist/chunk-t133w5tm.js +298 -0
- package/dist/chunk-t3360k46.js +75 -0
- package/dist/chunk-tdbpneze.js +346 -0
- package/dist/chunk-tjk56vh8.js +81 -0
- package/dist/chunk-tm5bn7aw.js +266 -0
- package/dist/chunk-ts2p6bv1.js +224 -0
- package/dist/chunk-ttk5dzz8.js +25 -0
- package/dist/chunk-v1kzp02e.js +785 -0
- package/dist/chunk-v2fqnqgx.js +163 -0
- package/dist/chunk-v2xpxnmd.js +673 -0
- package/dist/chunk-v78fj8by.js +145 -0
- package/dist/chunk-v90xv5n9.js +157 -0
- package/dist/chunk-v9smspw2.js +4301 -0
- package/dist/chunk-vd3bb2zh.js +173 -0
- package/dist/chunk-vest0y6x.js +3830 -0
- package/dist/chunk-vf5sd1nq.js +12 -0
- package/dist/chunk-vhjx5fag.js +56 -0
- package/dist/chunk-vjf2rt5s.js +751 -0
- package/dist/chunk-vn1e1j7w.js +655 -0
- package/dist/chunk-vqk1n5qr.js +63 -0
- package/dist/chunk-vqvd3qz0.js +151 -0
- package/dist/chunk-vrmgtjyy.js +195 -0
- package/dist/chunk-vyjeh50y.js +2149 -0
- package/dist/chunk-w100pzs6.js +41 -0
- package/dist/chunk-w962tnq8.js +1322 -0
- package/dist/chunk-wae2sy8c.js +225 -0
- package/dist/chunk-wfprv7va.js +192 -0
- package/dist/chunk-wfz0qffj.js +3939 -0
- package/dist/chunk-wgcssf6v.js +722 -0
- package/dist/chunk-wh43g70w.js +40 -0
- package/dist/chunk-whb2mrcf.js +2643 -0
- package/dist/chunk-wn2268qd.js +335 -0
- package/dist/chunk-wq8v0d1k.js +1391 -0
- package/dist/chunk-wrhhmkf7.js +16 -0
- package/dist/chunk-wt69n71b.js +779 -0
- package/dist/chunk-wz2ekprb.js +130 -0
- package/dist/chunk-wzpdet3m.js +843 -0
- package/dist/chunk-x21zmsfa.js +104 -0
- package/dist/chunk-x2h31hmh.js +642 -0
- package/dist/chunk-x2qg3sdd.js +114 -0
- package/dist/chunk-x6r4v44b.js +8 -0
- package/dist/chunk-x7vg43fv.js +79 -0
- package/dist/chunk-x8b7vft8.js +132 -0
- package/dist/chunk-xbtacp2f.js +4389 -0
- package/dist/chunk-xq4cfvpn.js +213 -0
- package/dist/chunk-xqde96jm.js +60 -0
- package/dist/chunk-xsq9ae7x.js +90 -0
- package/dist/chunk-xsx5x369.js +526 -0
- package/dist/chunk-xszk7n10.js +14358 -0
- package/dist/chunk-xtv4fh71.js +53 -0
- package/dist/chunk-xv3era3s.js +8 -0
- package/dist/chunk-xxr0mzqt.js +90 -0
- package/dist/chunk-xzcz58pv.js +90 -0
- package/dist/chunk-y1784krc.js +19 -0
- package/dist/chunk-y9pt2qdf.js +69 -0
- package/dist/chunk-ya53e6g3.js +333 -0
- package/dist/chunk-ydde1jqg.js +490 -0
- package/dist/chunk-yh7amsbv.js +143 -0
- package/dist/chunk-yn80rxav.js +458 -0
- package/dist/chunk-ysvwcdav.js +9300 -0
- package/dist/chunk-ytvzxnx2.js +862 -0
- package/dist/chunk-yv9c6hfk.js +286 -0
- package/dist/chunk-yvdj4t96.js +88 -0
- package/dist/chunk-ywxd4qw4.js +22 -0
- package/dist/chunk-yysj6sxt.js +336 -0
- package/dist/chunk-z2dp53wn.js +17 -0
- package/dist/chunk-z2gj7190.js +5398 -0
- package/dist/chunk-z7ns4g0p.js +802 -0
- package/dist/chunk-z9b8pnt1.js +654 -0
- package/dist/chunk-zc6g0qqe.js +29 -0
- package/dist/chunk-zk2wsm7d.js +15 -0
- package/dist/chunk-zq4j9zys.js +264 -0
- package/dist/chunk-zsfxha74.js +17655 -0
- package/dist/chunk-ztmjzgq7.js +524 -0
- package/dist/chunk-zv2r5chy.js +91 -0
- package/dist/chunk-zx7pgp71.js +20 -0
- package/dist/chunk-zxvm58cn.js +102 -0
- package/dist/chunk-zydy88cv.js +70 -0
- package/dist/cli.js +92 -0
- package/package.json +36 -0
|
@@ -0,0 +1,1322 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
getSessionIngressAuthHeaders,
|
|
4
|
+
getSessionIngressAuthToken,
|
|
5
|
+
init_sessionActivity,
|
|
6
|
+
init_sessionIngressAuth,
|
|
7
|
+
registerSessionActivityCallback,
|
|
8
|
+
unregisterSessionActivityCallback
|
|
9
|
+
} from "./chunk-sdxgmmma.js";
|
|
10
|
+
import {
|
|
11
|
+
getClaudeCodeUserAgent,
|
|
12
|
+
init_sleep,
|
|
13
|
+
init_userAgent,
|
|
14
|
+
sleep
|
|
15
|
+
} from "./chunk-3zzszjst.js";
|
|
16
|
+
import {
|
|
17
|
+
createAxiosInstance,
|
|
18
|
+
init_proxy
|
|
19
|
+
} from "./chunk-gmaybtrd.js";
|
|
20
|
+
import {
|
|
21
|
+
init_analytics,
|
|
22
|
+
logEvent
|
|
23
|
+
} from "./chunk-h0rbjg6x.js";
|
|
24
|
+
import {
|
|
25
|
+
init_diagLogs,
|
|
26
|
+
logForDiagnosticsNoPII
|
|
27
|
+
} from "./chunk-b8x1gk3y.js";
|
|
28
|
+
import {
|
|
29
|
+
errorMessage,
|
|
30
|
+
getErrnoCode,
|
|
31
|
+
init_debug,
|
|
32
|
+
init_errors,
|
|
33
|
+
init_slowOperations,
|
|
34
|
+
jsonParse,
|
|
35
|
+
jsonStringify,
|
|
36
|
+
logForDebugging
|
|
37
|
+
} from "./chunk-sbbj6ta3.js";
|
|
38
|
+
import {
|
|
39
|
+
axios_default,
|
|
40
|
+
init_axios
|
|
41
|
+
} from "./chunk-xszk7n10.js";
|
|
42
|
+
|
|
43
|
+
// src/bridge/jwtUtils.ts
|
|
44
|
+
init_analytics();
|
|
45
|
+
init_debug();
|
|
46
|
+
init_diagLogs();
|
|
47
|
+
init_errors();
|
|
48
|
+
init_slowOperations();
|
|
49
|
+
function formatDuration(ms) {
|
|
50
|
+
if (ms < 60000)
|
|
51
|
+
return `${Math.round(ms / 1000)}s`;
|
|
52
|
+
const m = Math.floor(ms / 60000);
|
|
53
|
+
const s = Math.round(ms % 60000 / 1000);
|
|
54
|
+
return s > 0 ? `${m}m ${s}s` : `${m}m`;
|
|
55
|
+
}
|
|
56
|
+
function decodeJwtPayload(token) {
|
|
57
|
+
const jwt = token.startsWith("sk-ant-si-") ? token.slice("sk-ant-si-".length) : token;
|
|
58
|
+
const parts = jwt.split(".");
|
|
59
|
+
if (parts.length !== 3 || !parts[1])
|
|
60
|
+
return null;
|
|
61
|
+
try {
|
|
62
|
+
return jsonParse(Buffer.from(parts[1], "base64url").toString("utf8"));
|
|
63
|
+
} catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function decodeJwtExpiry(token) {
|
|
68
|
+
const payload = decodeJwtPayload(token);
|
|
69
|
+
if (payload !== null && typeof payload === "object" && "exp" in payload && typeof payload.exp === "number") {
|
|
70
|
+
return payload.exp;
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
var TOKEN_REFRESH_BUFFER_MS = 5 * 60 * 1000;
|
|
75
|
+
var FALLBACK_REFRESH_INTERVAL_MS = 30 * 60 * 1000;
|
|
76
|
+
var MAX_REFRESH_FAILURES = 3;
|
|
77
|
+
var REFRESH_RETRY_DELAY_MS = 60000;
|
|
78
|
+
function createTokenRefreshScheduler({
|
|
79
|
+
getAccessToken,
|
|
80
|
+
onRefresh,
|
|
81
|
+
label,
|
|
82
|
+
refreshBufferMs = TOKEN_REFRESH_BUFFER_MS
|
|
83
|
+
}) {
|
|
84
|
+
const timers = new Map;
|
|
85
|
+
const failureCounts = new Map;
|
|
86
|
+
const generations = new Map;
|
|
87
|
+
function nextGeneration(sessionId) {
|
|
88
|
+
const gen = (generations.get(sessionId) ?? 0) + 1;
|
|
89
|
+
generations.set(sessionId, gen);
|
|
90
|
+
return gen;
|
|
91
|
+
}
|
|
92
|
+
function schedule(sessionId, token) {
|
|
93
|
+
const expiry = decodeJwtExpiry(token);
|
|
94
|
+
if (!expiry) {
|
|
95
|
+
logForDebugging(`[${label}:token] Could not decode JWT expiry for sessionId=${sessionId}, token prefix=${token.slice(0, 15)}\u2026, keeping existing timer`);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const existing = timers.get(sessionId);
|
|
99
|
+
if (existing) {
|
|
100
|
+
clearTimeout(existing);
|
|
101
|
+
}
|
|
102
|
+
const gen = nextGeneration(sessionId);
|
|
103
|
+
const expiryDate = new Date(expiry * 1000).toISOString();
|
|
104
|
+
const delayMs = expiry * 1000 - Date.now() - refreshBufferMs;
|
|
105
|
+
if (delayMs <= 0) {
|
|
106
|
+
logForDebugging(`[${label}:token] Token for sessionId=${sessionId} expires=${expiryDate} (past or within buffer), refreshing immediately`);
|
|
107
|
+
doRefresh(sessionId, gen);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
logForDebugging(`[${label}:token] Scheduled token refresh for sessionId=${sessionId} in ${formatDuration(delayMs)} (expires=${expiryDate}, buffer=${refreshBufferMs / 1000}s)`);
|
|
111
|
+
const timer = setTimeout(doRefresh, delayMs, sessionId, gen);
|
|
112
|
+
timers.set(sessionId, timer);
|
|
113
|
+
}
|
|
114
|
+
function scheduleFromExpiresIn(sessionId, expiresInSeconds) {
|
|
115
|
+
const existing = timers.get(sessionId);
|
|
116
|
+
if (existing)
|
|
117
|
+
clearTimeout(existing);
|
|
118
|
+
const gen = nextGeneration(sessionId);
|
|
119
|
+
const delayMs = Math.max(expiresInSeconds * 1000 - refreshBufferMs, 30000);
|
|
120
|
+
logForDebugging(`[${label}:token] Scheduled token refresh for sessionId=${sessionId} in ${formatDuration(delayMs)} (expires_in=${expiresInSeconds}s, buffer=${refreshBufferMs / 1000}s)`);
|
|
121
|
+
const timer = setTimeout(doRefresh, delayMs, sessionId, gen);
|
|
122
|
+
timers.set(sessionId, timer);
|
|
123
|
+
}
|
|
124
|
+
async function doRefresh(sessionId, gen) {
|
|
125
|
+
let oauthToken;
|
|
126
|
+
try {
|
|
127
|
+
oauthToken = await getAccessToken();
|
|
128
|
+
} catch (err) {
|
|
129
|
+
logForDebugging(`[${label}:token] getAccessToken threw for sessionId=${sessionId}: ${errorMessage(err)}`, { level: "error" });
|
|
130
|
+
}
|
|
131
|
+
if (generations.get(sessionId) !== gen) {
|
|
132
|
+
logForDebugging(`[${label}:token] doRefresh for sessionId=${sessionId} stale (gen ${gen} vs ${generations.get(sessionId)}), skipping`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (!oauthToken) {
|
|
136
|
+
const failures = (failureCounts.get(sessionId) ?? 0) + 1;
|
|
137
|
+
failureCounts.set(sessionId, failures);
|
|
138
|
+
logForDebugging(`[${label}:token] No OAuth token available for refresh, sessionId=${sessionId} (failure ${failures}/${MAX_REFRESH_FAILURES})`, { level: "error" });
|
|
139
|
+
logForDiagnosticsNoPII("error", "bridge_token_refresh_no_oauth");
|
|
140
|
+
if (failures < MAX_REFRESH_FAILURES) {
|
|
141
|
+
const retryTimer = setTimeout(doRefresh, REFRESH_RETRY_DELAY_MS, sessionId, gen);
|
|
142
|
+
timers.set(sessionId, retryTimer);
|
|
143
|
+
}
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
failureCounts.delete(sessionId);
|
|
147
|
+
logForDebugging(`[${label}:token] Refreshing token for sessionId=${sessionId}: new token prefix=${oauthToken.slice(0, 15)}\u2026`);
|
|
148
|
+
logEvent("tengu_bridge_token_refreshed", {});
|
|
149
|
+
onRefresh(sessionId, oauthToken);
|
|
150
|
+
const timer = setTimeout(doRefresh, FALLBACK_REFRESH_INTERVAL_MS, sessionId, gen);
|
|
151
|
+
timers.set(sessionId, timer);
|
|
152
|
+
logForDebugging(`[${label}:token] Scheduled follow-up refresh for sessionId=${sessionId} in ${formatDuration(FALLBACK_REFRESH_INTERVAL_MS)}`);
|
|
153
|
+
}
|
|
154
|
+
function cancel(sessionId) {
|
|
155
|
+
nextGeneration(sessionId);
|
|
156
|
+
const timer = timers.get(sessionId);
|
|
157
|
+
if (timer) {
|
|
158
|
+
clearTimeout(timer);
|
|
159
|
+
timers.delete(sessionId);
|
|
160
|
+
}
|
|
161
|
+
failureCounts.delete(sessionId);
|
|
162
|
+
}
|
|
163
|
+
function cancelAll() {
|
|
164
|
+
for (const sessionId of generations.keys()) {
|
|
165
|
+
nextGeneration(sessionId);
|
|
166
|
+
}
|
|
167
|
+
for (const timer of timers.values()) {
|
|
168
|
+
clearTimeout(timer);
|
|
169
|
+
}
|
|
170
|
+
timers.clear();
|
|
171
|
+
failureCounts.clear();
|
|
172
|
+
}
|
|
173
|
+
return { schedule, scheduleFromExpiresIn, cancel, cancelAll };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/cli/transports/ccrClient.ts
|
|
177
|
+
import { randomUUID } from "crypto";
|
|
178
|
+
init_debug();
|
|
179
|
+
init_diagLogs();
|
|
180
|
+
init_errors();
|
|
181
|
+
init_proxy();
|
|
182
|
+
init_sessionActivity();
|
|
183
|
+
init_sessionIngressAuth();
|
|
184
|
+
init_sleep();
|
|
185
|
+
init_userAgent();
|
|
186
|
+
|
|
187
|
+
// src/cli/transports/SerialBatchEventUploader.ts
|
|
188
|
+
init_slowOperations();
|
|
189
|
+
|
|
190
|
+
class RetryableError extends Error {
|
|
191
|
+
retryAfterMs;
|
|
192
|
+
constructor(message, retryAfterMs) {
|
|
193
|
+
super(message);
|
|
194
|
+
this.retryAfterMs = retryAfterMs;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
class SerialBatchEventUploader {
|
|
199
|
+
pending = [];
|
|
200
|
+
pendingAtClose = 0;
|
|
201
|
+
draining = false;
|
|
202
|
+
closed = false;
|
|
203
|
+
backpressureResolvers = [];
|
|
204
|
+
sleepResolve = null;
|
|
205
|
+
flushResolvers = [];
|
|
206
|
+
droppedBatches = 0;
|
|
207
|
+
config;
|
|
208
|
+
constructor(config) {
|
|
209
|
+
this.config = config;
|
|
210
|
+
}
|
|
211
|
+
get droppedBatchCount() {
|
|
212
|
+
return this.droppedBatches;
|
|
213
|
+
}
|
|
214
|
+
get pendingCount() {
|
|
215
|
+
return this.closed ? this.pendingAtClose : this.pending.length;
|
|
216
|
+
}
|
|
217
|
+
async enqueue(events) {
|
|
218
|
+
if (this.closed)
|
|
219
|
+
return;
|
|
220
|
+
const items = Array.isArray(events) ? events : [events];
|
|
221
|
+
if (items.length === 0)
|
|
222
|
+
return;
|
|
223
|
+
while (this.pending.length + items.length > this.config.maxQueueSize && !this.closed) {
|
|
224
|
+
await new Promise((resolve) => {
|
|
225
|
+
this.backpressureResolvers.push(resolve);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
if (this.closed)
|
|
229
|
+
return;
|
|
230
|
+
this.pending.push(...items);
|
|
231
|
+
this.drain();
|
|
232
|
+
}
|
|
233
|
+
flush() {
|
|
234
|
+
if (this.pending.length === 0 && !this.draining) {
|
|
235
|
+
return Promise.resolve();
|
|
236
|
+
}
|
|
237
|
+
this.drain();
|
|
238
|
+
return new Promise((resolve) => {
|
|
239
|
+
this.flushResolvers.push(resolve);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
close() {
|
|
243
|
+
if (this.closed)
|
|
244
|
+
return;
|
|
245
|
+
this.closed = true;
|
|
246
|
+
this.pendingAtClose = this.pending.length;
|
|
247
|
+
this.pending = [];
|
|
248
|
+
this.sleepResolve?.();
|
|
249
|
+
this.sleepResolve = null;
|
|
250
|
+
for (const resolve of this.backpressureResolvers)
|
|
251
|
+
resolve();
|
|
252
|
+
this.backpressureResolvers = [];
|
|
253
|
+
for (const resolve of this.flushResolvers)
|
|
254
|
+
resolve();
|
|
255
|
+
this.flushResolvers = [];
|
|
256
|
+
}
|
|
257
|
+
async drain() {
|
|
258
|
+
if (this.draining || this.closed)
|
|
259
|
+
return;
|
|
260
|
+
this.draining = true;
|
|
261
|
+
let failures = 0;
|
|
262
|
+
try {
|
|
263
|
+
while (this.pending.length > 0 && !this.closed) {
|
|
264
|
+
const batch = this.takeBatch();
|
|
265
|
+
if (batch.length === 0)
|
|
266
|
+
continue;
|
|
267
|
+
try {
|
|
268
|
+
await this.config.send(batch);
|
|
269
|
+
failures = 0;
|
|
270
|
+
} catch (err) {
|
|
271
|
+
failures++;
|
|
272
|
+
if (this.config.maxConsecutiveFailures !== undefined && failures >= this.config.maxConsecutiveFailures) {
|
|
273
|
+
this.droppedBatches++;
|
|
274
|
+
this.config.onBatchDropped?.(batch.length, failures);
|
|
275
|
+
failures = 0;
|
|
276
|
+
this.releaseBackpressure();
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
this.pending = batch.concat(this.pending);
|
|
280
|
+
const retryAfterMs = err instanceof RetryableError ? err.retryAfterMs : undefined;
|
|
281
|
+
await this.sleep(this.retryDelay(failures, retryAfterMs));
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
this.releaseBackpressure();
|
|
285
|
+
}
|
|
286
|
+
} finally {
|
|
287
|
+
this.draining = false;
|
|
288
|
+
if (this.pending.length === 0) {
|
|
289
|
+
for (const resolve of this.flushResolvers)
|
|
290
|
+
resolve();
|
|
291
|
+
this.flushResolvers = [];
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
takeBatch() {
|
|
296
|
+
const { maxBatchSize, maxBatchBytes } = this.config;
|
|
297
|
+
if (maxBatchBytes === undefined) {
|
|
298
|
+
return this.pending.splice(0, maxBatchSize);
|
|
299
|
+
}
|
|
300
|
+
let bytes = 0;
|
|
301
|
+
let count = 0;
|
|
302
|
+
while (count < this.pending.length && count < maxBatchSize) {
|
|
303
|
+
let itemBytes;
|
|
304
|
+
try {
|
|
305
|
+
itemBytes = Buffer.byteLength(jsonStringify(this.pending[count]));
|
|
306
|
+
} catch {
|
|
307
|
+
this.pending.splice(count, 1);
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
if (count > 0 && bytes + itemBytes > maxBatchBytes)
|
|
311
|
+
break;
|
|
312
|
+
bytes += itemBytes;
|
|
313
|
+
count++;
|
|
314
|
+
}
|
|
315
|
+
return this.pending.splice(0, count);
|
|
316
|
+
}
|
|
317
|
+
retryDelay(failures, retryAfterMs) {
|
|
318
|
+
const jitter = Math.random() * this.config.jitterMs;
|
|
319
|
+
if (retryAfterMs !== undefined) {
|
|
320
|
+
const clamped = Math.max(this.config.baseDelayMs, Math.min(retryAfterMs, this.config.maxDelayMs));
|
|
321
|
+
return clamped + jitter;
|
|
322
|
+
}
|
|
323
|
+
const exponential = Math.min(this.config.baseDelayMs * 2 ** (failures - 1), this.config.maxDelayMs);
|
|
324
|
+
return exponential + jitter;
|
|
325
|
+
}
|
|
326
|
+
releaseBackpressure() {
|
|
327
|
+
const resolvers = this.backpressureResolvers;
|
|
328
|
+
this.backpressureResolvers = [];
|
|
329
|
+
for (const resolve of resolvers)
|
|
330
|
+
resolve();
|
|
331
|
+
}
|
|
332
|
+
sleep(ms) {
|
|
333
|
+
return new Promise((resolve) => {
|
|
334
|
+
this.sleepResolve = resolve;
|
|
335
|
+
setTimeout((self, resolve2) => {
|
|
336
|
+
self.sleepResolve = null;
|
|
337
|
+
resolve2();
|
|
338
|
+
}, ms, this, resolve);
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// src/cli/transports/WorkerStateUploader.ts
|
|
344
|
+
init_sleep();
|
|
345
|
+
|
|
346
|
+
class WorkerStateUploader {
|
|
347
|
+
inflight = null;
|
|
348
|
+
pending = null;
|
|
349
|
+
closed = false;
|
|
350
|
+
config;
|
|
351
|
+
constructor(config) {
|
|
352
|
+
this.config = config;
|
|
353
|
+
}
|
|
354
|
+
enqueue(patch) {
|
|
355
|
+
if (this.closed)
|
|
356
|
+
return;
|
|
357
|
+
this.pending = this.pending ? coalescePatches(this.pending, patch) : patch;
|
|
358
|
+
this.drain();
|
|
359
|
+
}
|
|
360
|
+
close() {
|
|
361
|
+
this.closed = true;
|
|
362
|
+
this.pending = null;
|
|
363
|
+
}
|
|
364
|
+
async drain() {
|
|
365
|
+
if (this.inflight || this.closed)
|
|
366
|
+
return;
|
|
367
|
+
if (!this.pending)
|
|
368
|
+
return;
|
|
369
|
+
const payload = this.pending;
|
|
370
|
+
this.pending = null;
|
|
371
|
+
this.inflight = this.sendWithRetry(payload).then(() => {
|
|
372
|
+
this.inflight = null;
|
|
373
|
+
if (this.pending && !this.closed) {
|
|
374
|
+
this.drain();
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
async sendWithRetry(payload) {
|
|
379
|
+
let current = payload;
|
|
380
|
+
let failures = 0;
|
|
381
|
+
while (!this.closed) {
|
|
382
|
+
const ok = await this.config.send(current);
|
|
383
|
+
if (ok)
|
|
384
|
+
return;
|
|
385
|
+
failures++;
|
|
386
|
+
await sleep(this.retryDelay(failures));
|
|
387
|
+
if (this.pending && !this.closed) {
|
|
388
|
+
current = coalescePatches(current, this.pending);
|
|
389
|
+
this.pending = null;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
retryDelay(failures) {
|
|
394
|
+
const exponential = Math.min(this.config.baseDelayMs * 2 ** (failures - 1), this.config.maxDelayMs);
|
|
395
|
+
const jitter = Math.random() * this.config.jitterMs;
|
|
396
|
+
return exponential + jitter;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function coalescePatches(base, overlay) {
|
|
400
|
+
const merged = { ...base };
|
|
401
|
+
for (const [key, value] of Object.entries(overlay)) {
|
|
402
|
+
if ((key === "external_metadata" || key === "internal_metadata") && merged[key] && typeof merged[key] === "object" && typeof value === "object" && value !== null) {
|
|
403
|
+
merged[key] = {
|
|
404
|
+
...merged[key],
|
|
405
|
+
...value
|
|
406
|
+
};
|
|
407
|
+
} else {
|
|
408
|
+
merged[key] = value;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return merged;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// src/cli/transports/ccrClient.ts
|
|
415
|
+
var DEFAULT_HEARTBEAT_INTERVAL_MS = 20000;
|
|
416
|
+
var STREAM_EVENT_FLUSH_INTERVAL_MS = 100;
|
|
417
|
+
function alwaysValidStatus() {
|
|
418
|
+
return true;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
class CCRInitError extends Error {
|
|
422
|
+
reason;
|
|
423
|
+
constructor(reason) {
|
|
424
|
+
super(`CCRClient init failed: ${reason}`);
|
|
425
|
+
this.reason = reason;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
var MAX_CONSECUTIVE_AUTH_FAILURES = 10;
|
|
429
|
+
function createStreamAccumulator() {
|
|
430
|
+
return { byMessage: new Map, scopeToMessage: new Map };
|
|
431
|
+
}
|
|
432
|
+
function scopeKey(m) {
|
|
433
|
+
return `${m.session_id}:${m.parent_tool_use_id ?? ""}`;
|
|
434
|
+
}
|
|
435
|
+
function accumulateStreamEvents(buffer, state) {
|
|
436
|
+
const out = [];
|
|
437
|
+
const touched = new Map;
|
|
438
|
+
for (const msg of buffer) {
|
|
439
|
+
switch (msg.event.type) {
|
|
440
|
+
case "message_start": {
|
|
441
|
+
const id = msg.event.message.id;
|
|
442
|
+
const prevId = state.scopeToMessage.get(scopeKey(msg));
|
|
443
|
+
if (prevId)
|
|
444
|
+
state.byMessage.delete(prevId);
|
|
445
|
+
state.scopeToMessage.set(scopeKey(msg), id);
|
|
446
|
+
state.byMessage.set(id, []);
|
|
447
|
+
out.push(msg);
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
case "content_block_delta": {
|
|
451
|
+
if (msg.event.delta.type !== "text_delta") {
|
|
452
|
+
out.push(msg);
|
|
453
|
+
break;
|
|
454
|
+
}
|
|
455
|
+
const messageId = state.scopeToMessage.get(scopeKey(msg));
|
|
456
|
+
const blocks = messageId ? state.byMessage.get(messageId) : undefined;
|
|
457
|
+
if (!blocks) {
|
|
458
|
+
out.push(msg);
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
const chunks = blocks[msg.event.index] ??= [];
|
|
462
|
+
chunks.push(msg.event.delta.text);
|
|
463
|
+
const existing = touched.get(chunks);
|
|
464
|
+
if (existing) {
|
|
465
|
+
existing.event.delta.text = chunks.join("");
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
const snapshot = {
|
|
469
|
+
type: "stream_event",
|
|
470
|
+
uuid: msg.uuid,
|
|
471
|
+
session_id: msg.session_id,
|
|
472
|
+
parent_tool_use_id: msg.parent_tool_use_id,
|
|
473
|
+
event: {
|
|
474
|
+
type: "content_block_delta",
|
|
475
|
+
index: msg.event.index,
|
|
476
|
+
delta: { type: "text_delta", text: chunks.join("") }
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
touched.set(chunks, snapshot);
|
|
480
|
+
out.push(snapshot);
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
483
|
+
default:
|
|
484
|
+
out.push(msg);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
return out;
|
|
488
|
+
}
|
|
489
|
+
function clearStreamAccumulatorForMessage(state, assistant) {
|
|
490
|
+
state.byMessage.delete(assistant.message.id);
|
|
491
|
+
const scope = scopeKey(assistant);
|
|
492
|
+
if (state.scopeToMessage.get(scope) === assistant.message.id) {
|
|
493
|
+
state.scopeToMessage.delete(scope);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
class CCRClient {
|
|
498
|
+
workerEpoch = 0;
|
|
499
|
+
heartbeatIntervalMs;
|
|
500
|
+
heartbeatJitterFraction;
|
|
501
|
+
heartbeatTimer = null;
|
|
502
|
+
heartbeatInFlight = false;
|
|
503
|
+
closed = false;
|
|
504
|
+
consecutiveAuthFailures = 0;
|
|
505
|
+
currentState = null;
|
|
506
|
+
sessionBaseUrl;
|
|
507
|
+
sessionId;
|
|
508
|
+
http = createAxiosInstance({ keepAlive: true });
|
|
509
|
+
streamEventBuffer = [];
|
|
510
|
+
streamEventTimer = null;
|
|
511
|
+
streamTextAccumulator = createStreamAccumulator();
|
|
512
|
+
workerState;
|
|
513
|
+
eventUploader;
|
|
514
|
+
internalEventUploader;
|
|
515
|
+
deliveryUploader;
|
|
516
|
+
onEpochMismatch;
|
|
517
|
+
getAuthHeaders;
|
|
518
|
+
constructor(transport, sessionUrl, opts) {
|
|
519
|
+
this.onEpochMismatch = opts?.onEpochMismatch ?? (() => {
|
|
520
|
+
process.exit(1);
|
|
521
|
+
});
|
|
522
|
+
this.heartbeatIntervalMs = opts?.heartbeatIntervalMs ?? DEFAULT_HEARTBEAT_INTERVAL_MS;
|
|
523
|
+
this.heartbeatJitterFraction = opts?.heartbeatJitterFraction ?? 0;
|
|
524
|
+
this.getAuthHeaders = opts?.getAuthHeaders ?? getSessionIngressAuthHeaders;
|
|
525
|
+
if (sessionUrl.protocol !== "http:" && sessionUrl.protocol !== "https:") {
|
|
526
|
+
throw new Error(`CCRClient: Expected http(s) URL, got ${sessionUrl.protocol}`);
|
|
527
|
+
}
|
|
528
|
+
const pathname = sessionUrl.pathname.replace(/\/$/, "");
|
|
529
|
+
this.sessionBaseUrl = `${sessionUrl.protocol}//${sessionUrl.host}${pathname}`;
|
|
530
|
+
this.sessionId = pathname.split("/").pop() || "";
|
|
531
|
+
this.workerState = new WorkerStateUploader({
|
|
532
|
+
send: (body) => this.request("put", "/worker", { worker_epoch: this.workerEpoch, ...body }, "PUT worker").then((r) => r.ok),
|
|
533
|
+
baseDelayMs: 500,
|
|
534
|
+
maxDelayMs: 30000,
|
|
535
|
+
jitterMs: 500
|
|
536
|
+
});
|
|
537
|
+
this.eventUploader = new SerialBatchEventUploader({
|
|
538
|
+
maxBatchSize: 100,
|
|
539
|
+
maxBatchBytes: 10 * 1024 * 1024,
|
|
540
|
+
maxQueueSize: 1e5,
|
|
541
|
+
send: async (batch) => {
|
|
542
|
+
const result = await this.request("post", "/worker/events", { worker_epoch: this.workerEpoch, events: batch }, "client events");
|
|
543
|
+
if (!result.ok) {
|
|
544
|
+
throw new RetryableError("client event POST failed", result.retryAfterMs);
|
|
545
|
+
}
|
|
546
|
+
},
|
|
547
|
+
baseDelayMs: 500,
|
|
548
|
+
maxDelayMs: 30000,
|
|
549
|
+
jitterMs: 500
|
|
550
|
+
});
|
|
551
|
+
this.internalEventUploader = new SerialBatchEventUploader({
|
|
552
|
+
maxBatchSize: 100,
|
|
553
|
+
maxBatchBytes: 10 * 1024 * 1024,
|
|
554
|
+
maxQueueSize: 200,
|
|
555
|
+
send: async (batch) => {
|
|
556
|
+
const result = await this.request("post", "/worker/internal-events", { worker_epoch: this.workerEpoch, events: batch }, "internal events");
|
|
557
|
+
if (!result.ok) {
|
|
558
|
+
throw new RetryableError("internal event POST failed", result.retryAfterMs);
|
|
559
|
+
}
|
|
560
|
+
},
|
|
561
|
+
baseDelayMs: 500,
|
|
562
|
+
maxDelayMs: 30000,
|
|
563
|
+
jitterMs: 500
|
|
564
|
+
});
|
|
565
|
+
this.deliveryUploader = new SerialBatchEventUploader({
|
|
566
|
+
maxBatchSize: 64,
|
|
567
|
+
maxQueueSize: 64,
|
|
568
|
+
send: async (batch) => {
|
|
569
|
+
const result = await this.request("post", "/worker/events/delivery", {
|
|
570
|
+
worker_epoch: this.workerEpoch,
|
|
571
|
+
updates: batch.map((d) => ({
|
|
572
|
+
event_id: d.eventId,
|
|
573
|
+
status: d.status
|
|
574
|
+
}))
|
|
575
|
+
}, "delivery batch");
|
|
576
|
+
if (!result.ok) {
|
|
577
|
+
throw new RetryableError("delivery POST failed", result.retryAfterMs);
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
baseDelayMs: 500,
|
|
581
|
+
maxDelayMs: 30000,
|
|
582
|
+
jitterMs: 500
|
|
583
|
+
});
|
|
584
|
+
transport.setOnEvent((event) => {
|
|
585
|
+
this.reportDelivery(event.event_id, "received");
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
async initialize(epoch) {
|
|
589
|
+
const startMs = Date.now();
|
|
590
|
+
if (Object.keys(this.getAuthHeaders()).length === 0) {
|
|
591
|
+
throw new CCRInitError("no_auth_headers");
|
|
592
|
+
}
|
|
593
|
+
if (epoch === undefined) {
|
|
594
|
+
const rawEpoch = process.env.CLAUDE_CODE_WORKER_EPOCH;
|
|
595
|
+
epoch = rawEpoch ? parseInt(rawEpoch, 10) : NaN;
|
|
596
|
+
}
|
|
597
|
+
if (isNaN(epoch)) {
|
|
598
|
+
throw new CCRInitError("missing_epoch");
|
|
599
|
+
}
|
|
600
|
+
this.workerEpoch = epoch;
|
|
601
|
+
const restoredPromise = this.getWorkerState();
|
|
602
|
+
const result = await this.request("put", "/worker", {
|
|
603
|
+
worker_status: "idle",
|
|
604
|
+
worker_epoch: this.workerEpoch,
|
|
605
|
+
external_metadata: {
|
|
606
|
+
pending_action: null,
|
|
607
|
+
task_summary: null
|
|
608
|
+
}
|
|
609
|
+
}, "PUT worker (init)");
|
|
610
|
+
if (!result.ok) {
|
|
611
|
+
throw new CCRInitError("worker_register_failed");
|
|
612
|
+
}
|
|
613
|
+
this.currentState = "idle";
|
|
614
|
+
this.startHeartbeat();
|
|
615
|
+
registerSessionActivityCallback(() => {
|
|
616
|
+
this.writeEvent({ type: "keep_alive" });
|
|
617
|
+
});
|
|
618
|
+
logForDebugging(`CCRClient: initialized, epoch=${this.workerEpoch}`);
|
|
619
|
+
logForDiagnosticsNoPII("info", "cli_worker_lifecycle_initialized", {
|
|
620
|
+
epoch: this.workerEpoch,
|
|
621
|
+
duration_ms: Date.now() - startMs
|
|
622
|
+
});
|
|
623
|
+
const { metadata, durationMs } = await restoredPromise;
|
|
624
|
+
if (!this.closed) {
|
|
625
|
+
logForDiagnosticsNoPII("info", "cli_worker_state_restored", {
|
|
626
|
+
duration_ms: durationMs,
|
|
627
|
+
had_state: metadata !== null
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
return metadata;
|
|
631
|
+
}
|
|
632
|
+
async getWorkerState() {
|
|
633
|
+
const startMs = Date.now();
|
|
634
|
+
const authHeaders = this.getAuthHeaders();
|
|
635
|
+
if (Object.keys(authHeaders).length === 0) {
|
|
636
|
+
return { metadata: null, durationMs: 0 };
|
|
637
|
+
}
|
|
638
|
+
const data = await this.getWithRetry(`${this.sessionBaseUrl}/worker`, authHeaders, "worker_state");
|
|
639
|
+
return {
|
|
640
|
+
metadata: data?.worker?.external_metadata ?? null,
|
|
641
|
+
durationMs: Date.now() - startMs
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
async request(method, path, body, label, { timeout = 1e4 } = {}) {
|
|
645
|
+
const authHeaders = this.getAuthHeaders();
|
|
646
|
+
if (Object.keys(authHeaders).length === 0)
|
|
647
|
+
return { ok: false };
|
|
648
|
+
try {
|
|
649
|
+
const response = await this.http[method](`${this.sessionBaseUrl}${path}`, body, {
|
|
650
|
+
headers: {
|
|
651
|
+
...authHeaders,
|
|
652
|
+
"Content-Type": "application/json",
|
|
653
|
+
"anthropic-version": "2023-06-01",
|
|
654
|
+
"User-Agent": getClaudeCodeUserAgent()
|
|
655
|
+
},
|
|
656
|
+
validateStatus: alwaysValidStatus,
|
|
657
|
+
timeout
|
|
658
|
+
});
|
|
659
|
+
if (response.status >= 200 && response.status < 300) {
|
|
660
|
+
this.consecutiveAuthFailures = 0;
|
|
661
|
+
return { ok: true };
|
|
662
|
+
}
|
|
663
|
+
if (response.status === 409) {
|
|
664
|
+
this.handleEpochMismatch();
|
|
665
|
+
}
|
|
666
|
+
if (response.status === 401 || response.status === 403) {
|
|
667
|
+
const tok = getSessionIngressAuthToken();
|
|
668
|
+
const exp = tok ? decodeJwtExpiry(tok) : null;
|
|
669
|
+
if (exp !== null && exp * 1000 < Date.now()) {
|
|
670
|
+
logForDebugging(`CCRClient: session_token expired (exp=${new Date(exp * 1000).toISOString()}) \u2014 no refresh was delivered, exiting`, { level: "error" });
|
|
671
|
+
logForDiagnosticsNoPII("error", "cli_worker_token_expired_no_refresh");
|
|
672
|
+
this.onEpochMismatch();
|
|
673
|
+
}
|
|
674
|
+
this.consecutiveAuthFailures++;
|
|
675
|
+
if (this.consecutiveAuthFailures >= MAX_CONSECUTIVE_AUTH_FAILURES) {
|
|
676
|
+
logForDebugging(`CCRClient: ${this.consecutiveAuthFailures} consecutive auth failures with a valid-looking token \u2014 server-side auth unrecoverable, exiting`, { level: "error" });
|
|
677
|
+
logForDiagnosticsNoPII("error", "cli_worker_auth_failures_exhausted");
|
|
678
|
+
this.onEpochMismatch();
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
logForDebugging(`CCRClient: ${label} returned ${response.status}`, {
|
|
682
|
+
level: "warn"
|
|
683
|
+
});
|
|
684
|
+
logForDiagnosticsNoPII("warn", "cli_worker_request_failed", {
|
|
685
|
+
method,
|
|
686
|
+
path,
|
|
687
|
+
status: response.status
|
|
688
|
+
});
|
|
689
|
+
if (response.status === 429) {
|
|
690
|
+
const raw = response.headers?.["retry-after"];
|
|
691
|
+
const seconds = typeof raw === "string" ? parseInt(raw, 10) : NaN;
|
|
692
|
+
if (!isNaN(seconds) && seconds >= 0) {
|
|
693
|
+
return { ok: false, retryAfterMs: seconds * 1000 };
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return { ok: false };
|
|
697
|
+
} catch (error) {
|
|
698
|
+
logForDebugging(`CCRClient: ${label} failed: ${errorMessage(error)}`, {
|
|
699
|
+
level: "warn"
|
|
700
|
+
});
|
|
701
|
+
logForDiagnosticsNoPII("warn", "cli_worker_request_error", {
|
|
702
|
+
method,
|
|
703
|
+
path,
|
|
704
|
+
error_code: getErrnoCode(error)
|
|
705
|
+
});
|
|
706
|
+
return { ok: false };
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
reportState(state, details) {
|
|
710
|
+
if (state === this.currentState && !details)
|
|
711
|
+
return;
|
|
712
|
+
this.currentState = state;
|
|
713
|
+
this.workerState.enqueue({
|
|
714
|
+
worker_status: state,
|
|
715
|
+
requires_action_details: details ? {
|
|
716
|
+
tool_name: details.tool_name,
|
|
717
|
+
action_description: details.action_description,
|
|
718
|
+
request_id: details.request_id
|
|
719
|
+
} : null
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
reportMetadata(metadata) {
|
|
723
|
+
this.workerState.enqueue({ external_metadata: metadata });
|
|
724
|
+
}
|
|
725
|
+
handleEpochMismatch() {
|
|
726
|
+
logForDebugging("CCRClient: Epoch mismatch (409), shutting down", {
|
|
727
|
+
level: "error"
|
|
728
|
+
});
|
|
729
|
+
logForDiagnosticsNoPII("error", "cli_worker_epoch_mismatch");
|
|
730
|
+
this.onEpochMismatch();
|
|
731
|
+
}
|
|
732
|
+
startHeartbeat() {
|
|
733
|
+
this.stopHeartbeat();
|
|
734
|
+
const schedule = () => {
|
|
735
|
+
const jitter = this.heartbeatIntervalMs * this.heartbeatJitterFraction * (2 * Math.random() - 1);
|
|
736
|
+
this.heartbeatTimer = setTimeout(tick, this.heartbeatIntervalMs + jitter);
|
|
737
|
+
};
|
|
738
|
+
const tick = () => {
|
|
739
|
+
this.sendHeartbeat();
|
|
740
|
+
if (this.heartbeatTimer === null)
|
|
741
|
+
return;
|
|
742
|
+
schedule();
|
|
743
|
+
};
|
|
744
|
+
schedule();
|
|
745
|
+
}
|
|
746
|
+
stopHeartbeat() {
|
|
747
|
+
if (this.heartbeatTimer) {
|
|
748
|
+
clearTimeout(this.heartbeatTimer);
|
|
749
|
+
this.heartbeatTimer = null;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
async sendHeartbeat() {
|
|
753
|
+
if (this.heartbeatInFlight)
|
|
754
|
+
return;
|
|
755
|
+
this.heartbeatInFlight = true;
|
|
756
|
+
try {
|
|
757
|
+
const result = await this.request("post", "/worker/heartbeat", { session_id: this.sessionId, worker_epoch: this.workerEpoch }, "Heartbeat", { timeout: 5000 });
|
|
758
|
+
if (result.ok) {
|
|
759
|
+
logForDebugging("CCRClient: Heartbeat sent");
|
|
760
|
+
}
|
|
761
|
+
} finally {
|
|
762
|
+
this.heartbeatInFlight = false;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
async writeEvent(message) {
|
|
766
|
+
if (message.type === "stream_event") {
|
|
767
|
+
this.streamEventBuffer.push(message);
|
|
768
|
+
if (!this.streamEventTimer) {
|
|
769
|
+
this.streamEventTimer = setTimeout(() => void this.flushStreamEventBuffer(), STREAM_EVENT_FLUSH_INTERVAL_MS);
|
|
770
|
+
}
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
await this.flushStreamEventBuffer();
|
|
774
|
+
if (message.type === "assistant") {
|
|
775
|
+
clearStreamAccumulatorForMessage(this.streamTextAccumulator, message);
|
|
776
|
+
}
|
|
777
|
+
await this.eventUploader.enqueue(this.toClientEvent(message));
|
|
778
|
+
}
|
|
779
|
+
toClientEvent(message) {
|
|
780
|
+
const msg = message;
|
|
781
|
+
return {
|
|
782
|
+
payload: {
|
|
783
|
+
...msg,
|
|
784
|
+
uuid: typeof msg.uuid === "string" ? msg.uuid : randomUUID()
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
async flushStreamEventBuffer() {
|
|
789
|
+
if (this.streamEventTimer) {
|
|
790
|
+
clearTimeout(this.streamEventTimer);
|
|
791
|
+
this.streamEventTimer = null;
|
|
792
|
+
}
|
|
793
|
+
if (this.streamEventBuffer.length === 0)
|
|
794
|
+
return;
|
|
795
|
+
const buffered = this.streamEventBuffer;
|
|
796
|
+
this.streamEventBuffer = [];
|
|
797
|
+
const payloads = accumulateStreamEvents(buffered, this.streamTextAccumulator);
|
|
798
|
+
await this.eventUploader.enqueue(payloads.map((payload) => ({ payload, ephemeral: true })));
|
|
799
|
+
}
|
|
800
|
+
async writeInternalEvent(eventType, payload, {
|
|
801
|
+
isCompaction = false,
|
|
802
|
+
agentId
|
|
803
|
+
} = {}) {
|
|
804
|
+
const event = {
|
|
805
|
+
payload: {
|
|
806
|
+
type: eventType,
|
|
807
|
+
...payload,
|
|
808
|
+
uuid: typeof payload.uuid === "string" ? payload.uuid : randomUUID()
|
|
809
|
+
},
|
|
810
|
+
...isCompaction && { is_compaction: true },
|
|
811
|
+
...agentId && { agent_id: agentId }
|
|
812
|
+
};
|
|
813
|
+
await this.internalEventUploader.enqueue(event);
|
|
814
|
+
}
|
|
815
|
+
flushInternalEvents() {
|
|
816
|
+
return this.internalEventUploader.flush();
|
|
817
|
+
}
|
|
818
|
+
async flush() {
|
|
819
|
+
await this.flushStreamEventBuffer();
|
|
820
|
+
return this.eventUploader.flush();
|
|
821
|
+
}
|
|
822
|
+
async readInternalEvents() {
|
|
823
|
+
return this.paginatedGet("/worker/internal-events", {}, "internal_events");
|
|
824
|
+
}
|
|
825
|
+
async readSubagentInternalEvents() {
|
|
826
|
+
return this.paginatedGet("/worker/internal-events", { subagents: "true" }, "subagent_events");
|
|
827
|
+
}
|
|
828
|
+
async paginatedGet(path, params, context) {
|
|
829
|
+
const authHeaders = this.getAuthHeaders();
|
|
830
|
+
if (Object.keys(authHeaders).length === 0)
|
|
831
|
+
return null;
|
|
832
|
+
const allEvents = [];
|
|
833
|
+
let cursor;
|
|
834
|
+
do {
|
|
835
|
+
const url = new URL(`${this.sessionBaseUrl}${path}`);
|
|
836
|
+
for (const [k, v] of Object.entries(params)) {
|
|
837
|
+
url.searchParams.set(k, v);
|
|
838
|
+
}
|
|
839
|
+
if (cursor) {
|
|
840
|
+
url.searchParams.set("cursor", cursor);
|
|
841
|
+
}
|
|
842
|
+
const page = await this.getWithRetry(url.toString(), authHeaders, context);
|
|
843
|
+
if (!page)
|
|
844
|
+
return null;
|
|
845
|
+
allEvents.push(...page.data ?? []);
|
|
846
|
+
cursor = page.next_cursor;
|
|
847
|
+
} while (cursor);
|
|
848
|
+
logForDebugging(`CCRClient: Read ${allEvents.length} internal events from ${path}${params.subagents ? " (subagents)" : ""}`);
|
|
849
|
+
return allEvents;
|
|
850
|
+
}
|
|
851
|
+
async getWithRetry(url, authHeaders, context) {
|
|
852
|
+
for (let attempt = 1;attempt <= 10; attempt++) {
|
|
853
|
+
let response;
|
|
854
|
+
try {
|
|
855
|
+
response = await this.http.get(url, {
|
|
856
|
+
headers: {
|
|
857
|
+
...authHeaders,
|
|
858
|
+
"anthropic-version": "2023-06-01",
|
|
859
|
+
"User-Agent": getClaudeCodeUserAgent()
|
|
860
|
+
},
|
|
861
|
+
validateStatus: alwaysValidStatus,
|
|
862
|
+
timeout: 30000
|
|
863
|
+
});
|
|
864
|
+
} catch (error) {
|
|
865
|
+
logForDebugging(`CCRClient: GET ${url} failed (attempt ${attempt}/10): ${errorMessage(error)}`, { level: "warn" });
|
|
866
|
+
if (attempt < 10) {
|
|
867
|
+
const delay = Math.min(500 * 2 ** (attempt - 1), 30000) + Math.random() * 500;
|
|
868
|
+
await sleep(delay);
|
|
869
|
+
}
|
|
870
|
+
continue;
|
|
871
|
+
}
|
|
872
|
+
if (response.status >= 200 && response.status < 300) {
|
|
873
|
+
return response.data;
|
|
874
|
+
}
|
|
875
|
+
if (response.status === 409) {
|
|
876
|
+
this.handleEpochMismatch();
|
|
877
|
+
}
|
|
878
|
+
logForDebugging(`CCRClient: GET ${url} returned ${response.status} (attempt ${attempt}/10)`, { level: "warn" });
|
|
879
|
+
if (attempt < 10) {
|
|
880
|
+
const delay = Math.min(500 * 2 ** (attempt - 1), 30000) + Math.random() * 500;
|
|
881
|
+
await sleep(delay);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
logForDebugging("CCRClient: GET retries exhausted", { level: "error" });
|
|
885
|
+
logForDiagnosticsNoPII("error", "cli_worker_get_retries_exhausted", {
|
|
886
|
+
context
|
|
887
|
+
});
|
|
888
|
+
return null;
|
|
889
|
+
}
|
|
890
|
+
reportDelivery(eventId, status) {
|
|
891
|
+
this.deliveryUploader.enqueue({ eventId, status });
|
|
892
|
+
}
|
|
893
|
+
getWorkerEpoch() {
|
|
894
|
+
return this.workerEpoch;
|
|
895
|
+
}
|
|
896
|
+
get internalEventsPending() {
|
|
897
|
+
return this.internalEventUploader.pendingCount;
|
|
898
|
+
}
|
|
899
|
+
close() {
|
|
900
|
+
this.closed = true;
|
|
901
|
+
this.stopHeartbeat();
|
|
902
|
+
unregisterSessionActivityCallback();
|
|
903
|
+
if (this.streamEventTimer) {
|
|
904
|
+
clearTimeout(this.streamEventTimer);
|
|
905
|
+
this.streamEventTimer = null;
|
|
906
|
+
}
|
|
907
|
+
this.streamEventBuffer = [];
|
|
908
|
+
this.streamTextAccumulator.byMessage.clear();
|
|
909
|
+
this.streamTextAccumulator.scopeToMessage.clear();
|
|
910
|
+
this.workerState.close();
|
|
911
|
+
this.eventUploader.close();
|
|
912
|
+
this.internalEventUploader.close();
|
|
913
|
+
this.deliveryUploader.close();
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
// src/cli/transports/SSETransport.ts
|
|
918
|
+
init_axios();
|
|
919
|
+
init_debug();
|
|
920
|
+
init_diagLogs();
|
|
921
|
+
init_errors();
|
|
922
|
+
init_sessionIngressAuth();
|
|
923
|
+
init_sleep();
|
|
924
|
+
init_slowOperations();
|
|
925
|
+
init_userAgent();
|
|
926
|
+
var RECONNECT_BASE_DELAY_MS = 1000;
|
|
927
|
+
var RECONNECT_MAX_DELAY_MS = 30000;
|
|
928
|
+
var RECONNECT_GIVE_UP_MS = 600000;
|
|
929
|
+
var LIVENESS_TIMEOUT_MS = 45000;
|
|
930
|
+
var PERMANENT_HTTP_CODES = new Set([401, 403, 404]);
|
|
931
|
+
var POST_MAX_RETRIES = 10;
|
|
932
|
+
var POST_BASE_DELAY_MS = 500;
|
|
933
|
+
var POST_MAX_DELAY_MS = 8000;
|
|
934
|
+
var STREAM_DECODE_OPTS = { stream: true };
|
|
935
|
+
function alwaysValidStatus2() {
|
|
936
|
+
return true;
|
|
937
|
+
}
|
|
938
|
+
function parseSSEFrames(buffer) {
|
|
939
|
+
const frames = [];
|
|
940
|
+
let pos = 0;
|
|
941
|
+
let idx;
|
|
942
|
+
while ((idx = buffer.indexOf(`
|
|
943
|
+
|
|
944
|
+
`, pos)) !== -1) {
|
|
945
|
+
const rawFrame = buffer.slice(pos, idx);
|
|
946
|
+
pos = idx + 2;
|
|
947
|
+
if (!rawFrame.trim())
|
|
948
|
+
continue;
|
|
949
|
+
const frame = {};
|
|
950
|
+
let isComment = false;
|
|
951
|
+
for (const line of rawFrame.split(`
|
|
952
|
+
`)) {
|
|
953
|
+
if (line.startsWith(":")) {
|
|
954
|
+
isComment = true;
|
|
955
|
+
continue;
|
|
956
|
+
}
|
|
957
|
+
const colonIdx = line.indexOf(":");
|
|
958
|
+
if (colonIdx === -1)
|
|
959
|
+
continue;
|
|
960
|
+
const field = line.slice(0, colonIdx);
|
|
961
|
+
const value = line[colonIdx + 1] === " " ? line.slice(colonIdx + 2) : line.slice(colonIdx + 1);
|
|
962
|
+
switch (field) {
|
|
963
|
+
case "event":
|
|
964
|
+
frame.event = value;
|
|
965
|
+
break;
|
|
966
|
+
case "id":
|
|
967
|
+
frame.id = value;
|
|
968
|
+
break;
|
|
969
|
+
case "data":
|
|
970
|
+
frame.data = frame.data ? frame.data + `
|
|
971
|
+
` + value : value;
|
|
972
|
+
break;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
if (frame.data || isComment) {
|
|
976
|
+
frames.push(frame);
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
return { frames, remaining: buffer.slice(pos) };
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
class SSETransport {
|
|
983
|
+
url;
|
|
984
|
+
state = "idle";
|
|
985
|
+
onData;
|
|
986
|
+
onCloseCallback;
|
|
987
|
+
onEventCallback;
|
|
988
|
+
headers;
|
|
989
|
+
sessionId;
|
|
990
|
+
refreshHeaders;
|
|
991
|
+
getAuthHeaders;
|
|
992
|
+
abortController = null;
|
|
993
|
+
lastSequenceNum = 0;
|
|
994
|
+
seenSequenceNums = new Set;
|
|
995
|
+
reconnectAttempts = 0;
|
|
996
|
+
reconnectStartTime = null;
|
|
997
|
+
reconnectTimer = null;
|
|
998
|
+
livenessTimer = null;
|
|
999
|
+
postUrl;
|
|
1000
|
+
constructor(url, headers = {}, sessionId, refreshHeaders, initialSequenceNum, getAuthHeaders) {
|
|
1001
|
+
this.url = url;
|
|
1002
|
+
this.headers = headers;
|
|
1003
|
+
this.sessionId = sessionId;
|
|
1004
|
+
this.refreshHeaders = refreshHeaders;
|
|
1005
|
+
this.getAuthHeaders = getAuthHeaders ?? getSessionIngressAuthHeaders;
|
|
1006
|
+
this.postUrl = convertSSEUrlToPostUrl(url);
|
|
1007
|
+
if (initialSequenceNum !== undefined && initialSequenceNum > 0) {
|
|
1008
|
+
this.lastSequenceNum = initialSequenceNum;
|
|
1009
|
+
}
|
|
1010
|
+
logForDebugging(`SSETransport: SSE URL = ${url.href}`);
|
|
1011
|
+
logForDebugging(`SSETransport: POST URL = ${this.postUrl}`);
|
|
1012
|
+
logForDiagnosticsNoPII("info", "cli_sse_transport_initialized");
|
|
1013
|
+
}
|
|
1014
|
+
getLastSequenceNum() {
|
|
1015
|
+
return this.lastSequenceNum;
|
|
1016
|
+
}
|
|
1017
|
+
async connect() {
|
|
1018
|
+
if (this.state !== "idle" && this.state !== "reconnecting") {
|
|
1019
|
+
logForDebugging(`SSETransport: Cannot connect, current state is ${this.state}`, { level: "error" });
|
|
1020
|
+
logForDiagnosticsNoPII("error", "cli_sse_connect_failed");
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
this.state = "reconnecting";
|
|
1024
|
+
const connectStartTime = Date.now();
|
|
1025
|
+
const sseUrl = new URL(this.url.href);
|
|
1026
|
+
if (this.lastSequenceNum > 0) {
|
|
1027
|
+
sseUrl.searchParams.set("from_sequence_num", String(this.lastSequenceNum));
|
|
1028
|
+
}
|
|
1029
|
+
const authHeaders = this.getAuthHeaders();
|
|
1030
|
+
const headers = {
|
|
1031
|
+
...this.headers,
|
|
1032
|
+
...authHeaders,
|
|
1033
|
+
Accept: "text/event-stream",
|
|
1034
|
+
"anthropic-version": "2023-06-01",
|
|
1035
|
+
"User-Agent": getClaudeCodeUserAgent()
|
|
1036
|
+
};
|
|
1037
|
+
if (authHeaders["Cookie"]) {
|
|
1038
|
+
delete headers["Authorization"];
|
|
1039
|
+
}
|
|
1040
|
+
if (this.lastSequenceNum > 0) {
|
|
1041
|
+
headers["Last-Event-ID"] = String(this.lastSequenceNum);
|
|
1042
|
+
}
|
|
1043
|
+
logForDebugging(`SSETransport: Opening ${sseUrl.href}`);
|
|
1044
|
+
logForDiagnosticsNoPII("info", "cli_sse_connect_opening");
|
|
1045
|
+
this.abortController = new AbortController;
|
|
1046
|
+
try {
|
|
1047
|
+
const response = await fetch(sseUrl.href, {
|
|
1048
|
+
headers,
|
|
1049
|
+
signal: this.abortController.signal
|
|
1050
|
+
});
|
|
1051
|
+
if (!response.ok) {
|
|
1052
|
+
const isPermanent = PERMANENT_HTTP_CODES.has(response.status);
|
|
1053
|
+
logForDebugging(`SSETransport: HTTP ${response.status}${isPermanent ? " (permanent)" : ""}`, { level: "error" });
|
|
1054
|
+
logForDiagnosticsNoPII("error", "cli_sse_connect_http_error", {
|
|
1055
|
+
status: response.status
|
|
1056
|
+
});
|
|
1057
|
+
if (isPermanent) {
|
|
1058
|
+
this.state = "closed";
|
|
1059
|
+
this.onCloseCallback?.(response.status);
|
|
1060
|
+
return;
|
|
1061
|
+
}
|
|
1062
|
+
this.handleConnectionError();
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
if (!response.body) {
|
|
1066
|
+
logForDebugging("SSETransport: No response body");
|
|
1067
|
+
this.handleConnectionError();
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
const connectDuration = Date.now() - connectStartTime;
|
|
1071
|
+
logForDebugging("SSETransport: Connected");
|
|
1072
|
+
logForDiagnosticsNoPII("info", "cli_sse_connect_connected", {
|
|
1073
|
+
duration_ms: connectDuration
|
|
1074
|
+
});
|
|
1075
|
+
this.state = "connected";
|
|
1076
|
+
this.reconnectAttempts = 0;
|
|
1077
|
+
this.reconnectStartTime = null;
|
|
1078
|
+
this.resetLivenessTimer();
|
|
1079
|
+
await this.readStream(response.body);
|
|
1080
|
+
} catch (error) {
|
|
1081
|
+
if (this.abortController?.signal.aborted) {
|
|
1082
|
+
return;
|
|
1083
|
+
}
|
|
1084
|
+
logForDebugging(`SSETransport: Connection error: ${errorMessage(error)}`, { level: "error" });
|
|
1085
|
+
logForDiagnosticsNoPII("error", "cli_sse_connect_error");
|
|
1086
|
+
this.handleConnectionError();
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
async readStream(body) {
|
|
1090
|
+
const reader = body.getReader();
|
|
1091
|
+
const decoder = new TextDecoder;
|
|
1092
|
+
let buffer = "";
|
|
1093
|
+
try {
|
|
1094
|
+
while (true) {
|
|
1095
|
+
const { done, value } = await reader.read();
|
|
1096
|
+
if (done)
|
|
1097
|
+
break;
|
|
1098
|
+
buffer += decoder.decode(value, STREAM_DECODE_OPTS);
|
|
1099
|
+
const { frames, remaining } = parseSSEFrames(buffer);
|
|
1100
|
+
buffer = remaining;
|
|
1101
|
+
for (const frame of frames) {
|
|
1102
|
+
this.resetLivenessTimer();
|
|
1103
|
+
if (frame.id) {
|
|
1104
|
+
const seqNum = parseInt(frame.id, 10);
|
|
1105
|
+
if (!isNaN(seqNum)) {
|
|
1106
|
+
if (this.seenSequenceNums.has(seqNum)) {
|
|
1107
|
+
logForDebugging(`SSETransport: DUPLICATE frame seq=${seqNum} (lastSequenceNum=${this.lastSequenceNum}, seenCount=${this.seenSequenceNums.size})`, { level: "warn" });
|
|
1108
|
+
logForDiagnosticsNoPII("warn", "cli_sse_duplicate_sequence");
|
|
1109
|
+
} else {
|
|
1110
|
+
this.seenSequenceNums.add(seqNum);
|
|
1111
|
+
if (this.seenSequenceNums.size > 1000) {
|
|
1112
|
+
const threshold = this.lastSequenceNum - 200;
|
|
1113
|
+
for (const s of this.seenSequenceNums) {
|
|
1114
|
+
if (s < threshold) {
|
|
1115
|
+
this.seenSequenceNums.delete(s);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
if (seqNum > this.lastSequenceNum) {
|
|
1121
|
+
this.lastSequenceNum = seqNum;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
if (frame.event && frame.data) {
|
|
1126
|
+
this.handleSSEFrame(frame.event, frame.data);
|
|
1127
|
+
} else if (frame.data) {
|
|
1128
|
+
logForDebugging("SSETransport: Frame has data: but no event: field \u2014 dropped", { level: "warn" });
|
|
1129
|
+
logForDiagnosticsNoPII("warn", "cli_sse_frame_missing_event_field");
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
} catch (error) {
|
|
1134
|
+
if (this.abortController?.signal.aborted)
|
|
1135
|
+
return;
|
|
1136
|
+
logForDebugging(`SSETransport: Stream read error: ${errorMessage(error)}`, { level: "error" });
|
|
1137
|
+
logForDiagnosticsNoPII("error", "cli_sse_stream_read_error");
|
|
1138
|
+
} finally {
|
|
1139
|
+
reader.releaseLock();
|
|
1140
|
+
}
|
|
1141
|
+
if (this.state !== "closing" && this.state !== "closed") {
|
|
1142
|
+
logForDebugging("SSETransport: Stream ended, reconnecting");
|
|
1143
|
+
this.handleConnectionError();
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
handleSSEFrame(eventType, data) {
|
|
1147
|
+
if (eventType !== "client_event") {
|
|
1148
|
+
logForDebugging(`SSETransport: Unexpected SSE event type '${eventType}' on worker stream`, { level: "warn" });
|
|
1149
|
+
logForDiagnosticsNoPII("warn", "cli_sse_unexpected_event_type", {
|
|
1150
|
+
event_type: eventType
|
|
1151
|
+
});
|
|
1152
|
+
return;
|
|
1153
|
+
}
|
|
1154
|
+
let ev;
|
|
1155
|
+
try {
|
|
1156
|
+
ev = jsonParse(data);
|
|
1157
|
+
} catch (error) {
|
|
1158
|
+
logForDebugging(`SSETransport: Failed to parse client_event data: ${errorMessage(error)}`, { level: "error" });
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
const payload = ev.payload;
|
|
1162
|
+
if (payload && typeof payload === "object" && "type" in payload) {
|
|
1163
|
+
const sessionLabel = this.sessionId ? ` session=${this.sessionId}` : "";
|
|
1164
|
+
logForDebugging(`SSETransport: Event seq=${ev.sequence_num} event_id=${ev.event_id} event_type=${ev.event_type} payload_type=${String(payload.type)}${sessionLabel}`);
|
|
1165
|
+
logForDiagnosticsNoPII("info", "cli_sse_message_received");
|
|
1166
|
+
this.onData?.(jsonStringify(payload) + `
|
|
1167
|
+
`);
|
|
1168
|
+
} else {
|
|
1169
|
+
logForDebugging(`SSETransport: Ignoring client_event with no type in payload: event_id=${ev.event_id}`);
|
|
1170
|
+
}
|
|
1171
|
+
this.onEventCallback?.(ev);
|
|
1172
|
+
}
|
|
1173
|
+
handleConnectionError() {
|
|
1174
|
+
this.clearLivenessTimer();
|
|
1175
|
+
if (this.state === "closing" || this.state === "closed")
|
|
1176
|
+
return;
|
|
1177
|
+
this.abortController?.abort();
|
|
1178
|
+
this.abortController = null;
|
|
1179
|
+
const now = Date.now();
|
|
1180
|
+
if (!this.reconnectStartTime) {
|
|
1181
|
+
this.reconnectStartTime = now;
|
|
1182
|
+
}
|
|
1183
|
+
const elapsed = now - this.reconnectStartTime;
|
|
1184
|
+
if (elapsed < RECONNECT_GIVE_UP_MS) {
|
|
1185
|
+
if (this.reconnectTimer) {
|
|
1186
|
+
clearTimeout(this.reconnectTimer);
|
|
1187
|
+
this.reconnectTimer = null;
|
|
1188
|
+
}
|
|
1189
|
+
if (this.refreshHeaders) {
|
|
1190
|
+
const freshHeaders = this.refreshHeaders();
|
|
1191
|
+
Object.assign(this.headers, freshHeaders);
|
|
1192
|
+
logForDebugging("SSETransport: Refreshed headers for reconnect");
|
|
1193
|
+
}
|
|
1194
|
+
this.state = "reconnecting";
|
|
1195
|
+
this.reconnectAttempts++;
|
|
1196
|
+
const baseDelay = Math.min(RECONNECT_BASE_DELAY_MS * Math.pow(2, this.reconnectAttempts - 1), RECONNECT_MAX_DELAY_MS);
|
|
1197
|
+
const delay = Math.max(0, baseDelay + baseDelay * 0.25 * (2 * Math.random() - 1));
|
|
1198
|
+
logForDebugging(`SSETransport: Reconnecting in ${Math.round(delay)}ms (attempt ${this.reconnectAttempts}, ${Math.round(elapsed / 1000)}s elapsed)`);
|
|
1199
|
+
logForDiagnosticsNoPII("error", "cli_sse_reconnect_attempt", {
|
|
1200
|
+
reconnectAttempts: this.reconnectAttempts
|
|
1201
|
+
});
|
|
1202
|
+
this.reconnectTimer = setTimeout(() => {
|
|
1203
|
+
this.reconnectTimer = null;
|
|
1204
|
+
this.connect();
|
|
1205
|
+
}, delay);
|
|
1206
|
+
} else {
|
|
1207
|
+
logForDebugging(`SSETransport: Reconnection time budget exhausted after ${Math.round(elapsed / 1000)}s`, { level: "error" });
|
|
1208
|
+
logForDiagnosticsNoPII("error", "cli_sse_reconnect_exhausted", {
|
|
1209
|
+
reconnectAttempts: this.reconnectAttempts,
|
|
1210
|
+
elapsedMs: elapsed
|
|
1211
|
+
});
|
|
1212
|
+
this.state = "closed";
|
|
1213
|
+
this.onCloseCallback?.();
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
onLivenessTimeout = () => {
|
|
1217
|
+
this.livenessTimer = null;
|
|
1218
|
+
logForDebugging("SSETransport: Liveness timeout, reconnecting", {
|
|
1219
|
+
level: "error"
|
|
1220
|
+
});
|
|
1221
|
+
logForDiagnosticsNoPII("error", "cli_sse_liveness_timeout");
|
|
1222
|
+
this.abortController?.abort();
|
|
1223
|
+
this.handleConnectionError();
|
|
1224
|
+
};
|
|
1225
|
+
resetLivenessTimer() {
|
|
1226
|
+
this.clearLivenessTimer();
|
|
1227
|
+
this.livenessTimer = setTimeout(this.onLivenessTimeout, LIVENESS_TIMEOUT_MS);
|
|
1228
|
+
}
|
|
1229
|
+
clearLivenessTimer() {
|
|
1230
|
+
if (this.livenessTimer) {
|
|
1231
|
+
clearTimeout(this.livenessTimer);
|
|
1232
|
+
this.livenessTimer = null;
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
async write(message) {
|
|
1236
|
+
const authHeaders = this.getAuthHeaders();
|
|
1237
|
+
if (Object.keys(authHeaders).length === 0) {
|
|
1238
|
+
logForDebugging("SSETransport: No session token available for POST");
|
|
1239
|
+
logForDiagnosticsNoPII("warn", "cli_sse_post_no_token");
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1242
|
+
const headers = {
|
|
1243
|
+
...authHeaders,
|
|
1244
|
+
"Content-Type": "application/json",
|
|
1245
|
+
"anthropic-version": "2023-06-01",
|
|
1246
|
+
"User-Agent": getClaudeCodeUserAgent()
|
|
1247
|
+
};
|
|
1248
|
+
logForDebugging(`SSETransport: POST body keys=${Object.keys(message).join(",")}`);
|
|
1249
|
+
for (let attempt = 1;attempt <= POST_MAX_RETRIES; attempt++) {
|
|
1250
|
+
try {
|
|
1251
|
+
const response = await axios_default.post(this.postUrl, message, {
|
|
1252
|
+
headers,
|
|
1253
|
+
validateStatus: alwaysValidStatus2
|
|
1254
|
+
});
|
|
1255
|
+
if (response.status === 200 || response.status === 201) {
|
|
1256
|
+
logForDebugging(`SSETransport: POST success type=${message.type}`);
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1259
|
+
logForDebugging(`SSETransport: POST ${response.status} body=${jsonStringify(response.data).slice(0, 200)}`);
|
|
1260
|
+
if (response.status >= 400 && response.status < 500 && response.status !== 429) {
|
|
1261
|
+
logForDebugging(`SSETransport: POST returned ${response.status} (client error), not retrying`);
|
|
1262
|
+
logForDiagnosticsNoPII("warn", "cli_sse_post_client_error", {
|
|
1263
|
+
status: response.status
|
|
1264
|
+
});
|
|
1265
|
+
return;
|
|
1266
|
+
}
|
|
1267
|
+
logForDebugging(`SSETransport: POST returned ${response.status}, attempt ${attempt}/${POST_MAX_RETRIES}`);
|
|
1268
|
+
logForDiagnosticsNoPII("warn", "cli_sse_post_retryable_error", {
|
|
1269
|
+
status: response.status,
|
|
1270
|
+
attempt
|
|
1271
|
+
});
|
|
1272
|
+
} catch (error) {
|
|
1273
|
+
const axiosError = error;
|
|
1274
|
+
logForDebugging(`SSETransport: POST error: ${axiosError.message}, attempt ${attempt}/${POST_MAX_RETRIES}`);
|
|
1275
|
+
logForDiagnosticsNoPII("warn", "cli_sse_post_network_error", {
|
|
1276
|
+
attempt
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
if (attempt === POST_MAX_RETRIES) {
|
|
1280
|
+
logForDebugging(`SSETransport: POST failed after ${POST_MAX_RETRIES} attempts, continuing`);
|
|
1281
|
+
logForDiagnosticsNoPII("warn", "cli_sse_post_retries_exhausted");
|
|
1282
|
+
return;
|
|
1283
|
+
}
|
|
1284
|
+
const delayMs = Math.min(POST_BASE_DELAY_MS * Math.pow(2, attempt - 1), POST_MAX_DELAY_MS);
|
|
1285
|
+
await sleep(delayMs);
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
isConnectedStatus() {
|
|
1289
|
+
return this.state === "connected";
|
|
1290
|
+
}
|
|
1291
|
+
isClosedStatus() {
|
|
1292
|
+
return this.state === "closed";
|
|
1293
|
+
}
|
|
1294
|
+
setOnData(callback) {
|
|
1295
|
+
this.onData = callback;
|
|
1296
|
+
}
|
|
1297
|
+
setOnClose(callback) {
|
|
1298
|
+
this.onCloseCallback = callback;
|
|
1299
|
+
}
|
|
1300
|
+
setOnEvent(callback) {
|
|
1301
|
+
this.onEventCallback = callback;
|
|
1302
|
+
}
|
|
1303
|
+
close() {
|
|
1304
|
+
if (this.reconnectTimer) {
|
|
1305
|
+
clearTimeout(this.reconnectTimer);
|
|
1306
|
+
this.reconnectTimer = null;
|
|
1307
|
+
}
|
|
1308
|
+
this.clearLivenessTimer();
|
|
1309
|
+
this.state = "closing";
|
|
1310
|
+
this.abortController?.abort();
|
|
1311
|
+
this.abortController = null;
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
function convertSSEUrlToPostUrl(sseUrl) {
|
|
1315
|
+
let pathname = sseUrl.pathname;
|
|
1316
|
+
if (pathname.endsWith("/stream")) {
|
|
1317
|
+
pathname = pathname.slice(0, -"/stream".length);
|
|
1318
|
+
}
|
|
1319
|
+
return `${sseUrl.protocol}//${sseUrl.host}${pathname}`;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
export { createTokenRefreshScheduler, SerialBatchEventUploader, CCRInitError, CCRClient, SSETransport };
|