jialing-code 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -0
- package/dist/chunk-065m026w.js +97 -0
- package/dist/chunk-06saje2v.js +39 -0
- package/dist/chunk-0731m51q.js +8 -0
- package/dist/chunk-0975ccyw.js +265 -0
- package/dist/chunk-09n3fjx5.js +67 -0
- package/dist/chunk-0bdjdzew.js +41 -0
- package/dist/chunk-0ce6kd7y.js +212 -0
- package/dist/chunk-0e1xsncc.js +969 -0
- package/dist/chunk-0m2861gw.js +154 -0
- package/dist/chunk-0paqc2yw.js +15 -0
- package/dist/chunk-0rg6yrhy.js +99 -0
- package/dist/chunk-0sakxrcf.js +643 -0
- package/dist/chunk-0v9hwxvz.js +105 -0
- package/dist/chunk-0vkfrmqm.js +690 -0
- package/dist/chunk-0vvfnhhv.js +248 -0
- package/dist/chunk-0w4rsycj.js +145 -0
- package/dist/chunk-0x9b2nmd.js +63 -0
- package/dist/chunk-0xjaqda8.js +1124 -0
- package/dist/chunk-1141xmr4.js +8 -0
- package/dist/chunk-13d1842d.js +154 -0
- package/dist/chunk-1921a6yb.js +32 -0
- package/dist/chunk-1ad8mk9g.js +527 -0
- package/dist/chunk-1ax41pws.js +28 -0
- package/dist/chunk-1c8z1b5v.js +16 -0
- package/dist/chunk-1cbn5kxf.js +7 -0
- package/dist/chunk-1eapde8a.js +726 -0
- package/dist/chunk-1h2famwb.js +49 -0
- package/dist/chunk-1jggnf7z.js +85 -0
- package/dist/chunk-1k92pn9c.js +32 -0
- package/dist/chunk-1qakq4sn.js +802 -0
- package/dist/chunk-1rvz0433.js +722 -0
- package/dist/chunk-1xkekb9y.js +19 -0
- package/dist/chunk-238g70xa.js +36 -0
- package/dist/chunk-24ge0eqa.js +106 -0
- package/dist/chunk-278vghwm.js +5395 -0
- package/dist/chunk-27xc1csx.js +104 -0
- package/dist/chunk-2a42s11t.js +412 -0
- package/dist/chunk-2aa02aw6.js +438 -0
- package/dist/chunk-2eykm0j0.js +20 -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-2sd2w2h4.js +44 -0
- package/dist/chunk-2tw2ve8h.js +145 -0
- package/dist/chunk-30rst83v.js +168 -0
- package/dist/chunk-3aavh06g.js +1581 -0
- package/dist/chunk-3b0yvt2h.js +469 -0
- package/dist/chunk-3be7ka25.js +56 -0
- package/dist/chunk-3c25bcsw.js +17 -0
- package/dist/chunk-3dyxka97.js +584 -0
- package/dist/chunk-3f7rypmf.js +16544 -0
- package/dist/chunk-3fsd7f51.js +93 -0
- package/dist/chunk-3gqdqmzb.js +75 -0
- package/dist/chunk-3h8a89gy.js +46 -0
- package/dist/chunk-3m84sret.js +71 -0
- package/dist/chunk-3nb7j3js.js +96 -0
- package/dist/chunk-3p08nvn2.js +98 -0
- package/dist/chunk-3r09htpc.js +318 -0
- package/dist/chunk-3r24h7t6.js +113 -0
- package/dist/chunk-3rkfxjtq.js +80 -0
- package/dist/chunk-3tmk7dc2.js +604 -0
- package/dist/chunk-3w6s9m5w.js +16 -0
- package/dist/chunk-43qjymy5.js +92 -0
- package/dist/chunk-44fpr6jq.js +434 -0
- package/dist/chunk-45kxdsp8.js +444 -0
- package/dist/chunk-495d85x1.js +8066 -0
- package/dist/chunk-4ba796se.js +1095 -0
- package/dist/chunk-4g3v8y12.js +23 -0
- package/dist/chunk-4h53xj8n.js +3445 -0
- package/dist/chunk-4jm600zv.js +13 -0
- package/dist/chunk-4jy9dtwk.js +116 -0
- package/dist/chunk-4p60dd45.js +55 -0
- package/dist/chunk-4z0jsrqg.js +81 -0
- package/dist/chunk-4zfkzkt6.js +37 -0
- package/dist/chunk-55wgxwa9.js +13877 -0
- package/dist/chunk-5dbk24zg.js +890 -0
- package/dist/chunk-5hzvp4va.js +115 -0
- package/dist/chunk-5kbt1mbt.js +500 -0
- package/dist/chunk-5pen7vr8.js +176 -0
- package/dist/chunk-5r280eng.js +198 -0
- package/dist/chunk-5srym52s.js +88 -0
- package/dist/chunk-600kg7k6.js +41 -0
- package/dist/chunk-616w0qj3.js +160 -0
- package/dist/chunk-62jw1t8c.js +94 -0
- package/dist/chunk-62xmt9mk.js +372 -0
- package/dist/chunk-64bvg7c3.js +229 -0
- package/dist/chunk-65yhe4s0.js +281 -0
- package/dist/chunk-6aewh27m.js +102 -0
- package/dist/chunk-6bd8brc4.js +48 -0
- package/dist/chunk-6dj5t602.js +341 -0
- package/dist/chunk-6exxdk1p.js +6956 -0
- package/dist/chunk-6f5j8fs0.js +752 -0
- package/dist/chunk-6g62sjpf.js +328 -0
- package/dist/chunk-6gecq2ta.js +1493 -0
- package/dist/chunk-6gr3c3w9.js +378 -0
- package/dist/chunk-6kpbgc5w.js +23 -0
- package/dist/chunk-6kseqw79.js +154 -0
- package/dist/chunk-6mxm1qd0.js +40764 -0
- package/dist/chunk-6n2qgm9v.js +8 -0
- package/dist/chunk-6tq2v3rk.js +186 -0
- package/dist/chunk-6wsdhj3v.js +93 -0
- package/dist/chunk-6zw9fhgb.js +4389 -0
- package/dist/chunk-71grc1mw.js +111 -0
- package/dist/chunk-73rpbt04.js +1947 -0
- package/dist/chunk-748feghg.js +604 -0
- package/dist/chunk-75e8gtg9.js +84 -0
- package/dist/chunk-75th4717.js +780 -0
- package/dist/chunk-760252na.js +101 -0
- package/dist/chunk-7739pg2c.js +4261 -0
- package/dist/chunk-778fnx46.js +472 -0
- package/dist/chunk-77g09znh.js +391 -0
- package/dist/chunk-7aw745vx.js +40175 -0
- package/dist/chunk-7m2nd8da.js +110 -0
- package/dist/chunk-7n35vjtw.js +444 -0
- package/dist/chunk-7n5ss4sh.js +144 -0
- package/dist/chunk-7rjnxcfe.js +107 -0
- package/dist/chunk-7sb5axvf.js +122 -0
- package/dist/chunk-7wm5s02e.js +216 -0
- package/dist/chunk-7ymfj7m3.js +151 -0
- package/dist/chunk-7z8j9qfn.js +121 -0
- package/dist/chunk-7zsapntc.js +216 -0
- package/dist/chunk-805fhkfh.js +908 -0
- package/dist/chunk-80k1nj24.js +253 -0
- package/dist/chunk-83hfzbx3.js +10 -0
- package/dist/chunk-85cypsdd.js +92 -0
- package/dist/chunk-8760caxf.js +2644 -0
- package/dist/chunk-88f6egg6.js +387 -0
- package/dist/chunk-88r7kwgj.js +22 -0
- package/dist/chunk-89e1v45e.js +463 -0
- package/dist/chunk-8bedvdm1.js +32 -0
- package/dist/chunk-8c4x4vdz.js +177 -0
- package/dist/chunk-8hq5kk3y.js +44 -0
- package/dist/chunk-8ngxagxq.js +18 -0
- package/dist/chunk-8tnsngw2.js +31 -0
- package/dist/chunk-8wjnca8h.js +307 -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-92bp5bnf.js +650 -0
- package/dist/chunk-92q8sx5z.js +90 -0
- package/dist/chunk-958rtmtx.js +10476 -0
- package/dist/chunk-9e2kqv5g.js +125 -0
- package/dist/chunk-9f4f1hy5.js +281 -0
- package/dist/chunk-9gbamk79.js +93 -0
- package/dist/chunk-9k5s3ryh.js +167 -0
- package/dist/chunk-9xzfqm15.js +97 -0
- package/dist/chunk-9zgdvbm6.js +110 -0
- package/dist/chunk-a0p3q8jw.js +24 -0
- package/dist/chunk-a22sayzp.js +220 -0
- package/dist/chunk-a8ejc632.js +3094 -0
- package/dist/chunk-a8gj9d9z.js +120 -0
- package/dist/chunk-a9vdeb6y.js +258 -0
- package/dist/chunk-a9yev47v.js +674 -0
- package/dist/chunk-a9zh40sj.js +48 -0
- package/dist/chunk-ack5mfba.js +105 -0
- package/dist/chunk-ae76ded0.js +30 -0
- package/dist/chunk-akjw4dh6.js +538 -0
- package/dist/chunk-asc6wz4q.js +1188 -0
- package/dist/chunk-atqejh3p.js +273 -0
- package/dist/chunk-atv2e6b7.js +61 -0
- package/dist/chunk-axvvkwz8.js +1551 -0
- package/dist/chunk-azgz7kj9.js +38 -0
- package/dist/chunk-b3zave8q.js +275 -0
- package/dist/chunk-b4wg70y1.js +54 -0
- package/dist/chunk-b8b13qn2.js +100 -0
- package/dist/chunk-bg3mt9bm.js +28 -0
- package/dist/chunk-bh4jvcjn.js +91 -0
- package/dist/chunk-bhdt6k7w.js +15 -0
- package/dist/chunk-bm1qb16p.js +17 -0
- package/dist/chunk-bpvsd1j1.js +266 -0
- package/dist/chunk-bqfnp99q.js +477 -0
- package/dist/chunk-bsbmmfyt.js +17 -0
- package/dist/chunk-bsbt34jm.js +42 -0
- package/dist/chunk-c78akdhr.js +458 -0
- package/dist/chunk-cdz5yb0r.js +57 -0
- package/dist/chunk-cfv996bs.js +22 -0
- package/dist/chunk-cgfdkzhb.js +12 -0
- package/dist/chunk-ckh4r5er.js +257 -0
- package/dist/chunk-cmgjnvn9.js +89 -0
- package/dist/chunk-cpjgvay8.js +687 -0
- package/dist/chunk-crfryjx9.js +276 -0
- package/dist/chunk-ctw5jwcd.js +213 -0
- package/dist/chunk-cvy3vntc.js +65 -0
- package/dist/chunk-cwbzz504.js +94 -0
- package/dist/chunk-cy2hswr1.js +15 -0
- package/dist/chunk-cyejkay3.js +222 -0
- package/dist/chunk-d18z9pna.js +106 -0
- package/dist/chunk-d5cq0n0v.js +162 -0
- package/dist/chunk-db45aryp.js +50 -0
- package/dist/chunk-de8nqh0z.js +790 -0
- package/dist/chunk-dfw6h350.js +2336 -0
- package/dist/chunk-dgqrcy74.js +48 -0
- package/dist/chunk-dn75ptgd.js +184 -0
- package/dist/chunk-dnh7jtpb.js +37 -0
- package/dist/chunk-dpshyv9m.js +90 -0
- package/dist/chunk-dt8cdvnm.js +642 -0
- package/dist/chunk-dtxby6fr.js +306 -0
- package/dist/chunk-dv1wfr85.js +6373 -0
- package/dist/chunk-dw363edx.js +1154 -0
- package/dist/chunk-dwrdacck.js +62 -0
- package/dist/chunk-dxnnv5e3.js +276 -0
- package/dist/chunk-e3g8q4cn.js +1646 -0
- package/dist/chunk-e3m9k9s2.js +542 -0
- package/dist/chunk-e4q49asn.js +155 -0
- package/dist/chunk-e5pntxye.js +37 -0
- package/dist/chunk-e7393td6.js +42 -0
- package/dist/chunk-ead42yrh.js +87 -0
- package/dist/chunk-eb90vwvr.js +152 -0
- package/dist/chunk-ecvwk9hg.js +250 -0
- package/dist/chunk-edjd6aay.js +173 -0
- package/dist/chunk-eg0h8mtm.js +130 -0
- package/dist/chunk-ehtwnxpg.js +1591 -0
- package/dist/chunk-ek686gx1.js +94 -0
- package/dist/chunk-eqp1rfft.js +17 -0
- package/dist/chunk-evhwt0ar.js +1015 -0
- package/dist/chunk-ewadzrm8.js +103 -0
- package/dist/chunk-ewsgsw9h.js +172291 -0
- package/dist/chunk-f0pa0r7e.js +3198 -0
- package/dist/chunk-f2mhrmww.js +62 -0
- package/dist/chunk-f39zxvwn.js +401 -0
- package/dist/chunk-f46z54tq.js +374 -0
- package/dist/chunk-f5ma3nh5.js +3436 -0
- package/dist/chunk-f60q23az.js +3038 -0
- package/dist/chunk-f6v2nz57.js +107 -0
- package/dist/chunk-f6yjan38.js +38 -0
- package/dist/chunk-fbv4apne.js +51 -0
- package/dist/chunk-fem4s778.js +70 -0
- package/dist/chunk-fezm1kn8.js +376 -0
- package/dist/chunk-fm1n3ysp.js +6108 -0
- package/dist/chunk-frg83bfw.js +225 -0
- package/dist/chunk-fscm8db0.js +692 -0
- package/dist/chunk-fyc5fepv.js +10 -0
- package/dist/chunk-g0j0t6qk.js +26 -0
- package/dist/chunk-g0nc1ftf.js +849 -0
- package/dist/chunk-g338npwr.js +1061 -0
- package/dist/chunk-g3t0act8.js +8 -0
- package/dist/chunk-g75w4hw3.js +26 -0
- package/dist/chunk-g8vp82en.js +1866 -0
- package/dist/chunk-gax0fcbx.js +182 -0
- package/dist/chunk-gsz4dh3y.js +606 -0
- package/dist/chunk-gtfffm7h.js +440 -0
- package/dist/chunk-gver9zb9.js +420 -0
- package/dist/chunk-gyj242zr.js +20 -0
- package/dist/chunk-h0qngp9w.js +157 -0
- package/dist/chunk-h14kemnk.js +123 -0
- package/dist/chunk-h8wj1a74.js +8960 -0
- package/dist/chunk-h9mcb2eg.js +87 -0
- package/dist/chunk-h9nh2980.js +91 -0
- package/dist/chunk-hakdhagh.js +16606 -0
- package/dist/chunk-hbc6ymdv.js +55 -0
- package/dist/chunk-hh7cmy4k.js +20 -0
- package/dist/chunk-hjhc4cpt.js +69 -0
- package/dist/chunk-hjwez8qc.js +5018 -0
- package/dist/chunk-hk9xz7gk.js +118 -0
- package/dist/chunk-hqmz36b3.js +552 -0
- package/dist/chunk-hrzerbfw.js +1299 -0
- package/dist/chunk-hs8ph4p8.js +8 -0
- package/dist/chunk-ht1xwrnd.js +716 -0
- package/dist/chunk-hvmfg2dc.js +338 -0
- package/dist/chunk-hx2tr4ep.js +7189 -0
- package/dist/chunk-hzhe8ygc.js +547 -0
- package/dist/chunk-j2k4p94p.js +55 -0
- package/dist/chunk-j3a4p81y.js +184 -0
- package/dist/chunk-j49g6g3s.js +57 -0
- package/dist/chunk-j5d5hp9h.js +71 -0
- package/dist/chunk-j64ga6ta.js +8035 -0
- package/dist/chunk-j7tyxan1.js +116 -0
- package/dist/chunk-j8v4774z.js +424 -0
- package/dist/chunk-jafes477.js +29 -0
- package/dist/chunk-jd32zbps.js +15 -0
- package/dist/chunk-jdgeec04.js +4249 -0
- package/dist/chunk-jftd4jq5.js +4521 -0
- package/dist/chunk-jkxqhv6y.js +812 -0
- package/dist/chunk-jmfr6h0n.js +120 -0
- package/dist/chunk-jn4aabmx.js +40 -0
- package/dist/chunk-jnhkref0.js +30 -0
- package/dist/chunk-jsbpm1gz.js +27 -0
- package/dist/chunk-jtcyjc3k.js +5802 -0
- package/dist/chunk-jx817w05.js +11 -0
- package/dist/chunk-jzmz18nn.js +65 -0
- package/dist/chunk-k0p9w03v.js +4957 -0
- package/dist/chunk-k3dcdnck.js +89 -0
- package/dist/chunk-k3wadzcd.js +88 -0
- package/dist/chunk-kaeshsk1.js +713 -0
- package/dist/chunk-kbkey9ed.js +522 -0
- package/dist/chunk-kcwfhqbb.js +196 -0
- package/dist/chunk-key6jr7p.js +224 -0
- package/dist/chunk-knay8cy9.js +173 -0
- package/dist/chunk-kr3rg2y1.js +95 -0
- package/dist/chunk-kwekc97v.js +18 -0
- package/dist/chunk-m06q12hg.js +61 -0
- package/dist/chunk-m2mcpbhk.js +43 -0
- package/dist/chunk-m8v220gz.js +71 -0
- package/dist/chunk-mgpqy78h.js +208 -0
- package/dist/chunk-mkejwh4t.js +16 -0
- package/dist/chunk-mptyw5n1.js +107 -0
- package/dist/chunk-mqajm0dp.js +66 -0
- package/dist/chunk-mrksbgxj.js +490 -0
- package/dist/chunk-msjfc5ba.js +246 -0
- package/dist/chunk-mt25echc.js +6157 -0
- package/dist/chunk-mt3jfnr8.js +277 -0
- package/dist/chunk-mtn242d4.js +9300 -0
- package/dist/chunk-mzfkvave.js +169 -0
- package/dist/chunk-n0qaeaa5.js +256 -0
- package/dist/chunk-n1erf6kh.js +22820 -0
- package/dist/chunk-n2avk1r2.js +61 -0
- package/dist/chunk-n6atnpcq.js +765 -0
- package/dist/chunk-n7ttdtk0.js +641 -0
- package/dist/chunk-ncnfzby5.js +822 -0
- package/dist/chunk-ncnr1jtf.js +2058 -0
- package/dist/chunk-nerv0jvx.js +74 -0
- package/dist/chunk-ngd2abep.js +90 -0
- package/dist/chunk-nka1g8f4.js +773 -0
- package/dist/chunk-nnaxkc2z.js +128 -0
- package/dist/chunk-npyrtj8j.js +691 -0
- package/dist/chunk-nq0fxyxh.js +752 -0
- package/dist/chunk-nrmffak7.js +114 -0
- package/dist/chunk-nsz546wq.js +1170 -0
- package/dist/chunk-nt837qt9.js +21 -0
- package/dist/chunk-nv64x1z5.js +86 -0
- package/dist/chunk-nxsh6de2.js +1711 -0
- package/dist/chunk-nz4getcr.js +40 -0
- package/dist/chunk-p1f607pa.js +83 -0
- package/dist/chunk-p2816w9z.js +1486 -0
- package/dist/chunk-p2d5nh3g.js +342 -0
- package/dist/chunk-p4r5y02t.js +90 -0
- package/dist/chunk-p7g7pf3f.js +336 -0
- package/dist/chunk-pb4ad8r2.js +110 -0
- package/dist/chunk-pbrhz0zr.js +716 -0
- package/dist/chunk-ps49ymvj.js +43 -0
- package/dist/chunk-pwnt3veb.js +103 -0
- package/dist/chunk-pwwa7s62.js +11 -0
- package/dist/chunk-px3w0kde.js +299 -0
- package/dist/chunk-pzn777jb.js +756 -0
- package/dist/chunk-q25bjaev.js +15 -0
- package/dist/chunk-q5by3da6.js +8 -0
- package/dist/chunk-q6av622g.js +38 -0
- package/dist/chunk-q6xkvtf2.js +1318 -0
- package/dist/chunk-q81jx1tq.js +476 -0
- package/dist/chunk-qehb6fk5.js +339 -0
- package/dist/chunk-qj1avx1q.js +87 -0
- package/dist/chunk-qn2dxr66.js +105 -0
- package/dist/chunk-qnfx3qtx.js +617 -0
- package/dist/chunk-qp18kd4h.js +48 -0
- package/dist/chunk-qp2qdcda.js +100 -0
- package/dist/chunk-qpjy9tcf.js +133 -0
- package/dist/chunk-qqfa0dqg.js +2343 -0
- package/dist/chunk-qwh3htcz.js +202 -0
- package/dist/chunk-qz2x630m.js +49145 -0
- package/dist/chunk-r3vakcs1.js +496 -0
- package/dist/chunk-r66hz8j6.js +34 -0
- package/dist/chunk-r6b58y3x.js +17 -0
- package/dist/chunk-rekp48rk.js +62 -0
- package/dist/chunk-rn0v1hk8.js +34 -0
- package/dist/chunk-rs1xrs6m.js +534 -0
- package/dist/chunk-rs45skes.js +123 -0
- package/dist/chunk-rzszqp82.js +524 -0
- package/dist/chunk-s274nv8k.js +8 -0
- package/dist/chunk-s3pzvdss.js +50 -0
- package/dist/chunk-s9mesaw0.js +26840 -0
- package/dist/chunk-sd36yzx8.js +954 -0
- package/dist/chunk-sdj9b9wh.js +782 -0
- package/dist/chunk-sdw2q69p.js +227 -0
- package/dist/chunk-sfgp9cc0.js +130 -0
- package/dist/chunk-spqaamnc.js +63 -0
- package/dist/chunk-spzrs4df.js +73 -0
- package/dist/chunk-sxkr7k43.js +55 -0
- package/dist/chunk-szj5wvdy.js +28 -0
- package/dist/chunk-t0rgmccj.js +39 -0
- package/dist/chunk-t1nnzjgg.js +17 -0
- package/dist/chunk-t94fcnt8.js +566 -0
- package/dist/chunk-tjaqa99q.js +125 -0
- package/dist/chunk-tjq2evtw.js +328 -0
- package/dist/chunk-ts2p6bv1.js +224 -0
- package/dist/chunk-ttk5dzz8.js +25 -0
- package/dist/chunk-tw0q7ynt.js +59 -0
- package/dist/chunk-v02jkvgy.js +131 -0
- package/dist/chunk-v084bqt3.js +1529 -0
- package/dist/chunk-v0amythm.js +164 -0
- package/dist/chunk-v1kzp02e.js +785 -0
- package/dist/chunk-v1mgv1et.js +15 -0
- package/dist/chunk-v399mzxk.js +58 -0
- package/dist/chunk-v3gm2day.js +8 -0
- package/dist/chunk-v43hrrxp.js +71 -0
- package/dist/chunk-v6aqb2aj.js +102 -0
- package/dist/chunk-v78fj8by.js +145 -0
- package/dist/chunk-v7qmhjdn.js +1921 -0
- package/dist/chunk-v9smspw2.js +4301 -0
- package/dist/chunk-vdw93s4h.js +2431 -0
- package/dist/chunk-vest0y6x.js +3830 -0
- package/dist/chunk-vf5sd1nq.js +12 -0
- package/dist/chunk-vratq94g.js +349 -0
- package/dist/chunk-vrz7t3m3.js +20 -0
- package/dist/chunk-vtb185z9.js +70 -0
- package/dist/chunk-vx01rvg8.js +654 -0
- package/dist/chunk-vyc0rjyx.js +31 -0
- package/dist/chunk-vyjeh50y.js +2149 -0
- package/dist/chunk-vzpffsza.js +269 -0
- package/dist/chunk-w2ef3kxk.js +3353 -0
- package/dist/chunk-w2z5pqd3.js +336 -0
- package/dist/chunk-w3whm4mn.js +432 -0
- package/dist/chunk-w7wgpqcp.js +157 -0
- package/dist/chunk-waa00cvb.js +301 -0
- package/dist/chunk-wb0qm4es.js +155 -0
- package/dist/chunk-wbkahkdc.js +27 -0
- package/dist/chunk-wfz0qffj.js +3939 -0
- package/dist/chunk-wn0cx0pt.js +283 -0
- package/dist/chunk-wv6gzt9c.js +726 -0
- package/dist/chunk-wx42ycm4.js +998 -0
- package/dist/chunk-wxkpgy05.js +268 -0
- package/dist/chunk-wzpdet3m.js +843 -0
- package/dist/chunk-x0mwzt38.js +714 -0
- package/dist/chunk-x592wbfh.js +244 -0
- package/dist/chunk-x5pqsp9r.js +100 -0
- package/dist/chunk-x679thag.js +825 -0
- package/dist/chunk-x8b7vft8.js +132 -0
- package/dist/chunk-x8cftch7.js +119 -0
- package/dist/chunk-x9q7r885.js +348 -0
- package/dist/chunk-xawkt0vb.js +1585 -0
- package/dist/chunk-xdw5dv00.js +8 -0
- package/dist/chunk-xe9cc860.js +287 -0
- package/dist/chunk-xjr9c3vt.js +101 -0
- package/dist/chunk-xk7zaqta.js +21933 -0
- package/dist/chunk-xktbmawc.js +678 -0
- package/dist/chunk-xn6yw46v.js +140 -0
- package/dist/chunk-xsq9ae7x.js +90 -0
- package/dist/chunk-xszk7n10.js +14358 -0
- package/dist/chunk-xt8a5r1t.js +84 -0
- package/dist/chunk-xydyndkv.js +195 -0
- package/dist/chunk-xzt10yc5.js +60 -0
- package/dist/chunk-y04y95dr.js +91 -0
- package/dist/chunk-y1784krc.js +19 -0
- package/dist/chunk-y1x32h3x.js +128 -0
- package/dist/chunk-y3s7aww5.js +99 -0
- package/dist/chunk-y47cg3kz.js +42 -0
- package/dist/chunk-y7kzvepn.js +469 -0
- package/dist/chunk-y89kbsyc.js +287 -0
- package/dist/chunk-yd87p1c3.js +159 -0
- package/dist/chunk-yf3yw8fw.js +105 -0
- package/dist/chunk-ygbf0ezx.js +1391 -0
- package/dist/chunk-yjbxnshv.js +208 -0
- package/dist/chunk-ynednmqd.js +192 -0
- package/dist/chunk-yvhez44y.js +259 -0
- package/dist/chunk-ywxd4qw4.js +22 -0
- package/dist/chunk-yzrmgpy4.js +117 -0
- package/dist/chunk-z0b2vb24.js +862 -0
- package/dist/chunk-z1zj044v.js +655 -0
- package/dist/chunk-z2dp53wn.js +17 -0
- package/dist/chunk-z3w0xasa.js +165 -0
- package/dist/chunk-z7ycmrb3.js +644 -0
- package/dist/chunk-zh11tdkb.js +347 -0
- package/dist/chunk-zk2wsm7d.js +15 -0
- package/dist/chunk-zqfqcf22.js +229 -0
- package/dist/chunk-zqk2j8px.js +699 -0
- package/dist/chunk-zqvsc10j.js +2833 -0
- package/dist/chunk-zsfxha74.js +17655 -0
- package/dist/chunk-zvc4snyb.js +117 -0
- package/dist/cli.js +194 -0
- package/package.json +173 -0
|
@@ -0,0 +1,1188 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
decodeJwtExpiry
|
|
4
|
+
} from "./chunk-eb90vwvr.js";
|
|
5
|
+
import {
|
|
6
|
+
getSessionIngressAuthHeaders,
|
|
7
|
+
getSessionIngressAuthToken,
|
|
8
|
+
init_sessionActivity,
|
|
9
|
+
init_sessionIngressAuth,
|
|
10
|
+
registerSessionActivityCallback,
|
|
11
|
+
unregisterSessionActivityCallback
|
|
12
|
+
} from "./chunk-key6jr7p.js";
|
|
13
|
+
import {
|
|
14
|
+
getClaudeCodeUserAgent,
|
|
15
|
+
init_sleep,
|
|
16
|
+
init_userAgent,
|
|
17
|
+
sleep
|
|
18
|
+
} from "./chunk-3f7rypmf.js";
|
|
19
|
+
import {
|
|
20
|
+
createAxiosInstance,
|
|
21
|
+
init_proxy
|
|
22
|
+
} from "./chunk-1eapde8a.js";
|
|
23
|
+
import {
|
|
24
|
+
init_diagLogs,
|
|
25
|
+
logForDiagnosticsNoPII
|
|
26
|
+
} from "./chunk-hrzerbfw.js";
|
|
27
|
+
import {
|
|
28
|
+
errorMessage,
|
|
29
|
+
getErrnoCode,
|
|
30
|
+
init_debug,
|
|
31
|
+
init_errors,
|
|
32
|
+
init_slowOperations,
|
|
33
|
+
jsonParse,
|
|
34
|
+
jsonStringify,
|
|
35
|
+
logForDebugging
|
|
36
|
+
} from "./chunk-nxsh6de2.js";
|
|
37
|
+
import {
|
|
38
|
+
axios_default,
|
|
39
|
+
init_axios
|
|
40
|
+
} from "./chunk-xszk7n10.js";
|
|
41
|
+
|
|
42
|
+
// src/cli/transports/ccrClient.ts
|
|
43
|
+
import { randomUUID } from "crypto";
|
|
44
|
+
init_debug();
|
|
45
|
+
init_diagLogs();
|
|
46
|
+
init_errors();
|
|
47
|
+
init_proxy();
|
|
48
|
+
init_sessionActivity();
|
|
49
|
+
init_sessionIngressAuth();
|
|
50
|
+
init_sleep();
|
|
51
|
+
init_userAgent();
|
|
52
|
+
|
|
53
|
+
// src/cli/transports/SerialBatchEventUploader.ts
|
|
54
|
+
init_slowOperations();
|
|
55
|
+
|
|
56
|
+
class RetryableError extends Error {
|
|
57
|
+
retryAfterMs;
|
|
58
|
+
constructor(message, retryAfterMs) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.retryAfterMs = retryAfterMs;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
class SerialBatchEventUploader {
|
|
65
|
+
pending = [];
|
|
66
|
+
pendingAtClose = 0;
|
|
67
|
+
draining = false;
|
|
68
|
+
closed = false;
|
|
69
|
+
backpressureResolvers = [];
|
|
70
|
+
sleepResolve = null;
|
|
71
|
+
flushResolvers = [];
|
|
72
|
+
droppedBatches = 0;
|
|
73
|
+
config;
|
|
74
|
+
constructor(config) {
|
|
75
|
+
this.config = config;
|
|
76
|
+
}
|
|
77
|
+
get droppedBatchCount() {
|
|
78
|
+
return this.droppedBatches;
|
|
79
|
+
}
|
|
80
|
+
get pendingCount() {
|
|
81
|
+
return this.closed ? this.pendingAtClose : this.pending.length;
|
|
82
|
+
}
|
|
83
|
+
async enqueue(events) {
|
|
84
|
+
if (this.closed)
|
|
85
|
+
return;
|
|
86
|
+
const items = Array.isArray(events) ? events : [events];
|
|
87
|
+
if (items.length === 0)
|
|
88
|
+
return;
|
|
89
|
+
while (this.pending.length + items.length > this.config.maxQueueSize && !this.closed) {
|
|
90
|
+
await new Promise((resolve) => {
|
|
91
|
+
this.backpressureResolvers.push(resolve);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (this.closed)
|
|
95
|
+
return;
|
|
96
|
+
this.pending.push(...items);
|
|
97
|
+
this.drain();
|
|
98
|
+
}
|
|
99
|
+
flush() {
|
|
100
|
+
if (this.pending.length === 0 && !this.draining) {
|
|
101
|
+
return Promise.resolve();
|
|
102
|
+
}
|
|
103
|
+
this.drain();
|
|
104
|
+
return new Promise((resolve) => {
|
|
105
|
+
this.flushResolvers.push(resolve);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
close() {
|
|
109
|
+
if (this.closed)
|
|
110
|
+
return;
|
|
111
|
+
this.closed = true;
|
|
112
|
+
this.pendingAtClose = this.pending.length;
|
|
113
|
+
this.pending = [];
|
|
114
|
+
this.sleepResolve?.();
|
|
115
|
+
this.sleepResolve = null;
|
|
116
|
+
for (const resolve of this.backpressureResolvers)
|
|
117
|
+
resolve();
|
|
118
|
+
this.backpressureResolvers = [];
|
|
119
|
+
for (const resolve of this.flushResolvers)
|
|
120
|
+
resolve();
|
|
121
|
+
this.flushResolvers = [];
|
|
122
|
+
}
|
|
123
|
+
async drain() {
|
|
124
|
+
if (this.draining || this.closed)
|
|
125
|
+
return;
|
|
126
|
+
this.draining = true;
|
|
127
|
+
let failures = 0;
|
|
128
|
+
try {
|
|
129
|
+
while (this.pending.length > 0 && !this.closed) {
|
|
130
|
+
const batch = this.takeBatch();
|
|
131
|
+
if (batch.length === 0)
|
|
132
|
+
continue;
|
|
133
|
+
try {
|
|
134
|
+
await this.config.send(batch);
|
|
135
|
+
failures = 0;
|
|
136
|
+
} catch (err) {
|
|
137
|
+
failures++;
|
|
138
|
+
if (this.config.maxConsecutiveFailures !== undefined && failures >= this.config.maxConsecutiveFailures) {
|
|
139
|
+
this.droppedBatches++;
|
|
140
|
+
this.config.onBatchDropped?.(batch.length, failures);
|
|
141
|
+
failures = 0;
|
|
142
|
+
this.releaseBackpressure();
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
this.pending = batch.concat(this.pending);
|
|
146
|
+
const retryAfterMs = err instanceof RetryableError ? err.retryAfterMs : undefined;
|
|
147
|
+
await this.sleep(this.retryDelay(failures, retryAfterMs));
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
this.releaseBackpressure();
|
|
151
|
+
}
|
|
152
|
+
} finally {
|
|
153
|
+
this.draining = false;
|
|
154
|
+
if (this.pending.length === 0) {
|
|
155
|
+
for (const resolve of this.flushResolvers)
|
|
156
|
+
resolve();
|
|
157
|
+
this.flushResolvers = [];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
takeBatch() {
|
|
162
|
+
const { maxBatchSize, maxBatchBytes } = this.config;
|
|
163
|
+
if (maxBatchBytes === undefined) {
|
|
164
|
+
return this.pending.splice(0, maxBatchSize);
|
|
165
|
+
}
|
|
166
|
+
let bytes = 0;
|
|
167
|
+
let count = 0;
|
|
168
|
+
while (count < this.pending.length && count < maxBatchSize) {
|
|
169
|
+
let itemBytes;
|
|
170
|
+
try {
|
|
171
|
+
itemBytes = Buffer.byteLength(jsonStringify(this.pending[count]));
|
|
172
|
+
} catch {
|
|
173
|
+
this.pending.splice(count, 1);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (count > 0 && bytes + itemBytes > maxBatchBytes)
|
|
177
|
+
break;
|
|
178
|
+
bytes += itemBytes;
|
|
179
|
+
count++;
|
|
180
|
+
}
|
|
181
|
+
return this.pending.splice(0, count);
|
|
182
|
+
}
|
|
183
|
+
retryDelay(failures, retryAfterMs) {
|
|
184
|
+
const jitter = Math.random() * this.config.jitterMs;
|
|
185
|
+
if (retryAfterMs !== undefined) {
|
|
186
|
+
const clamped = Math.max(this.config.baseDelayMs, Math.min(retryAfterMs, this.config.maxDelayMs));
|
|
187
|
+
return clamped + jitter;
|
|
188
|
+
}
|
|
189
|
+
const exponential = Math.min(this.config.baseDelayMs * 2 ** (failures - 1), this.config.maxDelayMs);
|
|
190
|
+
return exponential + jitter;
|
|
191
|
+
}
|
|
192
|
+
releaseBackpressure() {
|
|
193
|
+
const resolvers = this.backpressureResolvers;
|
|
194
|
+
this.backpressureResolvers = [];
|
|
195
|
+
for (const resolve of resolvers)
|
|
196
|
+
resolve();
|
|
197
|
+
}
|
|
198
|
+
sleep(ms) {
|
|
199
|
+
return new Promise((resolve) => {
|
|
200
|
+
this.sleepResolve = resolve;
|
|
201
|
+
setTimeout((self, resolve2) => {
|
|
202
|
+
self.sleepResolve = null;
|
|
203
|
+
resolve2();
|
|
204
|
+
}, ms, this, resolve);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/cli/transports/WorkerStateUploader.ts
|
|
210
|
+
init_sleep();
|
|
211
|
+
|
|
212
|
+
class WorkerStateUploader {
|
|
213
|
+
inflight = null;
|
|
214
|
+
pending = null;
|
|
215
|
+
closed = false;
|
|
216
|
+
config;
|
|
217
|
+
constructor(config) {
|
|
218
|
+
this.config = config;
|
|
219
|
+
}
|
|
220
|
+
enqueue(patch) {
|
|
221
|
+
if (this.closed)
|
|
222
|
+
return;
|
|
223
|
+
this.pending = this.pending ? coalescePatches(this.pending, patch) : patch;
|
|
224
|
+
this.drain();
|
|
225
|
+
}
|
|
226
|
+
close() {
|
|
227
|
+
this.closed = true;
|
|
228
|
+
this.pending = null;
|
|
229
|
+
}
|
|
230
|
+
async drain() {
|
|
231
|
+
if (this.inflight || this.closed)
|
|
232
|
+
return;
|
|
233
|
+
if (!this.pending)
|
|
234
|
+
return;
|
|
235
|
+
const payload = this.pending;
|
|
236
|
+
this.pending = null;
|
|
237
|
+
this.inflight = this.sendWithRetry(payload).then(() => {
|
|
238
|
+
this.inflight = null;
|
|
239
|
+
if (this.pending && !this.closed) {
|
|
240
|
+
this.drain();
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
async sendWithRetry(payload) {
|
|
245
|
+
let current = payload;
|
|
246
|
+
let failures = 0;
|
|
247
|
+
while (!this.closed) {
|
|
248
|
+
const ok = await this.config.send(current);
|
|
249
|
+
if (ok)
|
|
250
|
+
return;
|
|
251
|
+
failures++;
|
|
252
|
+
await sleep(this.retryDelay(failures));
|
|
253
|
+
if (this.pending && !this.closed) {
|
|
254
|
+
current = coalescePatches(current, this.pending);
|
|
255
|
+
this.pending = null;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
retryDelay(failures) {
|
|
260
|
+
const exponential = Math.min(this.config.baseDelayMs * 2 ** (failures - 1), this.config.maxDelayMs);
|
|
261
|
+
const jitter = Math.random() * this.config.jitterMs;
|
|
262
|
+
return exponential + jitter;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function coalescePatches(base, overlay) {
|
|
266
|
+
const merged = { ...base };
|
|
267
|
+
for (const [key, value] of Object.entries(overlay)) {
|
|
268
|
+
if ((key === "external_metadata" || key === "internal_metadata") && merged[key] && typeof merged[key] === "object" && typeof value === "object" && value !== null) {
|
|
269
|
+
merged[key] = {
|
|
270
|
+
...merged[key],
|
|
271
|
+
...value
|
|
272
|
+
};
|
|
273
|
+
} else {
|
|
274
|
+
merged[key] = value;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return merged;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// src/cli/transports/ccrClient.ts
|
|
281
|
+
var DEFAULT_HEARTBEAT_INTERVAL_MS = 20000;
|
|
282
|
+
var STREAM_EVENT_FLUSH_INTERVAL_MS = 100;
|
|
283
|
+
function alwaysValidStatus() {
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
class CCRInitError extends Error {
|
|
288
|
+
reason;
|
|
289
|
+
constructor(reason) {
|
|
290
|
+
super(`CCRClient init failed: ${reason}`);
|
|
291
|
+
this.reason = reason;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
var MAX_CONSECUTIVE_AUTH_FAILURES = 10;
|
|
295
|
+
function createStreamAccumulator() {
|
|
296
|
+
return { byMessage: new Map, scopeToMessage: new Map };
|
|
297
|
+
}
|
|
298
|
+
function scopeKey(m) {
|
|
299
|
+
return `${m.session_id}:${m.parent_tool_use_id ?? ""}`;
|
|
300
|
+
}
|
|
301
|
+
function accumulateStreamEvents(buffer, state) {
|
|
302
|
+
const out = [];
|
|
303
|
+
const touched = new Map;
|
|
304
|
+
for (const msg of buffer) {
|
|
305
|
+
switch (msg.event.type) {
|
|
306
|
+
case "message_start": {
|
|
307
|
+
const id = msg.event.message.id;
|
|
308
|
+
const prevId = state.scopeToMessage.get(scopeKey(msg));
|
|
309
|
+
if (prevId)
|
|
310
|
+
state.byMessage.delete(prevId);
|
|
311
|
+
state.scopeToMessage.set(scopeKey(msg), id);
|
|
312
|
+
state.byMessage.set(id, []);
|
|
313
|
+
out.push(msg);
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
case "content_block_delta": {
|
|
317
|
+
if (msg.event.delta.type !== "text_delta") {
|
|
318
|
+
out.push(msg);
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
const messageId = state.scopeToMessage.get(scopeKey(msg));
|
|
322
|
+
const blocks = messageId ? state.byMessage.get(messageId) : undefined;
|
|
323
|
+
if (!blocks) {
|
|
324
|
+
out.push(msg);
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
const chunks = blocks[msg.event.index] ??= [];
|
|
328
|
+
chunks.push(msg.event.delta.text);
|
|
329
|
+
const existing = touched.get(chunks);
|
|
330
|
+
if (existing) {
|
|
331
|
+
existing.event.delta.text = chunks.join("");
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
const snapshot = {
|
|
335
|
+
type: "stream_event",
|
|
336
|
+
uuid: msg.uuid,
|
|
337
|
+
session_id: msg.session_id,
|
|
338
|
+
parent_tool_use_id: msg.parent_tool_use_id,
|
|
339
|
+
event: {
|
|
340
|
+
type: "content_block_delta",
|
|
341
|
+
index: msg.event.index,
|
|
342
|
+
delta: { type: "text_delta", text: chunks.join("") }
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
touched.set(chunks, snapshot);
|
|
346
|
+
out.push(snapshot);
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
default:
|
|
350
|
+
out.push(msg);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return out;
|
|
354
|
+
}
|
|
355
|
+
function clearStreamAccumulatorForMessage(state, assistant) {
|
|
356
|
+
state.byMessage.delete(assistant.message.id);
|
|
357
|
+
const scope = scopeKey(assistant);
|
|
358
|
+
if (state.scopeToMessage.get(scope) === assistant.message.id) {
|
|
359
|
+
state.scopeToMessage.delete(scope);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
class CCRClient {
|
|
364
|
+
workerEpoch = 0;
|
|
365
|
+
heartbeatIntervalMs;
|
|
366
|
+
heartbeatJitterFraction;
|
|
367
|
+
heartbeatTimer = null;
|
|
368
|
+
heartbeatInFlight = false;
|
|
369
|
+
closed = false;
|
|
370
|
+
consecutiveAuthFailures = 0;
|
|
371
|
+
currentState = null;
|
|
372
|
+
sessionBaseUrl;
|
|
373
|
+
sessionId;
|
|
374
|
+
http = createAxiosInstance({ keepAlive: true });
|
|
375
|
+
streamEventBuffer = [];
|
|
376
|
+
streamEventTimer = null;
|
|
377
|
+
streamTextAccumulator = createStreamAccumulator();
|
|
378
|
+
workerState;
|
|
379
|
+
eventUploader;
|
|
380
|
+
internalEventUploader;
|
|
381
|
+
deliveryUploader;
|
|
382
|
+
onEpochMismatch;
|
|
383
|
+
getAuthHeaders;
|
|
384
|
+
constructor(transport, sessionUrl, opts) {
|
|
385
|
+
this.onEpochMismatch = opts?.onEpochMismatch ?? (() => {
|
|
386
|
+
process.exit(1);
|
|
387
|
+
});
|
|
388
|
+
this.heartbeatIntervalMs = opts?.heartbeatIntervalMs ?? DEFAULT_HEARTBEAT_INTERVAL_MS;
|
|
389
|
+
this.heartbeatJitterFraction = opts?.heartbeatJitterFraction ?? 0;
|
|
390
|
+
this.getAuthHeaders = opts?.getAuthHeaders ?? getSessionIngressAuthHeaders;
|
|
391
|
+
if (sessionUrl.protocol !== "http:" && sessionUrl.protocol !== "https:") {
|
|
392
|
+
throw new Error(`CCRClient: Expected http(s) URL, got ${sessionUrl.protocol}`);
|
|
393
|
+
}
|
|
394
|
+
const pathname = sessionUrl.pathname.replace(/\/$/, "");
|
|
395
|
+
this.sessionBaseUrl = `${sessionUrl.protocol}//${sessionUrl.host}${pathname}`;
|
|
396
|
+
this.sessionId = pathname.split("/").pop() || "";
|
|
397
|
+
this.workerState = new WorkerStateUploader({
|
|
398
|
+
send: (body) => this.request("put", "/worker", { worker_epoch: this.workerEpoch, ...body }, "PUT worker").then((r) => r.ok),
|
|
399
|
+
baseDelayMs: 500,
|
|
400
|
+
maxDelayMs: 30000,
|
|
401
|
+
jitterMs: 500
|
|
402
|
+
});
|
|
403
|
+
this.eventUploader = new SerialBatchEventUploader({
|
|
404
|
+
maxBatchSize: 100,
|
|
405
|
+
maxBatchBytes: 10 * 1024 * 1024,
|
|
406
|
+
maxQueueSize: 1e5,
|
|
407
|
+
send: async (batch) => {
|
|
408
|
+
const result = await this.request("post", "/worker/events", { worker_epoch: this.workerEpoch, events: batch }, "client events");
|
|
409
|
+
if (!result.ok) {
|
|
410
|
+
throw new RetryableError("client event POST failed", result.retryAfterMs);
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
baseDelayMs: 500,
|
|
414
|
+
maxDelayMs: 30000,
|
|
415
|
+
jitterMs: 500
|
|
416
|
+
});
|
|
417
|
+
this.internalEventUploader = new SerialBatchEventUploader({
|
|
418
|
+
maxBatchSize: 100,
|
|
419
|
+
maxBatchBytes: 10 * 1024 * 1024,
|
|
420
|
+
maxQueueSize: 200,
|
|
421
|
+
send: async (batch) => {
|
|
422
|
+
const result = await this.request("post", "/worker/internal-events", { worker_epoch: this.workerEpoch, events: batch }, "internal events");
|
|
423
|
+
if (!result.ok) {
|
|
424
|
+
throw new RetryableError("internal event POST failed", result.retryAfterMs);
|
|
425
|
+
}
|
|
426
|
+
},
|
|
427
|
+
baseDelayMs: 500,
|
|
428
|
+
maxDelayMs: 30000,
|
|
429
|
+
jitterMs: 500
|
|
430
|
+
});
|
|
431
|
+
this.deliveryUploader = new SerialBatchEventUploader({
|
|
432
|
+
maxBatchSize: 64,
|
|
433
|
+
maxQueueSize: 64,
|
|
434
|
+
send: async (batch) => {
|
|
435
|
+
const result = await this.request("post", "/worker/events/delivery", {
|
|
436
|
+
worker_epoch: this.workerEpoch,
|
|
437
|
+
updates: batch.map((d) => ({
|
|
438
|
+
event_id: d.eventId,
|
|
439
|
+
status: d.status
|
|
440
|
+
}))
|
|
441
|
+
}, "delivery batch");
|
|
442
|
+
if (!result.ok) {
|
|
443
|
+
throw new RetryableError("delivery POST failed", result.retryAfterMs);
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
baseDelayMs: 500,
|
|
447
|
+
maxDelayMs: 30000,
|
|
448
|
+
jitterMs: 500
|
|
449
|
+
});
|
|
450
|
+
transport.setOnEvent((event) => {
|
|
451
|
+
this.reportDelivery(event.event_id, "received");
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
async initialize(epoch) {
|
|
455
|
+
const startMs = Date.now();
|
|
456
|
+
if (Object.keys(this.getAuthHeaders()).length === 0) {
|
|
457
|
+
throw new CCRInitError("no_auth_headers");
|
|
458
|
+
}
|
|
459
|
+
if (epoch === undefined) {
|
|
460
|
+
const rawEpoch = process.env.CLAUDE_CODE_WORKER_EPOCH;
|
|
461
|
+
epoch = rawEpoch ? parseInt(rawEpoch, 10) : NaN;
|
|
462
|
+
}
|
|
463
|
+
if (isNaN(epoch)) {
|
|
464
|
+
throw new CCRInitError("missing_epoch");
|
|
465
|
+
}
|
|
466
|
+
this.workerEpoch = epoch;
|
|
467
|
+
const restoredPromise = this.getWorkerState();
|
|
468
|
+
const result = await this.request("put", "/worker", {
|
|
469
|
+
worker_status: "idle",
|
|
470
|
+
worker_epoch: this.workerEpoch,
|
|
471
|
+
external_metadata: {
|
|
472
|
+
pending_action: null,
|
|
473
|
+
task_summary: null
|
|
474
|
+
}
|
|
475
|
+
}, "PUT worker (init)");
|
|
476
|
+
if (!result.ok) {
|
|
477
|
+
throw new CCRInitError("worker_register_failed");
|
|
478
|
+
}
|
|
479
|
+
this.currentState = "idle";
|
|
480
|
+
this.startHeartbeat();
|
|
481
|
+
registerSessionActivityCallback(() => {
|
|
482
|
+
this.writeEvent({ type: "keep_alive" });
|
|
483
|
+
});
|
|
484
|
+
logForDebugging(`CCRClient: initialized, epoch=${this.workerEpoch}`);
|
|
485
|
+
logForDiagnosticsNoPII("info", "cli_worker_lifecycle_initialized", {
|
|
486
|
+
epoch: this.workerEpoch,
|
|
487
|
+
duration_ms: Date.now() - startMs
|
|
488
|
+
});
|
|
489
|
+
const { metadata, durationMs } = await restoredPromise;
|
|
490
|
+
if (!this.closed) {
|
|
491
|
+
logForDiagnosticsNoPII("info", "cli_worker_state_restored", {
|
|
492
|
+
duration_ms: durationMs,
|
|
493
|
+
had_state: metadata !== null
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
return metadata;
|
|
497
|
+
}
|
|
498
|
+
async getWorkerState() {
|
|
499
|
+
const startMs = Date.now();
|
|
500
|
+
const authHeaders = this.getAuthHeaders();
|
|
501
|
+
if (Object.keys(authHeaders).length === 0) {
|
|
502
|
+
return { metadata: null, durationMs: 0 };
|
|
503
|
+
}
|
|
504
|
+
const data = await this.getWithRetry(`${this.sessionBaseUrl}/worker`, authHeaders, "worker_state");
|
|
505
|
+
return {
|
|
506
|
+
metadata: data?.worker?.external_metadata ?? null,
|
|
507
|
+
durationMs: Date.now() - startMs
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
async request(method, path, body, label, { timeout = 1e4 } = {}) {
|
|
511
|
+
const authHeaders = this.getAuthHeaders();
|
|
512
|
+
if (Object.keys(authHeaders).length === 0)
|
|
513
|
+
return { ok: false };
|
|
514
|
+
try {
|
|
515
|
+
const response = await this.http[method](`${this.sessionBaseUrl}${path}`, body, {
|
|
516
|
+
headers: {
|
|
517
|
+
...authHeaders,
|
|
518
|
+
"Content-Type": "application/json",
|
|
519
|
+
"anthropic-version": "2023-06-01",
|
|
520
|
+
"User-Agent": getClaudeCodeUserAgent()
|
|
521
|
+
},
|
|
522
|
+
validateStatus: alwaysValidStatus,
|
|
523
|
+
timeout
|
|
524
|
+
});
|
|
525
|
+
if (response.status >= 200 && response.status < 300) {
|
|
526
|
+
this.consecutiveAuthFailures = 0;
|
|
527
|
+
return { ok: true };
|
|
528
|
+
}
|
|
529
|
+
if (response.status === 409) {
|
|
530
|
+
this.handleEpochMismatch();
|
|
531
|
+
}
|
|
532
|
+
if (response.status === 401 || response.status === 403) {
|
|
533
|
+
const tok = getSessionIngressAuthToken();
|
|
534
|
+
const exp = tok ? decodeJwtExpiry(tok) : null;
|
|
535
|
+
if (exp !== null && exp * 1000 < Date.now()) {
|
|
536
|
+
logForDebugging(`CCRClient: session_token expired (exp=${new Date(exp * 1000).toISOString()}) \u2014 no refresh was delivered, exiting`, { level: "error" });
|
|
537
|
+
logForDiagnosticsNoPII("error", "cli_worker_token_expired_no_refresh");
|
|
538
|
+
this.onEpochMismatch();
|
|
539
|
+
}
|
|
540
|
+
this.consecutiveAuthFailures++;
|
|
541
|
+
if (this.consecutiveAuthFailures >= MAX_CONSECUTIVE_AUTH_FAILURES) {
|
|
542
|
+
logForDebugging(`CCRClient: ${this.consecutiveAuthFailures} consecutive auth failures with a valid-looking token \u2014 server-side auth unrecoverable, exiting`, { level: "error" });
|
|
543
|
+
logForDiagnosticsNoPII("error", "cli_worker_auth_failures_exhausted");
|
|
544
|
+
this.onEpochMismatch();
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
logForDebugging(`CCRClient: ${label} returned ${response.status}`, {
|
|
548
|
+
level: "warn"
|
|
549
|
+
});
|
|
550
|
+
logForDiagnosticsNoPII("warn", "cli_worker_request_failed", {
|
|
551
|
+
method,
|
|
552
|
+
path,
|
|
553
|
+
status: response.status
|
|
554
|
+
});
|
|
555
|
+
if (response.status === 429) {
|
|
556
|
+
const raw = response.headers?.["retry-after"];
|
|
557
|
+
const seconds = typeof raw === "string" ? parseInt(raw, 10) : NaN;
|
|
558
|
+
if (!isNaN(seconds) && seconds >= 0) {
|
|
559
|
+
return { ok: false, retryAfterMs: seconds * 1000 };
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
return { ok: false };
|
|
563
|
+
} catch (error) {
|
|
564
|
+
logForDebugging(`CCRClient: ${label} failed: ${errorMessage(error)}`, {
|
|
565
|
+
level: "warn"
|
|
566
|
+
});
|
|
567
|
+
logForDiagnosticsNoPII("warn", "cli_worker_request_error", {
|
|
568
|
+
method,
|
|
569
|
+
path,
|
|
570
|
+
error_code: getErrnoCode(error)
|
|
571
|
+
});
|
|
572
|
+
return { ok: false };
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
reportState(state, details) {
|
|
576
|
+
if (state === this.currentState && !details)
|
|
577
|
+
return;
|
|
578
|
+
this.currentState = state;
|
|
579
|
+
this.workerState.enqueue({
|
|
580
|
+
worker_status: state,
|
|
581
|
+
requires_action_details: details ? {
|
|
582
|
+
tool_name: details.tool_name,
|
|
583
|
+
action_description: details.action_description,
|
|
584
|
+
request_id: details.request_id
|
|
585
|
+
} : null
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
reportMetadata(metadata) {
|
|
589
|
+
this.workerState.enqueue({ external_metadata: metadata });
|
|
590
|
+
}
|
|
591
|
+
handleEpochMismatch() {
|
|
592
|
+
logForDebugging("CCRClient: Epoch mismatch (409), shutting down", {
|
|
593
|
+
level: "error"
|
|
594
|
+
});
|
|
595
|
+
logForDiagnosticsNoPII("error", "cli_worker_epoch_mismatch");
|
|
596
|
+
this.onEpochMismatch();
|
|
597
|
+
}
|
|
598
|
+
startHeartbeat() {
|
|
599
|
+
this.stopHeartbeat();
|
|
600
|
+
const schedule = () => {
|
|
601
|
+
const jitter = this.heartbeatIntervalMs * this.heartbeatJitterFraction * (2 * Math.random() - 1);
|
|
602
|
+
this.heartbeatTimer = setTimeout(tick, this.heartbeatIntervalMs + jitter);
|
|
603
|
+
};
|
|
604
|
+
const tick = () => {
|
|
605
|
+
this.sendHeartbeat();
|
|
606
|
+
if (this.heartbeatTimer === null)
|
|
607
|
+
return;
|
|
608
|
+
schedule();
|
|
609
|
+
};
|
|
610
|
+
schedule();
|
|
611
|
+
}
|
|
612
|
+
stopHeartbeat() {
|
|
613
|
+
if (this.heartbeatTimer) {
|
|
614
|
+
clearTimeout(this.heartbeatTimer);
|
|
615
|
+
this.heartbeatTimer = null;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
async sendHeartbeat() {
|
|
619
|
+
if (this.heartbeatInFlight)
|
|
620
|
+
return;
|
|
621
|
+
this.heartbeatInFlight = true;
|
|
622
|
+
try {
|
|
623
|
+
const result = await this.request("post", "/worker/heartbeat", { session_id: this.sessionId, worker_epoch: this.workerEpoch }, "Heartbeat", { timeout: 5000 });
|
|
624
|
+
if (result.ok) {
|
|
625
|
+
logForDebugging("CCRClient: Heartbeat sent");
|
|
626
|
+
}
|
|
627
|
+
} finally {
|
|
628
|
+
this.heartbeatInFlight = false;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
async writeEvent(message) {
|
|
632
|
+
if (message.type === "stream_event") {
|
|
633
|
+
this.streamEventBuffer.push(message);
|
|
634
|
+
if (!this.streamEventTimer) {
|
|
635
|
+
this.streamEventTimer = setTimeout(() => void this.flushStreamEventBuffer(), STREAM_EVENT_FLUSH_INTERVAL_MS);
|
|
636
|
+
}
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
await this.flushStreamEventBuffer();
|
|
640
|
+
if (message.type === "assistant") {
|
|
641
|
+
clearStreamAccumulatorForMessage(this.streamTextAccumulator, message);
|
|
642
|
+
}
|
|
643
|
+
await this.eventUploader.enqueue(this.toClientEvent(message));
|
|
644
|
+
}
|
|
645
|
+
toClientEvent(message) {
|
|
646
|
+
const msg = message;
|
|
647
|
+
return {
|
|
648
|
+
payload: {
|
|
649
|
+
...msg,
|
|
650
|
+
uuid: typeof msg.uuid === "string" ? msg.uuid : randomUUID()
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
async flushStreamEventBuffer() {
|
|
655
|
+
if (this.streamEventTimer) {
|
|
656
|
+
clearTimeout(this.streamEventTimer);
|
|
657
|
+
this.streamEventTimer = null;
|
|
658
|
+
}
|
|
659
|
+
if (this.streamEventBuffer.length === 0)
|
|
660
|
+
return;
|
|
661
|
+
const buffered = this.streamEventBuffer;
|
|
662
|
+
this.streamEventBuffer = [];
|
|
663
|
+
const payloads = accumulateStreamEvents(buffered, this.streamTextAccumulator);
|
|
664
|
+
await this.eventUploader.enqueue(payloads.map((payload) => ({ payload, ephemeral: true })));
|
|
665
|
+
}
|
|
666
|
+
async writeInternalEvent(eventType, payload, {
|
|
667
|
+
isCompaction = false,
|
|
668
|
+
agentId
|
|
669
|
+
} = {}) {
|
|
670
|
+
const event = {
|
|
671
|
+
payload: {
|
|
672
|
+
type: eventType,
|
|
673
|
+
...payload,
|
|
674
|
+
uuid: typeof payload.uuid === "string" ? payload.uuid : randomUUID()
|
|
675
|
+
},
|
|
676
|
+
...isCompaction && { is_compaction: true },
|
|
677
|
+
...agentId && { agent_id: agentId }
|
|
678
|
+
};
|
|
679
|
+
await this.internalEventUploader.enqueue(event);
|
|
680
|
+
}
|
|
681
|
+
flushInternalEvents() {
|
|
682
|
+
return this.internalEventUploader.flush();
|
|
683
|
+
}
|
|
684
|
+
async flush() {
|
|
685
|
+
await this.flushStreamEventBuffer();
|
|
686
|
+
return this.eventUploader.flush();
|
|
687
|
+
}
|
|
688
|
+
async readInternalEvents() {
|
|
689
|
+
return this.paginatedGet("/worker/internal-events", {}, "internal_events");
|
|
690
|
+
}
|
|
691
|
+
async readSubagentInternalEvents() {
|
|
692
|
+
return this.paginatedGet("/worker/internal-events", { subagents: "true" }, "subagent_events");
|
|
693
|
+
}
|
|
694
|
+
async paginatedGet(path, params, context) {
|
|
695
|
+
const authHeaders = this.getAuthHeaders();
|
|
696
|
+
if (Object.keys(authHeaders).length === 0)
|
|
697
|
+
return null;
|
|
698
|
+
const allEvents = [];
|
|
699
|
+
let cursor;
|
|
700
|
+
do {
|
|
701
|
+
const url = new URL(`${this.sessionBaseUrl}${path}`);
|
|
702
|
+
for (const [k, v] of Object.entries(params)) {
|
|
703
|
+
url.searchParams.set(k, v);
|
|
704
|
+
}
|
|
705
|
+
if (cursor) {
|
|
706
|
+
url.searchParams.set("cursor", cursor);
|
|
707
|
+
}
|
|
708
|
+
const page = await this.getWithRetry(url.toString(), authHeaders, context);
|
|
709
|
+
if (!page)
|
|
710
|
+
return null;
|
|
711
|
+
allEvents.push(...page.data ?? []);
|
|
712
|
+
cursor = page.next_cursor;
|
|
713
|
+
} while (cursor);
|
|
714
|
+
logForDebugging(`CCRClient: Read ${allEvents.length} internal events from ${path}${params.subagents ? " (subagents)" : ""}`);
|
|
715
|
+
return allEvents;
|
|
716
|
+
}
|
|
717
|
+
async getWithRetry(url, authHeaders, context) {
|
|
718
|
+
for (let attempt = 1;attempt <= 10; attempt++) {
|
|
719
|
+
let response;
|
|
720
|
+
try {
|
|
721
|
+
response = await this.http.get(url, {
|
|
722
|
+
headers: {
|
|
723
|
+
...authHeaders,
|
|
724
|
+
"anthropic-version": "2023-06-01",
|
|
725
|
+
"User-Agent": getClaudeCodeUserAgent()
|
|
726
|
+
},
|
|
727
|
+
validateStatus: alwaysValidStatus,
|
|
728
|
+
timeout: 30000
|
|
729
|
+
});
|
|
730
|
+
} catch (error) {
|
|
731
|
+
logForDebugging(`CCRClient: GET ${url} failed (attempt ${attempt}/10): ${errorMessage(error)}`, { level: "warn" });
|
|
732
|
+
if (attempt < 10) {
|
|
733
|
+
const delay = Math.min(500 * 2 ** (attempt - 1), 30000) + Math.random() * 500;
|
|
734
|
+
await sleep(delay);
|
|
735
|
+
}
|
|
736
|
+
continue;
|
|
737
|
+
}
|
|
738
|
+
if (response.status >= 200 && response.status < 300) {
|
|
739
|
+
return response.data;
|
|
740
|
+
}
|
|
741
|
+
if (response.status === 409) {
|
|
742
|
+
this.handleEpochMismatch();
|
|
743
|
+
}
|
|
744
|
+
logForDebugging(`CCRClient: GET ${url} returned ${response.status} (attempt ${attempt}/10)`, { level: "warn" });
|
|
745
|
+
if (attempt < 10) {
|
|
746
|
+
const delay = Math.min(500 * 2 ** (attempt - 1), 30000) + Math.random() * 500;
|
|
747
|
+
await sleep(delay);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
logForDebugging("CCRClient: GET retries exhausted", { level: "error" });
|
|
751
|
+
logForDiagnosticsNoPII("error", "cli_worker_get_retries_exhausted", {
|
|
752
|
+
context
|
|
753
|
+
});
|
|
754
|
+
return null;
|
|
755
|
+
}
|
|
756
|
+
reportDelivery(eventId, status) {
|
|
757
|
+
this.deliveryUploader.enqueue({ eventId, status });
|
|
758
|
+
}
|
|
759
|
+
getWorkerEpoch() {
|
|
760
|
+
return this.workerEpoch;
|
|
761
|
+
}
|
|
762
|
+
get internalEventsPending() {
|
|
763
|
+
return this.internalEventUploader.pendingCount;
|
|
764
|
+
}
|
|
765
|
+
close() {
|
|
766
|
+
this.closed = true;
|
|
767
|
+
this.stopHeartbeat();
|
|
768
|
+
unregisterSessionActivityCallback();
|
|
769
|
+
if (this.streamEventTimer) {
|
|
770
|
+
clearTimeout(this.streamEventTimer);
|
|
771
|
+
this.streamEventTimer = null;
|
|
772
|
+
}
|
|
773
|
+
this.streamEventBuffer = [];
|
|
774
|
+
this.streamTextAccumulator.byMessage.clear();
|
|
775
|
+
this.streamTextAccumulator.scopeToMessage.clear();
|
|
776
|
+
this.workerState.close();
|
|
777
|
+
this.eventUploader.close();
|
|
778
|
+
this.internalEventUploader.close();
|
|
779
|
+
this.deliveryUploader.close();
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
// src/cli/transports/SSETransport.ts
|
|
784
|
+
init_axios();
|
|
785
|
+
init_debug();
|
|
786
|
+
init_diagLogs();
|
|
787
|
+
init_errors();
|
|
788
|
+
init_sessionIngressAuth();
|
|
789
|
+
init_sleep();
|
|
790
|
+
init_slowOperations();
|
|
791
|
+
init_userAgent();
|
|
792
|
+
var RECONNECT_BASE_DELAY_MS = 1000;
|
|
793
|
+
var RECONNECT_MAX_DELAY_MS = 30000;
|
|
794
|
+
var RECONNECT_GIVE_UP_MS = 600000;
|
|
795
|
+
var LIVENESS_TIMEOUT_MS = 45000;
|
|
796
|
+
var PERMANENT_HTTP_CODES = new Set([401, 403, 404]);
|
|
797
|
+
var POST_MAX_RETRIES = 10;
|
|
798
|
+
var POST_BASE_DELAY_MS = 500;
|
|
799
|
+
var POST_MAX_DELAY_MS = 8000;
|
|
800
|
+
var STREAM_DECODE_OPTS = { stream: true };
|
|
801
|
+
function alwaysValidStatus2() {
|
|
802
|
+
return true;
|
|
803
|
+
}
|
|
804
|
+
function parseSSEFrames(buffer) {
|
|
805
|
+
const frames = [];
|
|
806
|
+
let pos = 0;
|
|
807
|
+
let idx;
|
|
808
|
+
while ((idx = buffer.indexOf(`
|
|
809
|
+
|
|
810
|
+
`, pos)) !== -1) {
|
|
811
|
+
const rawFrame = buffer.slice(pos, idx);
|
|
812
|
+
pos = idx + 2;
|
|
813
|
+
if (!rawFrame.trim())
|
|
814
|
+
continue;
|
|
815
|
+
const frame = {};
|
|
816
|
+
let isComment = false;
|
|
817
|
+
for (const line of rawFrame.split(`
|
|
818
|
+
`)) {
|
|
819
|
+
if (line.startsWith(":")) {
|
|
820
|
+
isComment = true;
|
|
821
|
+
continue;
|
|
822
|
+
}
|
|
823
|
+
const colonIdx = line.indexOf(":");
|
|
824
|
+
if (colonIdx === -1)
|
|
825
|
+
continue;
|
|
826
|
+
const field = line.slice(0, colonIdx);
|
|
827
|
+
const value = line[colonIdx + 1] === " " ? line.slice(colonIdx + 2) : line.slice(colonIdx + 1);
|
|
828
|
+
switch (field) {
|
|
829
|
+
case "event":
|
|
830
|
+
frame.event = value;
|
|
831
|
+
break;
|
|
832
|
+
case "id":
|
|
833
|
+
frame.id = value;
|
|
834
|
+
break;
|
|
835
|
+
case "data":
|
|
836
|
+
frame.data = frame.data ? frame.data + `
|
|
837
|
+
` + value : value;
|
|
838
|
+
break;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
if (frame.data || isComment) {
|
|
842
|
+
frames.push(frame);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
return { frames, remaining: buffer.slice(pos) };
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
class SSETransport {
|
|
849
|
+
url;
|
|
850
|
+
state = "idle";
|
|
851
|
+
onData;
|
|
852
|
+
onCloseCallback;
|
|
853
|
+
onEventCallback;
|
|
854
|
+
headers;
|
|
855
|
+
sessionId;
|
|
856
|
+
refreshHeaders;
|
|
857
|
+
getAuthHeaders;
|
|
858
|
+
abortController = null;
|
|
859
|
+
lastSequenceNum = 0;
|
|
860
|
+
seenSequenceNums = new Set;
|
|
861
|
+
reconnectAttempts = 0;
|
|
862
|
+
reconnectStartTime = null;
|
|
863
|
+
reconnectTimer = null;
|
|
864
|
+
livenessTimer = null;
|
|
865
|
+
postUrl;
|
|
866
|
+
constructor(url, headers = {}, sessionId, refreshHeaders, initialSequenceNum, getAuthHeaders) {
|
|
867
|
+
this.url = url;
|
|
868
|
+
this.headers = headers;
|
|
869
|
+
this.sessionId = sessionId;
|
|
870
|
+
this.refreshHeaders = refreshHeaders;
|
|
871
|
+
this.getAuthHeaders = getAuthHeaders ?? getSessionIngressAuthHeaders;
|
|
872
|
+
this.postUrl = convertSSEUrlToPostUrl(url);
|
|
873
|
+
if (initialSequenceNum !== undefined && initialSequenceNum > 0) {
|
|
874
|
+
this.lastSequenceNum = initialSequenceNum;
|
|
875
|
+
}
|
|
876
|
+
logForDebugging(`SSETransport: SSE URL = ${url.href}`);
|
|
877
|
+
logForDebugging(`SSETransport: POST URL = ${this.postUrl}`);
|
|
878
|
+
logForDiagnosticsNoPII("info", "cli_sse_transport_initialized");
|
|
879
|
+
}
|
|
880
|
+
getLastSequenceNum() {
|
|
881
|
+
return this.lastSequenceNum;
|
|
882
|
+
}
|
|
883
|
+
async connect() {
|
|
884
|
+
if (this.state !== "idle" && this.state !== "reconnecting") {
|
|
885
|
+
logForDebugging(`SSETransport: Cannot connect, current state is ${this.state}`, { level: "error" });
|
|
886
|
+
logForDiagnosticsNoPII("error", "cli_sse_connect_failed");
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
this.state = "reconnecting";
|
|
890
|
+
const connectStartTime = Date.now();
|
|
891
|
+
const sseUrl = new URL(this.url.href);
|
|
892
|
+
if (this.lastSequenceNum > 0) {
|
|
893
|
+
sseUrl.searchParams.set("from_sequence_num", String(this.lastSequenceNum));
|
|
894
|
+
}
|
|
895
|
+
const authHeaders = this.getAuthHeaders();
|
|
896
|
+
const headers = {
|
|
897
|
+
...this.headers,
|
|
898
|
+
...authHeaders,
|
|
899
|
+
Accept: "text/event-stream",
|
|
900
|
+
"anthropic-version": "2023-06-01",
|
|
901
|
+
"User-Agent": getClaudeCodeUserAgent()
|
|
902
|
+
};
|
|
903
|
+
if (authHeaders["Cookie"]) {
|
|
904
|
+
delete headers["Authorization"];
|
|
905
|
+
}
|
|
906
|
+
if (this.lastSequenceNum > 0) {
|
|
907
|
+
headers["Last-Event-ID"] = String(this.lastSequenceNum);
|
|
908
|
+
}
|
|
909
|
+
logForDebugging(`SSETransport: Opening ${sseUrl.href}`);
|
|
910
|
+
logForDiagnosticsNoPII("info", "cli_sse_connect_opening");
|
|
911
|
+
this.abortController = new AbortController;
|
|
912
|
+
try {
|
|
913
|
+
const response = await fetch(sseUrl.href, {
|
|
914
|
+
headers,
|
|
915
|
+
signal: this.abortController.signal
|
|
916
|
+
});
|
|
917
|
+
if (!response.ok) {
|
|
918
|
+
const isPermanent = PERMANENT_HTTP_CODES.has(response.status);
|
|
919
|
+
logForDebugging(`SSETransport: HTTP ${response.status}${isPermanent ? " (permanent)" : ""}`, { level: "error" });
|
|
920
|
+
logForDiagnosticsNoPII("error", "cli_sse_connect_http_error", {
|
|
921
|
+
status: response.status
|
|
922
|
+
});
|
|
923
|
+
if (isPermanent) {
|
|
924
|
+
this.state = "closed";
|
|
925
|
+
this.onCloseCallback?.(response.status);
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
this.handleConnectionError();
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
if (!response.body) {
|
|
932
|
+
logForDebugging("SSETransport: No response body");
|
|
933
|
+
this.handleConnectionError();
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
const connectDuration = Date.now() - connectStartTime;
|
|
937
|
+
logForDebugging("SSETransport: Connected");
|
|
938
|
+
logForDiagnosticsNoPII("info", "cli_sse_connect_connected", {
|
|
939
|
+
duration_ms: connectDuration
|
|
940
|
+
});
|
|
941
|
+
this.state = "connected";
|
|
942
|
+
this.reconnectAttempts = 0;
|
|
943
|
+
this.reconnectStartTime = null;
|
|
944
|
+
this.resetLivenessTimer();
|
|
945
|
+
await this.readStream(response.body);
|
|
946
|
+
} catch (error) {
|
|
947
|
+
if (this.abortController?.signal.aborted) {
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
logForDebugging(`SSETransport: Connection error: ${errorMessage(error)}`, { level: "error" });
|
|
951
|
+
logForDiagnosticsNoPII("error", "cli_sse_connect_error");
|
|
952
|
+
this.handleConnectionError();
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
async readStream(body) {
|
|
956
|
+
const reader = body.getReader();
|
|
957
|
+
const decoder = new TextDecoder;
|
|
958
|
+
let buffer = "";
|
|
959
|
+
try {
|
|
960
|
+
while (true) {
|
|
961
|
+
const { done, value } = await reader.read();
|
|
962
|
+
if (done)
|
|
963
|
+
break;
|
|
964
|
+
buffer += decoder.decode(value, STREAM_DECODE_OPTS);
|
|
965
|
+
const { frames, remaining } = parseSSEFrames(buffer);
|
|
966
|
+
buffer = remaining;
|
|
967
|
+
for (const frame of frames) {
|
|
968
|
+
this.resetLivenessTimer();
|
|
969
|
+
if (frame.id) {
|
|
970
|
+
const seqNum = parseInt(frame.id, 10);
|
|
971
|
+
if (!isNaN(seqNum)) {
|
|
972
|
+
if (this.seenSequenceNums.has(seqNum)) {
|
|
973
|
+
logForDebugging(`SSETransport: DUPLICATE frame seq=${seqNum} (lastSequenceNum=${this.lastSequenceNum}, seenCount=${this.seenSequenceNums.size})`, { level: "warn" });
|
|
974
|
+
logForDiagnosticsNoPII("warn", "cli_sse_duplicate_sequence");
|
|
975
|
+
} else {
|
|
976
|
+
this.seenSequenceNums.add(seqNum);
|
|
977
|
+
if (this.seenSequenceNums.size > 1000) {
|
|
978
|
+
const threshold = this.lastSequenceNum - 200;
|
|
979
|
+
for (const s of this.seenSequenceNums) {
|
|
980
|
+
if (s < threshold) {
|
|
981
|
+
this.seenSequenceNums.delete(s);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
if (seqNum > this.lastSequenceNum) {
|
|
987
|
+
this.lastSequenceNum = seqNum;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
if (frame.event && frame.data) {
|
|
992
|
+
this.handleSSEFrame(frame.event, frame.data);
|
|
993
|
+
} else if (frame.data) {
|
|
994
|
+
logForDebugging("SSETransport: Frame has data: but no event: field \u2014 dropped", { level: "warn" });
|
|
995
|
+
logForDiagnosticsNoPII("warn", "cli_sse_frame_missing_event_field");
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
} catch (error) {
|
|
1000
|
+
if (this.abortController?.signal.aborted)
|
|
1001
|
+
return;
|
|
1002
|
+
logForDebugging(`SSETransport: Stream read error: ${errorMessage(error)}`, { level: "error" });
|
|
1003
|
+
logForDiagnosticsNoPII("error", "cli_sse_stream_read_error");
|
|
1004
|
+
} finally {
|
|
1005
|
+
reader.releaseLock();
|
|
1006
|
+
}
|
|
1007
|
+
if (this.state !== "closing" && this.state !== "closed") {
|
|
1008
|
+
logForDebugging("SSETransport: Stream ended, reconnecting");
|
|
1009
|
+
this.handleConnectionError();
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
handleSSEFrame(eventType, data) {
|
|
1013
|
+
if (eventType !== "client_event") {
|
|
1014
|
+
logForDebugging(`SSETransport: Unexpected SSE event type '${eventType}' on worker stream`, { level: "warn" });
|
|
1015
|
+
logForDiagnosticsNoPII("warn", "cli_sse_unexpected_event_type", {
|
|
1016
|
+
event_type: eventType
|
|
1017
|
+
});
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
let ev;
|
|
1021
|
+
try {
|
|
1022
|
+
ev = jsonParse(data);
|
|
1023
|
+
} catch (error) {
|
|
1024
|
+
logForDebugging(`SSETransport: Failed to parse client_event data: ${errorMessage(error)}`, { level: "error" });
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
const payload = ev.payload;
|
|
1028
|
+
if (payload && typeof payload === "object" && "type" in payload) {
|
|
1029
|
+
const sessionLabel = this.sessionId ? ` session=${this.sessionId}` : "";
|
|
1030
|
+
logForDebugging(`SSETransport: Event seq=${ev.sequence_num} event_id=${ev.event_id} event_type=${ev.event_type} payload_type=${String(payload.type)}${sessionLabel}`);
|
|
1031
|
+
logForDiagnosticsNoPII("info", "cli_sse_message_received");
|
|
1032
|
+
this.onData?.(jsonStringify(payload) + `
|
|
1033
|
+
`);
|
|
1034
|
+
} else {
|
|
1035
|
+
logForDebugging(`SSETransport: Ignoring client_event with no type in payload: event_id=${ev.event_id}`);
|
|
1036
|
+
}
|
|
1037
|
+
this.onEventCallback?.(ev);
|
|
1038
|
+
}
|
|
1039
|
+
handleConnectionError() {
|
|
1040
|
+
this.clearLivenessTimer();
|
|
1041
|
+
if (this.state === "closing" || this.state === "closed")
|
|
1042
|
+
return;
|
|
1043
|
+
this.abortController?.abort();
|
|
1044
|
+
this.abortController = null;
|
|
1045
|
+
const now = Date.now();
|
|
1046
|
+
if (!this.reconnectStartTime) {
|
|
1047
|
+
this.reconnectStartTime = now;
|
|
1048
|
+
}
|
|
1049
|
+
const elapsed = now - this.reconnectStartTime;
|
|
1050
|
+
if (elapsed < RECONNECT_GIVE_UP_MS) {
|
|
1051
|
+
if (this.reconnectTimer) {
|
|
1052
|
+
clearTimeout(this.reconnectTimer);
|
|
1053
|
+
this.reconnectTimer = null;
|
|
1054
|
+
}
|
|
1055
|
+
if (this.refreshHeaders) {
|
|
1056
|
+
const freshHeaders = this.refreshHeaders();
|
|
1057
|
+
Object.assign(this.headers, freshHeaders);
|
|
1058
|
+
logForDebugging("SSETransport: Refreshed headers for reconnect");
|
|
1059
|
+
}
|
|
1060
|
+
this.state = "reconnecting";
|
|
1061
|
+
this.reconnectAttempts++;
|
|
1062
|
+
const baseDelay = Math.min(RECONNECT_BASE_DELAY_MS * Math.pow(2, this.reconnectAttempts - 1), RECONNECT_MAX_DELAY_MS);
|
|
1063
|
+
const delay = Math.max(0, baseDelay + baseDelay * 0.25 * (2 * Math.random() - 1));
|
|
1064
|
+
logForDebugging(`SSETransport: Reconnecting in ${Math.round(delay)}ms (attempt ${this.reconnectAttempts}, ${Math.round(elapsed / 1000)}s elapsed)`);
|
|
1065
|
+
logForDiagnosticsNoPII("error", "cli_sse_reconnect_attempt", {
|
|
1066
|
+
reconnectAttempts: this.reconnectAttempts
|
|
1067
|
+
});
|
|
1068
|
+
this.reconnectTimer = setTimeout(() => {
|
|
1069
|
+
this.reconnectTimer = null;
|
|
1070
|
+
this.connect();
|
|
1071
|
+
}, delay);
|
|
1072
|
+
} else {
|
|
1073
|
+
logForDebugging(`SSETransport: Reconnection time budget exhausted after ${Math.round(elapsed / 1000)}s`, { level: "error" });
|
|
1074
|
+
logForDiagnosticsNoPII("error", "cli_sse_reconnect_exhausted", {
|
|
1075
|
+
reconnectAttempts: this.reconnectAttempts,
|
|
1076
|
+
elapsedMs: elapsed
|
|
1077
|
+
});
|
|
1078
|
+
this.state = "closed";
|
|
1079
|
+
this.onCloseCallback?.();
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
onLivenessTimeout = () => {
|
|
1083
|
+
this.livenessTimer = null;
|
|
1084
|
+
logForDebugging("SSETransport: Liveness timeout, reconnecting", {
|
|
1085
|
+
level: "error"
|
|
1086
|
+
});
|
|
1087
|
+
logForDiagnosticsNoPII("error", "cli_sse_liveness_timeout");
|
|
1088
|
+
this.abortController?.abort();
|
|
1089
|
+
this.handleConnectionError();
|
|
1090
|
+
};
|
|
1091
|
+
resetLivenessTimer() {
|
|
1092
|
+
this.clearLivenessTimer();
|
|
1093
|
+
this.livenessTimer = setTimeout(this.onLivenessTimeout, LIVENESS_TIMEOUT_MS);
|
|
1094
|
+
}
|
|
1095
|
+
clearLivenessTimer() {
|
|
1096
|
+
if (this.livenessTimer) {
|
|
1097
|
+
clearTimeout(this.livenessTimer);
|
|
1098
|
+
this.livenessTimer = null;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
async write(message) {
|
|
1102
|
+
const authHeaders = this.getAuthHeaders();
|
|
1103
|
+
if (Object.keys(authHeaders).length === 0) {
|
|
1104
|
+
logForDebugging("SSETransport: No session token available for POST");
|
|
1105
|
+
logForDiagnosticsNoPII("warn", "cli_sse_post_no_token");
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
const headers = {
|
|
1109
|
+
...authHeaders,
|
|
1110
|
+
"Content-Type": "application/json",
|
|
1111
|
+
"anthropic-version": "2023-06-01",
|
|
1112
|
+
"User-Agent": getClaudeCodeUserAgent()
|
|
1113
|
+
};
|
|
1114
|
+
logForDebugging(`SSETransport: POST body keys=${Object.keys(message).join(",")}`);
|
|
1115
|
+
for (let attempt = 1;attempt <= POST_MAX_RETRIES; attempt++) {
|
|
1116
|
+
try {
|
|
1117
|
+
const response = await axios_default.post(this.postUrl, message, {
|
|
1118
|
+
headers,
|
|
1119
|
+
validateStatus: alwaysValidStatus2
|
|
1120
|
+
});
|
|
1121
|
+
if (response.status === 200 || response.status === 201) {
|
|
1122
|
+
logForDebugging(`SSETransport: POST success type=${message.type}`);
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
logForDebugging(`SSETransport: POST ${response.status} body=${jsonStringify(response.data).slice(0, 200)}`);
|
|
1126
|
+
if (response.status >= 400 && response.status < 500 && response.status !== 429) {
|
|
1127
|
+
logForDebugging(`SSETransport: POST returned ${response.status} (client error), not retrying`);
|
|
1128
|
+
logForDiagnosticsNoPII("warn", "cli_sse_post_client_error", {
|
|
1129
|
+
status: response.status
|
|
1130
|
+
});
|
|
1131
|
+
return;
|
|
1132
|
+
}
|
|
1133
|
+
logForDebugging(`SSETransport: POST returned ${response.status}, attempt ${attempt}/${POST_MAX_RETRIES}`);
|
|
1134
|
+
logForDiagnosticsNoPII("warn", "cli_sse_post_retryable_error", {
|
|
1135
|
+
status: response.status,
|
|
1136
|
+
attempt
|
|
1137
|
+
});
|
|
1138
|
+
} catch (error) {
|
|
1139
|
+
const axiosError = error;
|
|
1140
|
+
logForDebugging(`SSETransport: POST error: ${axiosError.message}, attempt ${attempt}/${POST_MAX_RETRIES}`);
|
|
1141
|
+
logForDiagnosticsNoPII("warn", "cli_sse_post_network_error", {
|
|
1142
|
+
attempt
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
if (attempt === POST_MAX_RETRIES) {
|
|
1146
|
+
logForDebugging(`SSETransport: POST failed after ${POST_MAX_RETRIES} attempts, continuing`);
|
|
1147
|
+
logForDiagnosticsNoPII("warn", "cli_sse_post_retries_exhausted");
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
const delayMs = Math.min(POST_BASE_DELAY_MS * Math.pow(2, attempt - 1), POST_MAX_DELAY_MS);
|
|
1151
|
+
await sleep(delayMs);
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
isConnectedStatus() {
|
|
1155
|
+
return this.state === "connected";
|
|
1156
|
+
}
|
|
1157
|
+
isClosedStatus() {
|
|
1158
|
+
return this.state === "closed";
|
|
1159
|
+
}
|
|
1160
|
+
setOnData(callback) {
|
|
1161
|
+
this.onData = callback;
|
|
1162
|
+
}
|
|
1163
|
+
setOnClose(callback) {
|
|
1164
|
+
this.onCloseCallback = callback;
|
|
1165
|
+
}
|
|
1166
|
+
setOnEvent(callback) {
|
|
1167
|
+
this.onEventCallback = callback;
|
|
1168
|
+
}
|
|
1169
|
+
close() {
|
|
1170
|
+
if (this.reconnectTimer) {
|
|
1171
|
+
clearTimeout(this.reconnectTimer);
|
|
1172
|
+
this.reconnectTimer = null;
|
|
1173
|
+
}
|
|
1174
|
+
this.clearLivenessTimer();
|
|
1175
|
+
this.state = "closing";
|
|
1176
|
+
this.abortController?.abort();
|
|
1177
|
+
this.abortController = null;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
function convertSSEUrlToPostUrl(sseUrl) {
|
|
1181
|
+
let pathname = sseUrl.pathname;
|
|
1182
|
+
if (pathname.endsWith("/stream")) {
|
|
1183
|
+
pathname = pathname.slice(0, -"/stream".length);
|
|
1184
|
+
}
|
|
1185
|
+
return `${sseUrl.protocol}//${sseUrl.host}${pathname}`;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
export { SerialBatchEventUploader, CCRInitError, CCRClient, SSETransport };
|