@jayjiang/open-cc 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +8 -0
- package/README.md +107 -0
- package/dist/chunk-00dxqxqj.js +227 -0
- package/dist/chunk-01p8hhsp.js +154 -0
- package/dist/chunk-02wy0m47.js +152 -0
- package/dist/chunk-0465tnzh.js +110 -0
- package/dist/chunk-054mjk62.js +678 -0
- package/dist/chunk-06saje2v.js +39 -0
- package/dist/chunk-0731m51q.js +8 -0
- package/dist/chunk-09y0jvtm.js +165 -0
- package/dist/chunk-0fkqze0v.js +113 -0
- package/dist/chunk-0hn525br.js +1920 -0
- package/dist/chunk-0hneh9ha.js +123 -0
- package/dist/chunk-0paqc2yw.js +15 -0
- package/dist/chunk-0rkbrabt.js +32 -0
- package/dist/chunk-0scs4rpx.js +96 -0
- package/dist/chunk-0vkfrmqm.js +690 -0
- package/dist/chunk-0w2byc95.js +38 -0
- package/dist/chunk-0xjaqda8.js +1124 -0
- package/dist/chunk-0y3vcsv4.js +92 -0
- package/dist/chunk-0yb4dz9c.js +26840 -0
- package/dist/chunk-10fdxge0.js +121 -0
- package/dist/chunk-1141xmr4.js +8 -0
- package/dist/chunk-14vffdmg.js +38 -0
- package/dist/chunk-178ykx7k.js +1493 -0
- package/dist/chunk-1bhva2z9.js +128 -0
- package/dist/chunk-1c8z1b5v.js +16 -0
- package/dist/chunk-1cbn5kxf.js +7 -0
- package/dist/chunk-1che51a5.js +1585 -0
- package/dist/chunk-1h2famwb.js +49 -0
- package/dist/chunk-1jrkpnbn.js +71 -0
- package/dist/chunk-1k4j1xcf.js +154 -0
- package/dist/chunk-1mm9d8p4.js +70 -0
- package/dist/chunk-1n3gnn2t.js +41 -0
- package/dist/chunk-1nqaq1rs.js +654 -0
- package/dist/chunk-1p2j9g3w.js +998 -0
- package/dist/chunk-1p7jfcee.js +533 -0
- package/dist/chunk-1pg8s12r.js +338 -0
- package/dist/chunk-1qjb22fx.js +109 -0
- package/dist/chunk-1yzc16qa.js +39 -0
- package/dist/chunk-20gm89wf.js +208 -0
- package/dist/chunk-238g70xa.js +36 -0
- package/dist/chunk-26k0324b.js +751 -0
- package/dist/chunk-27xc1csx.js +104 -0
- package/dist/chunk-2a42s11t.js +412 -0
- package/dist/chunk-2bhq4emw.js +10476 -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-2kpzaa7w.js +401 -0
- package/dist/chunk-2nayx6q1.js +63 -0
- package/dist/chunk-2qhs9n36.js +151 -0
- package/dist/chunk-2s5f2nnw.js +603 -0
- package/dist/chunk-2y54j9ew.js +174394 -0
- package/dist/chunk-2zcaw1jd.js +2343 -0
- package/dist/chunk-30chpfyc.js +15275 -0
- package/dist/chunk-30k39xd2.js +28 -0
- package/dist/chunk-30rst83v.js +168 -0
- package/dist/chunk-36z5enc4.js +160 -0
- package/dist/chunk-3c25bcsw.js +17 -0
- package/dist/chunk-3c4qja3e.js +63 -0
- package/dist/chunk-3ccx8k84.js +102 -0
- package/dist/chunk-3envnthj.js +157 -0
- package/dist/chunk-3h8a89gy.js +46 -0
- package/dist/chunk-3kadbep2.js +6956 -0
- package/dist/chunk-3kd79cnk.js +15 -0
- package/dist/chunk-3m45xtza.js +1188 -0
- package/dist/chunk-3q50xe1j.js +17 -0
- package/dist/chunk-3w6s9m5w.js +16 -0
- package/dist/chunk-3x0408tc.js +42 -0
- package/dist/chunk-3z7ae04g.js +372 -0
- package/dist/chunk-40tedt0y.js +275 -0
- package/dist/chunk-44q8kegv.js +811 -0
- package/dist/chunk-47gy6qkp.js +328 -0
- package/dist/chunk-495d85x1.js +8066 -0
- package/dist/chunk-4axcksrv.js +129 -0
- package/dist/chunk-4e1271a8.js +106 -0
- package/dist/chunk-4g3v8y12.js +23 -0
- package/dist/chunk-4g5mrzm0.js +220 -0
- package/dist/chunk-4jm600zv.js +13 -0
- package/dist/chunk-4n989n6h.js +153 -0
- package/dist/chunk-4qedx22a.js +44 -0
- package/dist/chunk-4rze71rx.js +116 -0
- package/dist/chunk-4wbhvcag.js +91 -0
- package/dist/chunk-4zfkzkt6.js +37 -0
- package/dist/chunk-55wgxwa9.js +13877 -0
- package/dist/chunk-56ta4h0b.js +154 -0
- package/dist/chunk-58a0x39g.js +89 -0
- package/dist/chunk-5dbk24zg.js +890 -0
- package/dist/chunk-5gzg4q1k.js +99 -0
- package/dist/chunk-5k2gdxnr.js +336 -0
- package/dist/chunk-5kp252z6.js +202 -0
- package/dist/chunk-5p2ssw3d.js +825 -0
- package/dist/chunk-5w33j8gy.js +1580 -0
- package/dist/chunk-5ywjzvm8.js +61 -0
- package/dist/chunk-5ztxx8gd.js +80 -0
- package/dist/chunk-62vwr0y5.js +117 -0
- package/dist/chunk-6b8ksqmf.js +1153 -0
- package/dist/chunk-6bd8brc4.js +48 -0
- package/dist/chunk-6cpqmd4r.js +132 -0
- package/dist/chunk-6dj5t602.js +341 -0
- package/dist/chunk-6g62sjpf.js +328 -0
- package/dist/chunk-6gr3c3w9.js +378 -0
- package/dist/chunk-6h9n8qbr.js +1170 -0
- package/dist/chunk-6kpbgc5w.js +23 -0
- package/dist/chunk-6n2qgm9v.js +8 -0
- package/dist/chunk-6n6jfmce.js +2833 -0
- package/dist/chunk-6q2x8zeg.js +802 -0
- package/dist/chunk-6tnekwtp.js +849 -0
- package/dist/chunk-6tq2v3rk.js +186 -0
- package/dist/chunk-6vphqqd1.js +27 -0
- package/dist/chunk-6wkdqk81.js +444 -0
- package/dist/chunk-7226mgjt.js +195 -0
- package/dist/chunk-72fey14y.js +565 -0
- package/dist/chunk-73fgm72g.js +698 -0
- package/dist/chunk-73fhat5j.js +212 -0
- package/dist/chunk-73rpbt04.js +1947 -0
- package/dist/chunk-743znc5c.js +56 -0
- package/dist/chunk-760252na.js +101 -0
- package/dist/chunk-76t2h5v2.js +495 -0
- package/dist/chunk-7739pg2c.js +4261 -0
- package/dist/chunk-789khc7a.js +96 -0
- package/dist/chunk-78mma1s7.js +88 -0
- package/dist/chunk-7aw745vx.js +40175 -0
- package/dist/chunk-7azp8c8y.js +584 -0
- package/dist/chunk-7m2nd8da.js +110 -0
- package/dist/chunk-7pemewz2.js +726 -0
- package/dist/chunk-7rjyn5d3.js +125 -0
- package/dist/chunk-7v0wq9nk.js +93 -0
- package/dist/chunk-7wm5s02e.js +216 -0
- package/dist/chunk-83hfzbx3.js +10 -0
- package/dist/chunk-84k64e4a.js +1646 -0
- package/dist/chunk-87jfpcm7.js +438 -0
- package/dist/chunk-8btm871b.js +42 -0
- package/dist/chunk-8hbbzet5.js +34 -0
- package/dist/chunk-8hq5kk3y.js +44 -0
- package/dist/chunk-8j6vs75t.js +256 -0
- package/dist/chunk-8ngxagxq.js +18 -0
- package/dist/chunk-8nsem424.js +110 -0
- package/dist/chunk-8pf73pc8.js +169 -0
- package/dist/chunk-8tnsngw2.js +31 -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-95dt8mpg.js +603 -0
- package/dist/chunk-95rj8m4e.js +130 -0
- package/dist/chunk-9ebygqen.js +89 -0
- package/dist/chunk-9gbamk79.js +93 -0
- package/dist/chunk-9tkq3g56.js +642 -0
- package/dist/chunk-a05hje2h.js +105 -0
- package/dist/chunk-a2krhf3c.js +90 -0
- package/dist/chunk-a6q9rehn.js +182 -0
- package/dist/chunk-a78b3pvt.js +71 -0
- package/dist/chunk-a8ejc632.js +3094 -0
- package/dist/chunk-a9vdeb6y.js +258 -0
- package/dist/chunk-a9zh40sj.js +48 -0
- package/dist/chunk-ab59azrr.js +480 -0
- package/dist/chunk-accxhkm6.js +88 -0
- package/dist/chunk-adzd8pzb.js +1095 -0
- package/dist/chunk-ae76ded0.js +30 -0
- package/dist/chunk-aftppv3p.js +691 -0
- package/dist/chunk-agmw1vmf.js +725 -0
- package/dist/chunk-an5cb1vx.js +16 -0
- package/dist/chunk-b1s11z4y.js +63 -0
- package/dist/chunk-b2rkh01x.js +443 -0
- package/dist/chunk-b4w4argn.js +1551 -0
- package/dist/chunk-b4wg70y1.js +54 -0
- package/dist/chunk-b5b7h81y.js +7189 -0
- package/dist/chunk-b9k5cs09.js +50 -0
- package/dist/chunk-bapy5rc8.js +40 -0
- package/dist/chunk-bda3gxxz.js +246 -0
- package/dist/chunk-bhdt6k7w.js +15 -0
- package/dist/chunk-bm1qb16p.js +17 -0
- package/dist/chunk-bp0dnrwg.js +281 -0
- package/dist/chunk-bqfnp99q.js +477 -0
- package/dist/chunk-bs6keys0.js +158 -0
- package/dist/chunk-bsbmmfyt.js +17 -0
- package/dist/chunk-btkettbr.js +166 -0
- package/dist/chunk-bwgde7nf.js +37 -0
- package/dist/chunk-c1zc58pw.js +280 -0
- package/dist/chunk-c2g96ga2.js +184 -0
- package/dist/chunk-c3z7ptb2.js +21933 -0
- package/dist/chunk-c8vn3ynx.js +349 -0
- package/dist/chunk-cdm0k2n0.js +115 -0
- package/dist/chunk-cdz5yb0r.js +57 -0
- package/dist/chunk-cfv996bs.js +22 -0
- package/dist/chunk-cg788ab0.js +100 -0
- package/dist/chunk-cgfdkzhb.js +12 -0
- package/dist/chunk-cp76dsdp.js +386 -0
- package/dist/chunk-cr6t6rth.js +306 -0
- package/dist/chunk-cvp5vayb.js +31 -0
- package/dist/chunk-cwehsmj5.js +114 -0
- package/dist/chunk-cy2hswr1.js +15 -0
- package/dist/chunk-d2rzy2p0.js +42 -0
- package/dist/chunk-d3v2fbay.js +106 -0
- package/dist/chunk-dc4eha8a.js +243 -0
- package/dist/chunk-dcz167d6.js +73 -0
- package/dist/chunk-de55jjre.js +106 -0
- package/dist/chunk-dfx733j3.js +650 -0
- package/dist/chunk-dgqrcy74.js +48 -0
- package/dist/chunk-dj6dk19k.js +55 -0
- package/dist/chunk-dn2xcmc4.js +173 -0
- package/dist/chunk-dndehvfr.js +57 -0
- package/dist/chunk-dnh7jtpb.js +37 -0
- package/dist/chunk-dnwzz9f7.js +88 -0
- package/dist/chunk-dv1wfr85.js +6373 -0
- package/dist/chunk-dwq5rs3q.js +62 -0
- package/dist/chunk-dz8exe78.js +91 -0
- package/dist/chunk-e4rzw1sd.js +606 -0
- package/dist/chunk-e6rrwzv0.js +463 -0
- package/dist/chunk-e6t9kpzq.js +145 -0
- package/dist/chunk-e7c8ypwc.js +287 -0
- package/dist/chunk-e9nkfs4e.js +738 -0
- package/dist/chunk-eaf7c8ck.js +537 -0
- package/dist/chunk-ebyr6p77.js +115 -0
- package/dist/chunk-edfv7pme.js +104 -0
- package/dist/chunk-eh474zhj.js +59 -0
- package/dist/chunk-er8ckwzt.js +140 -0
- package/dist/chunk-ev5p07yh.js +144 -0
- package/dist/chunk-ewadzrm8.js +103 -0
- package/dist/chunk-f2mhrmww.js +62 -0
- package/dist/chunk-f2zhqnb6.js +69 -0
- package/dist/chunk-f5ma3nh5.js +3436 -0
- package/dist/chunk-f63q7vx7.js +756 -0
- package/dist/chunk-fbv4apne.js +51 -0
- package/dist/chunk-fcna95wg.js +113 -0
- package/dist/chunk-fdvcpaz3.js +163 -0
- package/dist/chunk-fgc0q2b2.js +3354 -0
- package/dist/chunk-fm2jvsk7.js +87 -0
- package/dist/chunk-ft7fs35e.js +282 -0
- package/dist/chunk-fyc5fepv.js +10 -0
- package/dist/chunk-g0j0t6qk.js +26 -0
- package/dist/chunk-g0nbec9m.js +32 -0
- package/dist/chunk-g1fdv1kb.js +86 -0
- package/dist/chunk-g338npwr.js +1061 -0
- package/dist/chunk-g3t0act8.js +8 -0
- package/dist/chunk-g6qddbvf.js +1391 -0
- package/dist/chunk-ga5faygf.js +61 -0
- package/dist/chunk-gac6nzhc.js +90 -0
- package/dist/chunk-gck2cswd.js +862 -0
- package/dist/chunk-gntr3b25.js +40683 -0
- package/dist/chunk-gq5bbtme.js +456 -0
- package/dist/chunk-gyj242zr.js +20 -0
- package/dist/chunk-h0qngp9w.js +157 -0
- package/dist/chunk-h1xnvnye.js +524 -0
- package/dist/chunk-h3mhfamg.js +60 -0
- package/dist/chunk-h6s1tx0e.js +250 -0
- package/dist/chunk-h7qb4hyj.js +70 -0
- package/dist/chunk-h8qd1gw2.js +106 -0
- package/dist/chunk-hakdhagh.js +16606 -0
- package/dist/chunk-hcdt34n4.js +143 -0
- package/dist/chunk-hh7cmy4k.js +20 -0
- package/dist/chunk-hk9xz7gk.js +118 -0
- package/dist/chunk-hqmz36b3.js +552 -0
- package/dist/chunk-hs8ph4p8.js +8 -0
- package/dist/chunk-hsq4vtjy.js +92 -0
- package/dist/chunk-hzhd0p1y.js +104 -0
- package/dist/chunk-hzhe8ygc.js +547 -0
- package/dist/chunk-j0tqbsh7.js +176 -0
- package/dist/chunk-j1s1jvad.js +346 -0
- package/dist/chunk-j2k4p94p.js +55 -0
- package/dist/chunk-j3a4p81y.js +184 -0
- package/dist/chunk-j595yd4h.js +439 -0
- package/dist/chunk-j64ga6ta.js +8035 -0
- package/dist/chunk-j7qwxra8.js +2335 -0
- package/dist/chunk-j98f65zv.js +789 -0
- package/dist/chunk-jd32zbps.js +15 -0
- package/dist/chunk-jdgeec04.js +4249 -0
- package/dist/chunk-jdt5s5k7.js +62 -0
- package/dist/chunk-jeaek018.js +97 -0
- package/dist/chunk-jkhvm8yk.js +104 -0
- package/dist/chunk-jmxaze30.js +780 -0
- package/dist/chunk-jne71s1f.js +104 -0
- package/dist/chunk-jnhkref0.js +30 -0
- package/dist/chunk-jpgr7zfs.js +95 -0
- package/dist/chunk-jqp0q5nk.js +339 -0
- package/dist/chunk-jtqgnyaq.js +1317 -0
- package/dist/chunk-jx817w05.js +11 -0
- package/dist/chunk-jynzr5w9.js +71 -0
- package/dist/chunk-jzmz18nn.js +65 -0
- package/dist/chunk-k0p9w03v.js +4957 -0
- package/dist/chunk-k1jnpyj9.js +155 -0
- package/dist/chunk-k445en8h.js +102 -0
- package/dist/chunk-k62k13ya.js +81 -0
- package/dist/chunk-kf8kjmfv.js +821 -0
- package/dist/chunk-kgn1nfg9.js +468 -0
- package/dist/chunk-khmz14d4.js +38 -0
- package/dist/chunk-kjhmt6ba.js +100 -0
- package/dist/chunk-kkrz2zw2.js +122 -0
- package/dist/chunk-kv1ryvtm.js +176 -0
- package/dist/chunk-kwekc97v.js +18 -0
- package/dist/chunk-kyvwf342.js +65 -0
- package/dist/chunk-m0g3xv72.js +266 -0
- package/dist/chunk-m26twd8m.js +277 -0
- package/dist/chunk-m4bc15mz.js +229 -0
- package/dist/chunk-m9t8j37k.js +253 -0
- package/dist/chunk-mb2gpwwf.js +432 -0
- package/dist/chunk-mezwt1bt.js +306 -0
- package/dist/chunk-mfm83xn5.js +84 -0
- package/dist/chunk-mn7870fh.js +4389 -0
- package/dist/chunk-mr9df5v8.js +722 -0
- package/dist/chunk-mt25echc.js +6157 -0
- package/dist/chunk-mwrr6zbb.js +55 -0
- package/dist/chunk-mywpbwad.js +198 -0
- package/dist/chunk-mzdtkccs.js +125 -0
- package/dist/chunk-mzn0z9d3.js +691 -0
- package/dist/chunk-n0qaeaa5.js +256 -0
- package/dist/chunk-n128bzxs.js +2739 -0
- package/dist/chunk-n1erf6kh.js +22820 -0
- package/dist/chunk-n4nbgkvd.js +520 -0
- package/dist/chunk-n5gkdn9v.js +120 -0
- package/dist/chunk-n7ttdtk0.js +641 -0
- package/dist/chunk-n8b1njwb.js +208 -0
- package/dist/chunk-nek12gtk.js +94 -0
- package/dist/chunk-nerv0jvx.js +74 -0
- package/dist/chunk-nka1g8f4.js +773 -0
- package/dist/chunk-nm2cncrq.js +336 -0
- package/dist/chunk-nq0fxyxh.js +752 -0
- package/dist/chunk-nrnkshv2.js +192 -0
- package/dist/chunk-nsqma629.js +128 -0
- package/dist/chunk-nt837qt9.js +21 -0
- package/dist/chunk-nttf3k0r.js +2643 -0
- package/dist/chunk-nx638j6h.js +268 -0
- package/dist/chunk-nx7s0zn5.js +375 -0
- package/dist/chunk-p0hff8zy.js +8871 -0
- package/dist/chunk-p2816w9z.js +1486 -0
- package/dist/chunk-p2d5nh3g.js +342 -0
- package/dist/chunk-p57bz7nv.js +55 -0
- package/dist/chunk-p5z8t6r3.js +130 -0
- package/dist/chunk-pd6653na.js +5394 -0
- package/dist/chunk-pjnzf3cg.js +61 -0
- package/dist/chunk-ps49ymvj.js +43 -0
- package/dist/chunk-pthzapbx.js +348 -0
- package/dist/chunk-pwwa7s62.js +11 -0
- package/dist/chunk-pyx135a5.js +20 -0
- package/dist/chunk-q132dkwr.js +195 -0
- package/dist/chunk-q16y18s1.js +120 -0
- package/dist/chunk-q25bjaev.js +15 -0
- package/dist/chunk-q3jxs36m.js +716 -0
- package/dist/chunk-q5by3da6.js +8 -0
- package/dist/chunk-q663msp4.js +908 -0
- package/dist/chunk-qezgfppb.js +4521 -0
- package/dist/chunk-qgjgqmy5.js +5796 -0
- package/dist/chunk-qj7h3xc3.js +40 -0
- package/dist/chunk-qjcxkbv6.js +644 -0
- package/dist/chunk-qnfx3qtx.js +617 -0
- package/dist/chunk-qnmyzsam.js +84 -0
- package/dist/chunk-qp2qdcda.js +100 -0
- package/dist/chunk-qvrq1sby.js +6107 -0
- package/dist/chunk-qz2x630m.js +49145 -0
- package/dist/chunk-qz3fe4fj.js +469 -0
- package/dist/chunk-r0af6bw0.js +173 -0
- package/dist/chunk-r1v8d6da.js +1299 -0
- package/dist/chunk-r6b58y3x.js +17 -0
- package/dist/chunk-r6e45bzh.js +118 -0
- package/dist/chunk-r843jezp.js +28 -0
- package/dist/chunk-rbgjkg3v.js +90 -0
- package/dist/chunk-rc5bbzx4.js +655 -0
- package/dist/chunk-rca5xtnd.js +267 -0
- package/dist/chunk-rfdbzyjh.js +1865 -0
- package/dist/chunk-rh7q28df.js +93 -0
- package/dist/chunk-rn0v1hk8.js +34 -0
- package/dist/chunk-rvxs7x7j.js +542 -0
- package/dist/chunk-rw6fwk2s.js +98 -0
- package/dist/chunk-rwagvxh5.js +1711 -0
- package/dist/chunk-s10vyjz4.js +224 -0
- package/dist/chunk-s274nv8k.js +8 -0
- package/dist/chunk-s3pzvdss.js +50 -0
- package/dist/chunk-s4w01jsb.js +969 -0
- package/dist/chunk-s56j2d6g.js +500 -0
- package/dist/chunk-sbs1r0h4.js +317 -0
- package/dist/chunk-sd36yzx8.js +954 -0
- package/dist/chunk-sd6env07.js +19 -0
- package/dist/chunk-sdj9b9wh.js +782 -0
- package/dist/chunk-sfht9xvd.js +24 -0
- package/dist/chunk-sk3gpkdt.js +89 -0
- package/dist/chunk-sp5cjcjh.js +526 -0
- package/dist/chunk-sq847dr5.js +1528 -0
- package/dist/chunk-sskngwam.js +89 -0
- package/dist/chunk-svar8pp2.js +276 -0
- package/dist/chunk-szj5wvdy.js +28 -0
- package/dist/chunk-t175chdd.js +714 -0
- package/dist/chunk-t4k75hqs.js +4987 -0
- package/dist/chunk-t7z7vg91.js +225 -0
- package/dist/chunk-tanfpxm1.js +419 -0
- package/dist/chunk-tf9h0cyj.js +3037 -0
- package/dist/chunk-tm1wwvm1.js +99 -0
- package/dist/chunk-trtgjd28.js +9300 -0
- package/dist/chunk-ts2p6bv1.js +224 -0
- package/dist/chunk-ttk5dzz8.js +25 -0
- package/dist/chunk-tvg352rv.js +391 -0
- package/dist/chunk-tww14j0s.js +86 -0
- package/dist/chunk-tz03j2da.js +66 -0
- package/dist/chunk-v1kzp02e.js +785 -0
- package/dist/chunk-v2sm9w6h.js +220 -0
- package/dist/chunk-v3gm2day.js +8 -0
- package/dist/chunk-v4qn3g0d.js +286 -0
- package/dist/chunk-v66tbnn6.js +476 -0
- package/dist/chunk-v78fj8by.js +145 -0
- package/dist/chunk-v9smspw2.js +4301 -0
- package/dist/chunk-v9ybze94.js +713 -0
- package/dist/chunk-vest0y6x.js +3830 -0
- package/dist/chunk-vf5sd1nq.js +12 -0
- package/dist/chunk-vht4mzgb.js +298 -0
- package/dist/chunk-vjwgf4qh.js +41 -0
- package/dist/chunk-vkrhafhf.js +248 -0
- package/dist/chunk-vn56q87z.js +2058 -0
- package/dist/chunk-vscz82fv.js +27 -0
- package/dist/chunk-vvn4gkak.js +642 -0
- package/dist/chunk-vxj5rbg5.js +84 -0
- package/dist/chunk-vyjeh50y.js +2149 -0
- package/dist/chunk-w44nvpvt.js +22 -0
- package/dist/chunk-waambva2.js +2430 -0
- package/dist/chunk-wbhsqc2a.js +275 -0
- package/dist/chunk-wbsnpxzh.js +471 -0
- package/dist/chunk-wfz0qffj.js +3939 -0
- package/dist/chunk-wpqbrv0f.js +83 -0
- package/dist/chunk-wzpdet3m.js +843 -0
- package/dist/chunk-x6tb96y2.js +264 -0
- package/dist/chunk-x8b7vft8.js +132 -0
- package/dist/chunk-x8eg216f.js +99 -0
- package/dist/chunk-xc9khn0r.js +490 -0
- package/dist/chunk-xch406a3.js +673 -0
- package/dist/chunk-xdw5dv00.js +8 -0
- package/dist/chunk-xe0bpcbr.js +3444 -0
- package/dist/chunk-xm3ed3zn.js +300 -0
- package/dist/chunk-xpm4ebhz.js +87 -0
- package/dist/chunk-xr6yfttj.js +43 -0
- package/dist/chunk-xsq9ae7x.js +90 -0
- package/dist/chunk-xszk7n10.js +14358 -0
- package/dist/chunk-xzmkekfb.js +259 -0
- package/dist/chunk-y1784krc.js +19 -0
- package/dist/chunk-y3py9g5d.js +213 -0
- package/dist/chunk-y9nnmev5.js +687 -0
- package/dist/chunk-ya6jq0hf.js +29 -0
- package/dist/chunk-ycc3xnx0.js +374 -0
- package/dist/chunk-yfa54ssn.js +87 -0
- package/dist/chunk-ymy4xrr8.js +101 -0
- package/dist/chunk-yqfz2k9z.js +48 -0
- package/dist/chunk-ywxd4qw4.js +22 -0
- package/dist/chunk-yxmz5k16.js +122 -0
- package/dist/chunk-yxvy4jt4.js +1014 -0
- package/dist/chunk-z2dp53wn.js +17 -0
- package/dist/chunk-z2xxx2sz.js +294 -0
- package/dist/chunk-z31an09g.js +67 -0
- package/dist/chunk-z95xqvr0.js +75 -0
- package/dist/chunk-zbmxxxz8.js +161 -0
- package/dist/chunk-zk2wsm7d.js +15 -0
- package/dist/chunk-zmg1pcp3.js +71 -0
- package/dist/chunk-znrwmznk.js +272 -0
- package/dist/chunk-zq9r43cb.js +26 -0
- package/dist/chunk-zsfxha74.js +17655 -0
- package/dist/chunk-ztpr96av.js +229 -0
- package/dist/chunk-zv7qrz04.js +58 -0
- package/dist/chunk-zxa7st21.js +32 -0
- package/dist/chunk-zxhezavg.js +216 -0
- package/dist/chunk-zz0qcq2n.js +434 -0
- package/dist/cli.js +194 -0
- package/package.json +164 -0
|
@@ -0,0 +1,1188 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
decodeJwtExpiry
|
|
4
|
+
} from "./chunk-02wy0m47.js";
|
|
5
|
+
import {
|
|
6
|
+
getSessionIngressAuthHeaders,
|
|
7
|
+
getSessionIngressAuthToken,
|
|
8
|
+
init_sessionActivity,
|
|
9
|
+
init_sessionIngressAuth,
|
|
10
|
+
registerSessionActivityCallback,
|
|
11
|
+
unregisterSessionActivityCallback
|
|
12
|
+
} from "./chunk-s10vyjz4.js";
|
|
13
|
+
import {
|
|
14
|
+
getUserAgent1 as getUserAgent,
|
|
15
|
+
init_sleep,
|
|
16
|
+
init_userAgent,
|
|
17
|
+
sleep
|
|
18
|
+
} from "./chunk-30chpfyc.js";
|
|
19
|
+
import {
|
|
20
|
+
createAxiosInstance,
|
|
21
|
+
init_proxy
|
|
22
|
+
} from "./chunk-7pemewz2.js";
|
|
23
|
+
import {
|
|
24
|
+
init_diagLogs,
|
|
25
|
+
logForDiagnosticsNoPII
|
|
26
|
+
} from "./chunk-r1v8d6da.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-rwagvxh5.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": getUserAgent()
|
|
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": getUserAgent()
|
|
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": getUserAgent()
|
|
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 * 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": getUserAgent()
|
|
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 * 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 };
|