@redscope-ai/redscope 1.0.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 +224 -0
- package/dist/chunk-090920rk.js +288 -0
- package/dist/chunk-0afb2r78.js +141 -0
- package/dist/chunk-0d4ekx1g.js +73 -0
- package/dist/chunk-0g6nwbhq.js +15 -0
- package/dist/chunk-0qj905nt.js +18 -0
- package/dist/chunk-0s5btnn1.js +186 -0
- package/dist/chunk-0s8fars0.js +91 -0
- package/dist/chunk-10ev3dvh.js +312 -0
- package/dist/chunk-10k5jfc5.js +1295 -0
- package/dist/chunk-12tspwqa.js +240 -0
- package/dist/chunk-13qesvnw.js +17 -0
- package/dist/chunk-143eh1e0.js +121 -0
- package/dist/chunk-14p6wvsq.js +39 -0
- package/dist/chunk-19f3zb1m.js +342 -0
- package/dist/chunk-1a5cep8h.js +145 -0
- package/dist/chunk-1abw9kkn.js +34 -0
- package/dist/chunk-1aer7c78.js +118 -0
- package/dist/chunk-1dazz4g6.js +154 -0
- package/dist/chunk-1fcf4ty1.js +142 -0
- package/dist/chunk-1gnxhyf8.js +62 -0
- package/dist/chunk-1he3944e.js +8124 -0
- package/dist/chunk-1jpayz7y.js +952 -0
- package/dist/chunk-1qd6f6vk.js +269 -0
- package/dist/chunk-1v0kpe62.js +2547 -0
- package/dist/chunk-1w20m7gw.js +445 -0
- package/dist/chunk-1y7kp51j.js +72 -0
- package/dist/chunk-1ycb5sxt.js +247 -0
- package/dist/chunk-1zbwhcbt.js +1124 -0
- package/dist/chunk-20psem54.js +116 -0
- package/dist/chunk-23h69r5b.js +30 -0
- package/dist/chunk-23x86ptv.js +473 -0
- package/dist/chunk-24fyv3jz.js +378 -0
- package/dist/chunk-24kv69g3.js +97 -0
- package/dist/chunk-2azx8zsc.js +125 -0
- package/dist/chunk-2d1gwzz9.js +524 -0
- package/dist/chunk-2g0ytd9d.js +29058 -0
- package/dist/chunk-2hfp9kat.js +21 -0
- package/dist/chunk-2j875eq6.js +37 -0
- package/dist/chunk-2kcgxnvp.js +39 -0
- package/dist/chunk-2kz09j2s.js +23 -0
- package/dist/chunk-2mwnwp0n.js +17 -0
- package/dist/chunk-2p1cqhcn.js +921 -0
- package/dist/chunk-2p369q9z.js +61 -0
- package/dist/chunk-2rf6asgf.js +151 -0
- package/dist/chunk-2vr7mqx1.js +384 -0
- package/dist/chunk-2xcg933e.js +205 -0
- package/dist/chunk-2ypwckbz.js +40310 -0
- package/dist/chunk-30wnahyg.js +626 -0
- package/dist/chunk-326zehp8.js +204 -0
- package/dist/chunk-32s6jzgw.js +183 -0
- package/dist/chunk-35yzt1a7.js +202 -0
- package/dist/chunk-38frkej6.js +62 -0
- package/dist/chunk-3abaq08g.js +34 -0
- package/dist/chunk-3h59ttr5.js +32 -0
- package/dist/chunk-3nk9q8dr.js +154 -0
- package/dist/chunk-3prrxevm.js +224 -0
- package/dist/chunk-3tv8p9xw.js +127 -0
- package/dist/chunk-3txyekes.js +19 -0
- package/dist/chunk-3vfxjn7g.js +19 -0
- package/dist/chunk-3w9sye8h.js +81 -0
- package/dist/chunk-3y69j7y8.js +24 -0
- package/dist/chunk-3zwjpkjh.js +1603 -0
- package/dist/chunk-40t1d75v.js +3442 -0
- package/dist/chunk-470kmby4.js +318 -0
- package/dist/chunk-47jc141z.js +335 -0
- package/dist/chunk-48rz50ct.js +868 -0
- package/dist/chunk-49wv03ts.js +232 -0
- package/dist/chunk-4a189mn2.js +103 -0
- package/dist/chunk-4c4fmh7a.js +15 -0
- package/dist/chunk-4ct8dsj5.js +49 -0
- package/dist/chunk-4kqt1pm1.js +100 -0
- package/dist/chunk-4ng0xy0e.js +802 -0
- package/dist/chunk-4spgkgr3.js +43 -0
- package/dist/chunk-4tjdwtyy.js +19 -0
- package/dist/chunk-4tr60273.js +370 -0
- package/dist/chunk-4vnaeng5.js +29 -0
- package/dist/chunk-4wbqpeaw.js +871 -0
- package/dist/chunk-4wgkv3fv.js +1140 -0
- package/dist/chunk-4yjskjb6.js +40 -0
- package/dist/chunk-50m3a23z.js +35 -0
- package/dist/chunk-511f79az.js +182 -0
- package/dist/chunk-51sgztvv.js +161 -0
- package/dist/chunk-563fcpv1.js +290 -0
- package/dist/chunk-564cnq6v.js +735 -0
- package/dist/chunk-569r8cxc.js +31 -0
- package/dist/chunk-570x55d4.js +12 -0
- package/dist/chunk-571556cm.js +80 -0
- package/dist/chunk-59t4c56e.js +63 -0
- package/dist/chunk-5axjhkma.js +36 -0
- package/dist/chunk-5b188q5e.js +157 -0
- package/dist/chunk-5dmn1865.js +439 -0
- package/dist/chunk-5ks4829r.js +267 -0
- package/dist/chunk-5mmhfbxb.js +1078 -0
- package/dist/chunk-5rdt14hy.js +742 -0
- package/dist/chunk-5ssryexj.js +121 -0
- package/dist/chunk-5v95pnq4.js +15 -0
- package/dist/chunk-5xvjt2t9.js +68 -0
- package/dist/chunk-5zyq6t1q.js +118 -0
- package/dist/chunk-60fkafk2.js +15 -0
- package/dist/chunk-62fjkf5q.js +46 -0
- package/dist/chunk-64gazrrb.js +8067 -0
- package/dist/chunk-65tq2yjx.js +126 -0
- package/dist/chunk-65zbgg1n.js +14 -0
- package/dist/chunk-66v8mty3.js +264 -0
- package/dist/chunk-6acx5heq.js +292 -0
- package/dist/chunk-6hr7742d.js +61 -0
- package/dist/chunk-6hygvrhn.js +143 -0
- package/dist/chunk-6kjh280m.js +128 -0
- package/dist/chunk-6s0q1s5r.js +66 -0
- package/dist/chunk-6x35ffpx.js +690 -0
- package/dist/chunk-71jfy1hh.js +570 -0
- package/dist/chunk-71sdcaq6.js +15 -0
- package/dist/chunk-754qdxs5.js +92 -0
- package/dist/chunk-79v5bkj4.js +1176 -0
- package/dist/chunk-7br0w7j5.js +151 -0
- package/dist/chunk-7cjgrzz1.js +298 -0
- package/dist/chunk-7d41ks0y.js +133 -0
- package/dist/chunk-7f40pmtr.js +71 -0
- package/dist/chunk-7g15x8hm.js +131 -0
- package/dist/chunk-7gtnzdet.js +120 -0
- package/dist/chunk-7h0z4aqx.js +702 -0
- package/dist/chunk-7h7e5a7d.js +25 -0
- package/dist/chunk-7m2cznwr.js +40 -0
- package/dist/chunk-7nvday0n.js +252 -0
- package/dist/chunk-7qey87th.js +145 -0
- package/dist/chunk-7qx3xhv3.js +9076 -0
- package/dist/chunk-7tfdhkpy.js +61 -0
- package/dist/chunk-80m511j6.js +121 -0
- package/dist/chunk-80ysxfe9.js +784 -0
- package/dist/chunk-8375zk8t.js +17200 -0
- package/dist/chunk-85bpkyy9.js +412 -0
- package/dist/chunk-85tcn547.js +876 -0
- package/dist/chunk-85vqgbc8.js +13 -0
- package/dist/chunk-86626jb4.js +49 -0
- package/dist/chunk-87ms17f6.js +444 -0
- package/dist/chunk-87mz239c.js +118 -0
- package/dist/chunk-89vdzt4e.js +254 -0
- package/dist/chunk-89z3e99z.js +159 -0
- package/dist/chunk-8cwrz1dd.js +1806 -0
- package/dist/chunk-8gv2pjby.js +21 -0
- package/dist/chunk-8hdevr3s.js +140 -0
- package/dist/chunk-8hdsk6qc.js +710 -0
- package/dist/chunk-8kct9arg.js +724 -0
- package/dist/chunk-8kf8h7xf.js +23 -0
- package/dist/chunk-8qed8ymj.js +605 -0
- package/dist/chunk-8sdgr592.js +101 -0
- package/dist/chunk-8we9w8pw.js +111 -0
- package/dist/chunk-8xnm5637.js +72 -0
- package/dist/chunk-8y3q0eqy.js +67 -0
- package/dist/chunk-8yvsnrkr.js +3449 -0
- package/dist/chunk-8zz4z1q3.js +42 -0
- package/dist/chunk-90eyff3k.js +119 -0
- package/dist/chunk-92bjkrf2.js +121 -0
- package/dist/chunk-92zrc7c6.js +327 -0
- package/dist/chunk-935nrvdb.js +13 -0
- package/dist/chunk-94pfyv6a.js +48 -0
- package/dist/chunk-9568p8se.js +115 -0
- package/dist/chunk-96km1ywr.js +37 -0
- package/dist/chunk-980bg4w4.js +163 -0
- package/dist/chunk-9a9g5hbj.js +205 -0
- package/dist/chunk-9cm4725d.js +4395 -0
- package/dist/chunk-9ds3vzq8.js +847 -0
- package/dist/chunk-9ffc9n60.js +618 -0
- package/dist/chunk-9fstrwv2.js +184 -0
- package/dist/chunk-9gt0g0qe.js +153 -0
- package/dist/chunk-9h9k5vz3.js +2761 -0
- package/dist/chunk-9he8bmhy.js +17 -0
- package/dist/chunk-9hn8e6h1.js +12 -0
- package/dist/chunk-9j0n3g8e.js +179 -0
- package/dist/chunk-9j6pa3ft.js +251 -0
- package/dist/chunk-9jpg9dn7.js +122 -0
- package/dist/chunk-9mycnwj5.js +46 -0
- package/dist/chunk-9npy2c17.js +517 -0
- package/dist/chunk-9p6sec8n.js +34 -0
- package/dist/chunk-9pnym83h.js +4584 -0
- package/dist/chunk-9skwrnd2.js +25 -0
- package/dist/chunk-9tsfaqr8.js +459 -0
- package/dist/chunk-9tsw3cqv.js +5924 -0
- package/dist/chunk-9w6ckyk4.js +49 -0
- package/dist/chunk-a15bwzv6.js +147 -0
- package/dist/chunk-a9t6cp69.js +28 -0
- package/dist/chunk-ad2yk19p.js +102 -0
- package/dist/chunk-ad4cw4nw.js +336 -0
- package/dist/chunk-ad69fbsk.js +347 -0
- package/dist/chunk-ae76ded0.js +30 -0
- package/dist/chunk-aeysytks.js +216 -0
- package/dist/chunk-ag81m9bq.js +61 -0
- package/dist/chunk-ahx7gp6r.js +4448 -0
- package/dist/chunk-aj4tk4tk.js +23 -0
- package/dist/chunk-an82t9jc.js +104 -0
- package/dist/chunk-apg95qd7.js +1393 -0
- package/dist/chunk-aq5n2adz.js +27 -0
- package/dist/chunk-aw4s3a99.js +208 -0
- package/dist/chunk-awgdfggg.js +14 -0
- package/dist/chunk-ayymxgn1.js +164 -0
- package/dist/chunk-azbab59e.js +637 -0
- package/dist/chunk-azdxq2a3.js +293 -0
- package/dist/chunk-b0tjx3k1.js +523 -0
- package/dist/chunk-b5pp4g2g.js +371 -0
- package/dist/chunk-b5zm8dt6.js +26 -0
- package/dist/chunk-bcnye5a0.js +109 -0
- package/dist/chunk-beqz3k49.js +190 -0
- package/dist/chunk-bf906wpw.js +147 -0
- package/dist/chunk-bgan4cpf.js +13 -0
- package/dist/chunk-bhzp13h7.js +1178 -0
- package/dist/chunk-bk403kpw.js +142 -0
- package/dist/chunk-bmq4c135.js +489 -0
- package/dist/chunk-bprbeda7.js +35 -0
- package/dist/chunk-bst7czdd.js +888 -0
- package/dist/chunk-bths4xgn.js +111 -0
- package/dist/chunk-btjn3qby.js +13 -0
- package/dist/chunk-bwb1vxnt.js +120 -0
- package/dist/chunk-bxa6tw4m.js +643 -0
- package/dist/chunk-bxfjr8qb.js +27 -0
- package/dist/chunk-bxpzhrej.js +73 -0
- package/dist/chunk-bzyzrq0k.js +51 -0
- package/dist/chunk-c0k7b0jw.js +4265 -0
- package/dist/chunk-c17f0h2s.js +16 -0
- package/dist/chunk-c1yc761e.js +6748 -0
- package/dist/chunk-c5g9shkw.js +298 -0
- package/dist/chunk-c696122m.js +69 -0
- package/dist/chunk-c92b3yxx.js +109 -0
- package/dist/chunk-c9aqz56y.js +143 -0
- package/dist/chunk-cba7c5w3.js +345 -0
- package/dist/chunk-cbcxbbe6.js +6543 -0
- package/dist/chunk-cdfjb87h.js +11 -0
- package/dist/chunk-ce8zjt1y.js +136 -0
- package/dist/chunk-cep7e37k.js +22740 -0
- package/dist/chunk-chs5qm8d.js +258 -0
- package/dist/chunk-ckydq33g.js +144 -0
- package/dist/chunk-cnge6wpj.js +514 -0
- package/dist/chunk-cpnsvqf1.js +13 -0
- package/dist/chunk-cqqebkv4.js +32 -0
- package/dist/chunk-cvqpp7dk.js +627 -0
- package/dist/chunk-cwc33j40.js +65 -0
- package/dist/chunk-cypvrq2a.js +155 -0
- package/dist/chunk-d1ha0swn.js +475 -0
- package/dist/chunk-d2an0138.js +35 -0
- package/dist/chunk-d2tt72ck.js +343 -0
- package/dist/chunk-d6wvcqrw.js +9507 -0
- package/dist/chunk-d7ys2kka.js +991 -0
- package/dist/chunk-dbts5q5p.js +122 -0
- package/dist/chunk-dct29ggs.js +295 -0
- package/dist/chunk-de0qnnf7.js +1059 -0
- package/dist/chunk-dep72ce4.js +513 -0
- package/dist/chunk-dgpvgy8x.js +47 -0
- package/dist/chunk-dhhd7dtc.js +20 -0
- package/dist/chunk-dhzpmxv6.js +594 -0
- package/dist/chunk-djes4da7.js +413 -0
- package/dist/chunk-dnhv3vx7.js +166 -0
- package/dist/chunk-dqtvafan.js +2365 -0
- package/dist/chunk-dr4a3tcp.js +60 -0
- package/dist/chunk-dz2xk9kb.js +100 -0
- package/dist/chunk-dz7nc6rf.js +15 -0
- package/dist/chunk-e3abfxpy.js +1486 -0
- package/dist/chunk-e3cq9z89.js +85 -0
- package/dist/chunk-e3j7m7k2.js +642 -0
- package/dist/chunk-e4dsy4g1.js +9951 -0
- package/dist/chunk-e5592pnn.js +197 -0
- package/dist/chunk-e55hdegh.js +129 -0
- package/dist/chunk-e5r5r04e.js +1030 -0
- package/dist/chunk-e60zztbt.js +442 -0
- package/dist/chunk-e7qq6vn0.js +372 -0
- package/dist/chunk-e9aat7xw.js +80 -0
- package/dist/chunk-e9d5v3zs.js +143 -0
- package/dist/chunk-eax32zk4.js +87 -0
- package/dist/chunk-ebfwmbx1.js +117 -0
- package/dist/chunk-ec71pb8t.js +971 -0
- package/dist/chunk-eemjb825.js +17252 -0
- package/dist/chunk-ees8xdhd.js +256 -0
- package/dist/chunk-eewg66y1.js +112 -0
- package/dist/chunk-eg22v12d.js +266 -0
- package/dist/chunk-enzzk67f.js +313 -0
- package/dist/chunk-eskhp70f.js +117 -0
- package/dist/chunk-ewx6z4g8.js +55 -0
- package/dist/chunk-eyvx461k.js +76 -0
- package/dist/chunk-eztq2b5f.js +94 -0
- package/dist/chunk-f0ffwzdd.js +321 -0
- package/dist/chunk-f80n68mf.js +119 -0
- package/dist/chunk-fae2hjxp.js +99 -0
- package/dist/chunk-fbtfp370.js +60 -0
- package/dist/chunk-fc6ndtgf.js +94 -0
- package/dist/chunk-fdwabr8p.js +13870 -0
- package/dist/chunk-fejeqe61.js +785 -0
- package/dist/chunk-fh0d6mvk.js +168 -0
- package/dist/chunk-fh19zcaf.js +304 -0
- package/dist/chunk-fh8bd39r.js +186 -0
- package/dist/chunk-fj2ebbpn.js +33 -0
- package/dist/chunk-fjn632v7.js +194 -0
- package/dist/chunk-fncpkzs5.js +1389 -0
- package/dist/chunk-fpd1gpt8.js +332 -0
- package/dist/chunk-fq9snrnh.js +295 -0
- package/dist/chunk-fqcfzg3j.js +207 -0
- package/dist/chunk-ftt3vqj2.js +1919 -0
- package/dist/chunk-g06pm4n9.js +395 -0
- package/dist/chunk-g4m5pf4g.js +8 -0
- package/dist/chunk-g72h52y6.js +36 -0
- package/dist/chunk-g79ej71s.js +1627 -0
- package/dist/chunk-g7fwk59d.js +19 -0
- package/dist/chunk-g9jnkrtm.js +663 -0
- package/dist/chunk-g9vg5d7t.js +38 -0
- package/dist/chunk-ga1jkyqy.js +1636 -0
- package/dist/chunk-gaaap2nk.js +676 -0
- package/dist/chunk-gc6erq5q.js +483 -0
- package/dist/chunk-gjrcmf0a.js +752 -0
- package/dist/chunk-gmdy2w3z.js +238999 -0
- package/dist/chunk-gsz4yrrk.js +81 -0
- package/dist/chunk-gy47rjy8.js +3830 -0
- package/dist/chunk-h12a4f4x.js +11 -0
- package/dist/chunk-h1yratmg.js +725 -0
- package/dist/chunk-h9y0jnsy.js +155 -0
- package/dist/chunk-hbhs3mwy.js +133 -0
- package/dist/chunk-hbs8cmb4.js +8 -0
- package/dist/chunk-hdk0t1ht.js +940 -0
- package/dist/chunk-hef8dx4s.js +178 -0
- package/dist/chunk-hgsca8mt.js +381 -0
- package/dist/chunk-hhsxm2yr.js +67 -0
- package/dist/chunk-hj5tzzpd.js +39 -0
- package/dist/chunk-hjxqmtg5.js +94 -0
- package/dist/chunk-hn4w9pkj.js +68 -0
- package/dist/chunk-hnprkjgp.js +25 -0
- package/dist/chunk-hq3n5ex7.js +183 -0
- package/dist/chunk-hqjspfma.js +158 -0
- package/dist/chunk-hqxp6b72.js +1198 -0
- package/dist/chunk-hs6nrmq6.js +94 -0
- package/dist/chunk-hwba5xdc.js +267 -0
- package/dist/chunk-hy566ev3.js +430 -0
- package/dist/chunk-hzmzwte2.js +153 -0
- package/dist/chunk-hzxzvzw8.js +274 -0
- package/dist/chunk-j139fzgs.js +114 -0
- package/dist/chunk-j1mep9ck.js +62 -0
- package/dist/chunk-j3xveeg4.js +273 -0
- package/dist/chunk-j5y1s11j.js +100 -0
- package/dist/chunk-j9475b46.js +26 -0
- package/dist/chunk-j9rgqs8m.js +1192 -0
- package/dist/chunk-jccjaddz.js +74 -0
- package/dist/chunk-jdkwfy9e.js +35 -0
- package/dist/chunk-jdqp0r4h.js +6157 -0
- package/dist/chunk-jdzk4zwn.js +587 -0
- package/dist/chunk-jfafmkte.js +49 -0
- package/dist/chunk-jg3r989b.js +16 -0
- package/dist/chunk-jhtccjc9.js +54 -0
- package/dist/chunk-jj2ff1pr.js +688 -0
- package/dist/chunk-jmv7k0jn.js +37 -0
- package/dist/chunk-jmxzmwpw.js +65 -0
- package/dist/chunk-jnjxdqyr.js +353 -0
- package/dist/chunk-jsbbez9j.js +138 -0
- package/dist/chunk-jvpt2dc0.js +424 -0
- package/dist/chunk-jwd7cka0.js +34 -0
- package/dist/chunk-jy5er3st.js +15 -0
- package/dist/chunk-jyby79z5.js +121 -0
- package/dist/chunk-jzyr6j5n.js +332 -0
- package/dist/chunk-k49xc781.js +63 -0
- package/dist/chunk-k7dt2g4a.js +41 -0
- package/dist/chunk-k7hexw3v.js +969 -0
- package/dist/chunk-k7wwkraa.js +117 -0
- package/dist/chunk-kb3758f7.js +51 -0
- package/dist/chunk-kc67kt75.js +3119 -0
- package/dist/chunk-kdhmfxmh.js +3149 -0
- package/dist/chunk-kejdd6zc.js +51 -0
- package/dist/chunk-kekrjeem.js +402 -0
- package/dist/chunk-kez5r0zz.js +280 -0
- package/dist/chunk-kfsvcs5t.js +75 -0
- package/dist/chunk-khtvffc4.js +285 -0
- package/dist/chunk-kkz4w1tv.js +64 -0
- package/dist/chunk-kmywng0j.js +272 -0
- package/dist/chunk-kq6vcpdr.js +224 -0
- package/dist/chunk-kqzdszcc.js +37 -0
- package/dist/chunk-ktxpp02w.js +435 -0
- package/dist/chunk-kwcvhbtz.js +26 -0
- package/dist/chunk-kx0cm9qr.js +128 -0
- package/dist/chunk-kxcmqz10.js +120 -0
- package/dist/chunk-kxwava1g.js +14 -0
- package/dist/chunk-kywtr3jg.js +825 -0
- package/dist/chunk-kzwg923p.js +8 -0
- package/dist/chunk-m1eq3sgv.js +255 -0
- package/dist/chunk-m21h5zb4.js +119 -0
- package/dist/chunk-m2c3bjv1.js +111 -0
- package/dist/chunk-m41e19ms.js +42 -0
- package/dist/chunk-m7ka36ex.js +97 -0
- package/dist/chunk-m81w8tbm.js +259 -0
- package/dist/chunk-m95ggkax.js +281 -0
- package/dist/chunk-manx26xa.js +145 -0
- package/dist/chunk-mdxh3pk2.js +298 -0
- package/dist/chunk-mhbfkcja.js +311 -0
- package/dist/chunk-mjnr5erm.js +173 -0
- package/dist/chunk-mngvnmwp.js +135 -0
- package/dist/chunk-mvfqanv5.js +63 -0
- package/dist/chunk-mw1nesq1.js +140 -0
- package/dist/chunk-mx168925.js +661 -0
- package/dist/chunk-mxwvj18g.js +795 -0
- package/dist/chunk-my7r5mba.js +257 -0
- package/dist/chunk-myaa1kkf.js +17 -0
- package/dist/chunk-myypc3tn.js +46 -0
- package/dist/chunk-mzcnmnpq.js +3379 -0
- package/dist/chunk-mznav6d1.js +194 -0
- package/dist/chunk-n0qxskpr.js +24 -0
- package/dist/chunk-n6a6hgtp.js +394 -0
- package/dist/chunk-n6d5fgx0.js +254 -0
- package/dist/chunk-n6ym3n03.js +120 -0
- package/dist/chunk-n9g24mwe.js +104 -0
- package/dist/chunk-naamqdf9.js +185 -0
- package/dist/chunk-nb2jk7zj.js +15 -0
- package/dist/chunk-nbkbq9en.js +67 -0
- package/dist/chunk-ndttd6es.js +38 -0
- package/dist/chunk-nfygaaxg.js +133 -0
- package/dist/chunk-ngdzpszd.js +454 -0
- package/dist/chunk-nmfwksa4.js +1297 -0
- package/dist/chunk-nt837qt9.js +21 -0
- package/dist/chunk-nwc3v0vp.js +691 -0
- package/dist/chunk-nz8ha95p.js +3610 -0
- package/dist/chunk-nzxfj0gq.js +2007 -0
- package/dist/chunk-p0r8887g.js +6932 -0
- package/dist/chunk-p1seyqdm.js +120 -0
- package/dist/chunk-p425zbgw.js +726 -0
- package/dist/chunk-p7hamd2c.js +146 -0
- package/dist/chunk-pdvg91cg.js +32 -0
- package/dist/chunk-pecy49yr.js +14649 -0
- package/dist/chunk-pfxrg89f.js +547 -0
- package/dist/chunk-pfyw3155.js +2750 -0
- package/dist/chunk-pr8m11pm.js +1192 -0
- package/dist/chunk-ptxteaeh.js +1591 -0
- package/dist/chunk-pv164mac.js +394 -0
- package/dist/chunk-pxxhtxf5.js +10154 -0
- package/dist/chunk-q0e485mg.js +61 -0
- package/dist/chunk-q1vrhh0q.js +458 -0
- package/dist/chunk-q2h79ncs.js +370 -0
- package/dist/chunk-q3b4n194.js +56 -0
- package/dist/chunk-q44zc68f.js +4301 -0
- package/dist/chunk-q8gknbdx.js +352 -0
- package/dist/chunk-q8xk3kdj.js +11 -0
- package/dist/chunk-qak46xtp.js +119 -0
- package/dist/chunk-qfq7absv.js +95 -0
- package/dist/chunk-qfsn720k.js +151 -0
- package/dist/chunk-qg4811f6.js +228 -0
- package/dist/chunk-qgzn3qps.js +90 -0
- package/dist/chunk-qhaggqkt.js +113 -0
- package/dist/chunk-qjjp27z8.js +195 -0
- package/dist/chunk-qxp0nye6.js +34 -0
- package/dist/chunk-qy3nagaq.js +4957 -0
- package/dist/chunk-qz2meav1.js +1452 -0
- package/dist/chunk-r50hne7m.js +63 -0
- package/dist/chunk-r6m0vgnv.js +80 -0
- package/dist/chunk-r7yw38vf.js +22864 -0
- package/dist/chunk-r8xc618w.js +42 -0
- package/dist/chunk-r961r5kj.js +87 -0
- package/dist/chunk-r9b5xrh0.js +66 -0
- package/dist/chunk-rcn2pd6q.js +477 -0
- package/dist/chunk-rdeh8p3y.js +148 -0
- package/dist/chunk-rg9x1742.js +542 -0
- package/dist/chunk-rgyzsbs3.js +39 -0
- package/dist/chunk-rk2fsxtz.js +16 -0
- package/dist/chunk-rkchkwv9.js +40 -0
- package/dist/chunk-rp8whpb3.js +478 -0
- package/dist/chunk-rpkxdtgr.js +68 -0
- package/dist/chunk-rpmntgyh.js +394 -0
- package/dist/chunk-rpshz4dy.js +614 -0
- package/dist/chunk-rqd60ay5.js +133 -0
- package/dist/chunk-rrsjf2ea.js +229 -0
- package/dist/chunk-rtjk8c8e.js +173 -0
- package/dist/chunk-rw0y2wdf.js +1017 -0
- package/dist/chunk-rx5w7ess.js +663 -0
- package/dist/chunk-rx8t9d35.js +1947 -0
- package/dist/chunk-rxcazxgf.js +195 -0
- package/dist/chunk-rxg6q3bp.js +1413 -0
- package/dist/chunk-rxrb7xnd.js +71 -0
- package/dist/chunk-rxrzxff3.js +118 -0
- package/dist/chunk-ryqjc943.js +71 -0
- package/dist/chunk-rzk9k2rf.js +81 -0
- package/dist/chunk-s2qv0nht.js +119 -0
- package/dist/chunk-s3hafnk3.js +2285 -0
- package/dist/chunk-s4a496tt.js +226 -0
- package/dist/chunk-s4d1h3ka.js +35 -0
- package/dist/chunk-sm3k3ze4.js +16525 -0
- package/dist/chunk-sn0bja82.js +385 -0
- package/dist/chunk-sngjggw1.js +4227 -0
- package/dist/chunk-sq047n34.js +364 -0
- package/dist/chunk-sttwe2tw.js +8584 -0
- package/dist/chunk-sw8qx1r0.js +86 -0
- package/dist/chunk-swstah6a.js +240 -0
- package/dist/chunk-syrkr0mf.js +63 -0
- package/dist/chunk-sz206bd9.js +26 -0
- package/dist/chunk-t09669cj.js +333 -0
- package/dist/chunk-t5f8e30k.js +602 -0
- package/dist/chunk-t5m78mc8.js +432 -0
- package/dist/chunk-t5x1dqwn.js +143 -0
- package/dist/chunk-t877ea0w.js +168 -0
- package/dist/chunk-t91hb71c.js +17 -0
- package/dist/chunk-tb636bcf.js +942 -0
- package/dist/chunk-tb8sykbr.js +426 -0
- package/dist/chunk-tbdkekz3.js +125 -0
- package/dist/chunk-td2gsz7s.js +225 -0
- package/dist/chunk-tenvxbyh.js +20 -0
- package/dist/chunk-texg4qqt.js +317 -0
- package/dist/chunk-teymzz80.js +266 -0
- package/dist/chunk-tj26qpf7.js +153 -0
- package/dist/chunk-tk85ec4p.js +395 -0
- package/dist/chunk-tq205h01.js +164 -0
- package/dist/chunk-tqzddjzg.js +61 -0
- package/dist/chunk-trqrj23e.js +134 -0
- package/dist/chunk-tw1hfsxv.js +2477 -0
- package/dist/chunk-txxdfq83.js +122 -0
- package/dist/chunk-v0yhe582.js +31 -0
- package/dist/chunk-v14184xm.js +15 -0
- package/dist/chunk-v1h9z4hw.js +138 -0
- package/dist/chunk-v3ey5j7f.js +329 -0
- package/dist/chunk-v3nh1sfn.js +208 -0
- package/dist/chunk-v3x8tcc0.js +45 -0
- package/dist/chunk-v4nqnvqq.js +3984 -0
- package/dist/chunk-v4ypszbb.js +15 -0
- package/dist/chunk-v7wbqcx9.js +63 -0
- package/dist/chunk-v8r5fev3.js +341 -0
- package/dist/chunk-v9zg5kzx.js +2810 -0
- package/dist/chunk-va1wh5ss.js +24 -0
- package/dist/chunk-vbfswhht.js +42 -0
- package/dist/chunk-ve7x2tfq.js +124 -0
- package/dist/chunk-vfz8k89y.js +485 -0
- package/dist/chunk-vgm5k14x.js +35678 -0
- package/dist/chunk-vh9pej3c.js +247 -0
- package/dist/chunk-vjxqyt6f.js +3820 -0
- package/dist/chunk-vpb1xstn.js +178 -0
- package/dist/chunk-vqt79tj8.js +110 -0
- package/dist/chunk-vr0n9pv9.js +152 -0
- package/dist/chunk-vrejmja5.js +90 -0
- package/dist/chunk-vrxasmdw.js +449 -0
- package/dist/chunk-vrxb946v.js +125 -0
- package/dist/chunk-vv4kj0q8.js +98 -0
- package/dist/chunk-vvpfng7w.js +8 -0
- package/dist/chunk-vw6ybyew.js +2007 -0
- package/dist/chunk-vwenx8ke.js +17 -0
- package/dist/chunk-vwfa0s5a.js +155 -0
- package/dist/chunk-vx71j8xe.js +63 -0
- package/dist/chunk-vxbjzggp.js +43 -0
- package/dist/chunk-vxjxtz8w.js +440 -0
- package/dist/chunk-vy0c1bwp.js +9 -0
- package/dist/chunk-w3zczyse.js +14 -0
- package/dist/chunk-w4p5t920.js +655 -0
- package/dist/chunk-w68wc625.js +287 -0
- package/dist/chunk-w9ddp3yf.js +96 -0
- package/dist/chunk-wcggm5ja.js +125 -0
- package/dist/chunk-wgnyph3q.js +1306 -0
- package/dist/chunk-wjm5pc1e.js +134 -0
- package/dist/chunk-wnve0drm.js +131 -0
- package/dist/chunk-wp27ev2k.js +135 -0
- package/dist/chunk-wyvy8a4x.js +131 -0
- package/dist/chunk-x671y4dk.js +129 -0
- package/dist/chunk-xbj5keyy.js +22 -0
- package/dist/chunk-xf4fzms8.js +39 -0
- package/dist/chunk-xf59k3zg.js +65 -0
- package/dist/chunk-xgzc4w49.js +204 -0
- package/dist/chunk-xhj7g13b.js +2149 -0
- package/dist/chunk-xjp0cd00.js +56 -0
- package/dist/chunk-xkhnmhqs.js +74 -0
- package/dist/chunk-xkrkqx61.js +55 -0
- package/dist/chunk-xmpgmeb8.js +114 -0
- package/dist/chunk-xrw80zgd.js +4249 -0
- package/dist/chunk-xrzc96g0.js +202 -0
- package/dist/chunk-xt76sm44.js +318 -0
- package/dist/chunk-xwet3awb.js +20 -0
- package/dist/chunk-xyg1sk2w.js +78 -0
- package/dist/chunk-y0jpkqb0.js +180 -0
- package/dist/chunk-y1q7rt9n.js +102 -0
- package/dist/chunk-y67ntyek.js +258 -0
- package/dist/chunk-ybk37qp9.js +37 -0
- package/dist/chunk-yc1stfve.js +5386 -0
- package/dist/chunk-ychjpjef.js +62 -0
- package/dist/chunk-yez8fa9g.js +276 -0
- package/dist/chunk-ygm7xszr.js +90 -0
- package/dist/chunk-ym11azkj.js +37 -0
- package/dist/chunk-ympz2h15.js +578 -0
- package/dist/chunk-yqx3az3n.js +129 -0
- package/dist/chunk-yt3nfhcc.js +152 -0
- package/dist/chunk-yy8q0n8s.js +120 -0
- package/dist/chunk-yzb92zxv.js +8 -0
- package/dist/chunk-yzet6xyr.js +119 -0
- package/dist/chunk-yzm97qp1.js +226 -0
- package/dist/chunk-z0jgeax8.js +35 -0
- package/dist/chunk-z1r3z6w6.js +29 -0
- package/dist/chunk-z2dp53wn.js +17 -0
- package/dist/chunk-z79355gz.js +308 -0
- package/dist/chunk-z7e94hxz.js +251 -0
- package/dist/chunk-z8cqdcec.js +173 -0
- package/dist/chunk-z99tbg45.js +148 -0
- package/dist/chunk-z9nsjcht.js +37 -0
- package/dist/chunk-za3k6h2h.js +470 -0
- package/dist/chunk-zacynq5p.js +265 -0
- package/dist/chunk-zb0x40az.js +1785 -0
- package/dist/chunk-zbxtzycc.js +274 -0
- package/dist/chunk-zga50181.js +342 -0
- package/dist/chunk-zhb2pns1.js +44 -0
- package/dist/chunk-zkch6trx.js +231 -0
- package/dist/chunk-znf3z4qt.js +954 -0
- package/dist/chunk-zp8zwdgq.js +72 -0
- package/dist/chunk-ztjd8pyf.js +120 -0
- package/dist/chunk-ztmb7geg.js +173 -0
- package/dist/chunk-zvr4snzv.js +887 -0
- package/dist/chunk-zw62m6n3.js +34858 -0
- package/dist/chunk-zwwdebd0.js +65 -0
- package/dist/chunk-zxc6x9w8.js +340 -0
- package/dist/chunk-zy2e7sz0.js +8 -0
- package/dist/chunk-zzf074w3.js +196 -0
- package/dist/chunk-zzz0nwb5.js +310 -0
- package/dist/cli-bun.js +2 -0
- package/dist/cli-node.js +2 -0
- package/dist/cli.js +218 -0
- package/dist/vendor/audio-capture/arm64-darwin/audio-capture.node +0 -0
- package/dist/vendor/audio-capture/arm64-linux/audio-capture.node +0 -0
- package/dist/vendor/audio-capture/arm64-win32/audio-capture.node +0 -0
- package/dist/vendor/audio-capture/x64-darwin/audio-capture.node +0 -0
- package/dist/vendor/audio-capture/x64-linux/audio-capture.node +0 -0
- package/dist/vendor/audio-capture/x64-win32/audio-capture.node +0 -0
- package/dist/vendor/ripgrep/x64-win32/rg.exe +0 -0
- package/package.json +243 -0
- package/scripts/chrome-mcp-bridge-resolver.mjs +43 -0
- package/scripts/chrome-mcp-env.mjs +19 -0
- package/scripts/postinstall.cjs +339 -0
- package/scripts/run-parallel.mjs +10 -0
- package/scripts/setup-chrome-mcp.mjs +69 -0
|
@@ -0,0 +1,1603 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
HybridTransport
|
|
4
|
+
} from "./chunk-nwc3v0vp.js";
|
|
5
|
+
import {
|
|
6
|
+
FlushGate,
|
|
7
|
+
createV1ReplTransport,
|
|
8
|
+
createV2ReplTransport
|
|
9
|
+
} from "./chunk-xgzc4w49.js";
|
|
10
|
+
import"./chunk-80ysxfe9.js";
|
|
11
|
+
import {
|
|
12
|
+
BoundedUUIDSet,
|
|
13
|
+
extractTitleText,
|
|
14
|
+
handleIngressMessage,
|
|
15
|
+
handleServerControlRequest,
|
|
16
|
+
isEligibleBridgeMessage,
|
|
17
|
+
makeResultMessage
|
|
18
|
+
} from "./chunk-d2tt72ck.js";
|
|
19
|
+
import"./chunk-nt837qt9.js";
|
|
20
|
+
import {
|
|
21
|
+
createCapacityWake
|
|
22
|
+
} from "./chunk-ae76ded0.js";
|
|
23
|
+
import {
|
|
24
|
+
DEFAULT_POLL_CONFIG,
|
|
25
|
+
getPollIntervalConfig
|
|
26
|
+
} from "./chunk-syrkr0mf.js";
|
|
27
|
+
import {
|
|
28
|
+
buildCCRv2SdkUrl,
|
|
29
|
+
buildSdkUrl,
|
|
30
|
+
decodeWorkSecret,
|
|
31
|
+
sameSessionId
|
|
32
|
+
} from "./chunk-cwc33j40.js";
|
|
33
|
+
import"./chunk-yt3nfhcc.js";
|
|
34
|
+
import"./chunk-87ms17f6.js";
|
|
35
|
+
import {
|
|
36
|
+
exports_assistant,
|
|
37
|
+
init_assistant
|
|
38
|
+
} from "./chunk-8hdevr3s.js";
|
|
39
|
+
import {
|
|
40
|
+
checkEnvLessBridgeMinVersion,
|
|
41
|
+
init_envLessBridgeConfig
|
|
42
|
+
} from "./chunk-hs6nrmq6.js";
|
|
43
|
+
import {
|
|
44
|
+
init_mappers,
|
|
45
|
+
toSDKMessages
|
|
46
|
+
} from "./chunk-qg4811f6.js";
|
|
47
|
+
import {
|
|
48
|
+
archiveBridgeSession,
|
|
49
|
+
createBridgeSession,
|
|
50
|
+
init_createSession,
|
|
51
|
+
updateBridgeSessionTitle
|
|
52
|
+
} from "./chunk-89vdzt4e.js";
|
|
53
|
+
import {
|
|
54
|
+
extractConversationText,
|
|
55
|
+
generateSessionTitle,
|
|
56
|
+
init_sessionTitle
|
|
57
|
+
} from "./chunk-wjm5pc1e.js";
|
|
58
|
+
import {
|
|
59
|
+
BridgeFatalError,
|
|
60
|
+
clearBridgeDebugHandle,
|
|
61
|
+
createBridgeApiClient,
|
|
62
|
+
generateShortWordSlug,
|
|
63
|
+
getContentText,
|
|
64
|
+
getCurrentSessionTitle,
|
|
65
|
+
getMessagesAfterCompactBoundary,
|
|
66
|
+
init_bridgeApi,
|
|
67
|
+
init_bridgeDebug,
|
|
68
|
+
init_concurrentSessions,
|
|
69
|
+
init_messages1 as init_messages,
|
|
70
|
+
init_policyLimits,
|
|
71
|
+
init_sessionStorage,
|
|
72
|
+
init_words,
|
|
73
|
+
injectBridgeFault,
|
|
74
|
+
isExpiredErrorType,
|
|
75
|
+
isPolicyAllowed,
|
|
76
|
+
isSuppressible403,
|
|
77
|
+
isSyntheticMessage,
|
|
78
|
+
registerBridgeDebugHandle,
|
|
79
|
+
updateSessionBridgeId,
|
|
80
|
+
validateBridgeId,
|
|
81
|
+
waitForPolicyLimitsToLoad,
|
|
82
|
+
wrapApiForFaultInjection
|
|
83
|
+
} from "./chunk-gmdy2w3z.js";
|
|
84
|
+
import"./chunk-q0e485mg.js";
|
|
85
|
+
import"./chunk-2kcgxnvp.js";
|
|
86
|
+
import"./chunk-14p6wvsq.js";
|
|
87
|
+
import"./chunk-6s0q1s5r.js";
|
|
88
|
+
import"./chunk-3w9sye8h.js";
|
|
89
|
+
import {
|
|
90
|
+
init_rcDebugLog,
|
|
91
|
+
init_sessionIngressAuth,
|
|
92
|
+
init_sessionState,
|
|
93
|
+
rcLog,
|
|
94
|
+
setSessionMetadataChangedListener,
|
|
95
|
+
updateSessionIngressAuthToken
|
|
96
|
+
} from "./chunk-nzxfj0gq.js";
|
|
97
|
+
import {
|
|
98
|
+
getTrustedDeviceToken,
|
|
99
|
+
init_trustedDevice
|
|
100
|
+
} from "./chunk-vr0n9pv9.js";
|
|
101
|
+
import"./chunk-9a9g5hbj.js";
|
|
102
|
+
import"./chunk-ptxteaeh.js";
|
|
103
|
+
import"./chunk-w4p5t920.js";
|
|
104
|
+
import"./chunk-rgyzsbs3.js";
|
|
105
|
+
import"./chunk-q3b4n194.js";
|
|
106
|
+
import"./chunk-kywtr3jg.js";
|
|
107
|
+
import {
|
|
108
|
+
checkBridgeMinVersion,
|
|
109
|
+
init_bridgeEnabled,
|
|
110
|
+
isBridgeEnabledBlocking,
|
|
111
|
+
isCseShimEnabled,
|
|
112
|
+
isEnvLessBridgeEnabled
|
|
113
|
+
} from "./chunk-eewg66y1.js";
|
|
114
|
+
import"./chunk-71sdcaq6.js";
|
|
115
|
+
import"./chunk-9hn8e6h1.js";
|
|
116
|
+
import"./chunk-7qey87th.js";
|
|
117
|
+
import"./chunk-zw62m6n3.js";
|
|
118
|
+
import"./chunk-1w20m7gw.js";
|
|
119
|
+
import"./chunk-zzf074w3.js";
|
|
120
|
+
import"./chunk-rpmntgyh.js";
|
|
121
|
+
import"./chunk-24kv69g3.js";
|
|
122
|
+
import"./chunk-hzxzvzw8.js";
|
|
123
|
+
import"./chunk-30wnahyg.js";
|
|
124
|
+
import"./chunk-ztmb7geg.js";
|
|
125
|
+
import {
|
|
126
|
+
describeAxiosError,
|
|
127
|
+
extractHttpStatus,
|
|
128
|
+
init_debugUtils,
|
|
129
|
+
init_sessionIdCompat,
|
|
130
|
+
logBridgeSkip,
|
|
131
|
+
setCseShimGate,
|
|
132
|
+
toCompatSessionId,
|
|
133
|
+
toInfraSessionId
|
|
134
|
+
} from "./chunk-tbdkekz3.js";
|
|
135
|
+
import"./chunk-65zbgg1n.js";
|
|
136
|
+
import"./chunk-4spgkgr3.js";
|
|
137
|
+
import"./chunk-60fkafk2.js";
|
|
138
|
+
import"./chunk-50m3a23z.js";
|
|
139
|
+
import"./chunk-6hygvrhn.js";
|
|
140
|
+
import"./chunk-7tfdhkpy.js";
|
|
141
|
+
import"./chunk-8gv2pjby.js";
|
|
142
|
+
import"./chunk-g06pm4n9.js";
|
|
143
|
+
import {
|
|
144
|
+
getBridgeAccessToken,
|
|
145
|
+
getBridgeBaseUrl,
|
|
146
|
+
getBridgeSessionIngressUrl,
|
|
147
|
+
getBridgeTokenOverride,
|
|
148
|
+
init_bridgeConfig,
|
|
149
|
+
init_bridgeEnv,
|
|
150
|
+
isBridgeCcrV2OverrideEnabled,
|
|
151
|
+
isSelfHostedBridge
|
|
152
|
+
} from "./chunk-2p369q9z.js";
|
|
153
|
+
import"./chunk-z0jgeax8.js";
|
|
154
|
+
import"./chunk-w68wc625.js";
|
|
155
|
+
import"./chunk-6hr7742d.js";
|
|
156
|
+
import"./chunk-xyg1sk2w.js";
|
|
157
|
+
import"./chunk-935nrvdb.js";
|
|
158
|
+
import"./chunk-8zz4z1q3.js";
|
|
159
|
+
import"./chunk-fncpkzs5.js";
|
|
160
|
+
import"./chunk-hqxp6b72.js";
|
|
161
|
+
import"./chunk-m2c3bjv1.js";
|
|
162
|
+
import"./chunk-jhtccjc9.js";
|
|
163
|
+
import"./chunk-7nvday0n.js";
|
|
164
|
+
import"./chunk-vxbjzggp.js";
|
|
165
|
+
import"./chunk-yc1stfve.js";
|
|
166
|
+
import"./chunk-8yvsnrkr.js";
|
|
167
|
+
import"./chunk-5mmhfbxb.js";
|
|
168
|
+
import {
|
|
169
|
+
checkAndRefreshOAuthTokenIfNeeded,
|
|
170
|
+
getClaudeAIOAuthTokens,
|
|
171
|
+
getFeatureValue_CACHED_WITH_REFRESH,
|
|
172
|
+
getGlobalConfig,
|
|
173
|
+
getOrganizationUUID,
|
|
174
|
+
handleOAuth401Error,
|
|
175
|
+
init_auth,
|
|
176
|
+
init_client,
|
|
177
|
+
init_config1 as init_config,
|
|
178
|
+
init_growthbook,
|
|
179
|
+
saveGlobalConfig
|
|
180
|
+
} from "./chunk-eemjb825.js";
|
|
181
|
+
import"./chunk-ga1jkyqy.js";
|
|
182
|
+
import"./chunk-y1q7rt9n.js";
|
|
183
|
+
import"./chunk-8kct9arg.js";
|
|
184
|
+
import"./chunk-k7hexw3v.js";
|
|
185
|
+
import"./chunk-trqrj23e.js";
|
|
186
|
+
import"./chunk-za3k6h2h.js";
|
|
187
|
+
import"./chunk-8kf8h7xf.js";
|
|
188
|
+
import"./chunk-bgan4cpf.js";
|
|
189
|
+
import {
|
|
190
|
+
init_sleep,
|
|
191
|
+
sleep
|
|
192
|
+
} from "./chunk-jmv7k0jn.js";
|
|
193
|
+
import"./chunk-hjxqmtg5.js";
|
|
194
|
+
import"./chunk-bzyzrq0k.js";
|
|
195
|
+
import"./chunk-vwenx8ke.js";
|
|
196
|
+
import"./chunk-q2h79ncs.js";
|
|
197
|
+
import"./chunk-v4ypszbb.js";
|
|
198
|
+
import"./chunk-qfsn720k.js";
|
|
199
|
+
import"./chunk-7qx3xhv3.js";
|
|
200
|
+
import"./chunk-j9475b46.js";
|
|
201
|
+
import"./chunk-fdwabr8p.js";
|
|
202
|
+
import"./chunk-e4dsy4g1.js";
|
|
203
|
+
import"./chunk-326zehp8.js";
|
|
204
|
+
import"./chunk-kc67kt75.js";
|
|
205
|
+
import"./chunk-40t1d75v.js";
|
|
206
|
+
import"./chunk-dbts5q5p.js";
|
|
207
|
+
import"./chunk-e3abfxpy.js";
|
|
208
|
+
import"./chunk-q44zc68f.js";
|
|
209
|
+
import"./chunk-fejeqe61.js";
|
|
210
|
+
import"./chunk-q1vrhh0q.js";
|
|
211
|
+
import"./chunk-hn4w9pkj.js";
|
|
212
|
+
import"./chunk-2g0ytd9d.js";
|
|
213
|
+
import"./chunk-de0qnnf7.js";
|
|
214
|
+
import {
|
|
215
|
+
init_analytics,
|
|
216
|
+
logEvent
|
|
217
|
+
} from "./chunk-j1mep9ck.js";
|
|
218
|
+
import"./chunk-6x35ffpx.js";
|
|
219
|
+
import"./chunk-1zbwhcbt.js";
|
|
220
|
+
import"./chunk-92bjkrf2.js";
|
|
221
|
+
import {
|
|
222
|
+
getBranch,
|
|
223
|
+
getRemoteUrl,
|
|
224
|
+
init_diagLogs,
|
|
225
|
+
init_git,
|
|
226
|
+
logForDiagnosticsNoPII
|
|
227
|
+
} from "./chunk-10k5jfc5.js";
|
|
228
|
+
import"./chunk-n9g24mwe.js";
|
|
229
|
+
import"./chunk-e3j7m7k2.js";
|
|
230
|
+
import"./chunk-hzmzwte2.js";
|
|
231
|
+
import"./chunk-pdvg91cg.js";
|
|
232
|
+
import"./chunk-c696122m.js";
|
|
233
|
+
import"./chunk-xbj5keyy.js";
|
|
234
|
+
import"./chunk-c1yc761e.js";
|
|
235
|
+
import"./chunk-c5g9shkw.js";
|
|
236
|
+
import"./chunk-aeysytks.js";
|
|
237
|
+
import {
|
|
238
|
+
errorMessage,
|
|
239
|
+
init_cleanupRegistry,
|
|
240
|
+
init_debug,
|
|
241
|
+
init_displayTags,
|
|
242
|
+
init_envUtils,
|
|
243
|
+
init_errors,
|
|
244
|
+
isInProtectedNamespace,
|
|
245
|
+
logForDebugging,
|
|
246
|
+
registerCleanup,
|
|
247
|
+
stripDisplayTagsAllowEmpty
|
|
248
|
+
} from "./chunk-s3hafnk3.js";
|
|
249
|
+
import"./chunk-kb3758f7.js";
|
|
250
|
+
import {
|
|
251
|
+
getOriginalCwd,
|
|
252
|
+
getSessionId,
|
|
253
|
+
init_state
|
|
254
|
+
} from "./chunk-9h9k5vz3.js";
|
|
255
|
+
import"./chunk-xmpgmeb8.js";
|
|
256
|
+
import"./chunk-2kz09j2s.js";
|
|
257
|
+
import"./chunk-c0k7b0jw.js";
|
|
258
|
+
import"./chunk-pecy49yr.js";
|
|
259
|
+
import"./chunk-azbab59e.js";
|
|
260
|
+
import"./chunk-3nk9q8dr.js";
|
|
261
|
+
import {
|
|
262
|
+
__require,
|
|
263
|
+
__toCommonJS
|
|
264
|
+
} from "./chunk-hhsxm2yr.js";
|
|
265
|
+
|
|
266
|
+
// src/bridge/initReplBridge.ts
|
|
267
|
+
init_state();
|
|
268
|
+
init_growthbook();
|
|
269
|
+
init_client();
|
|
270
|
+
init_policyLimits();
|
|
271
|
+
init_auth();
|
|
272
|
+
init_config();
|
|
273
|
+
init_debug();
|
|
274
|
+
init_displayTags();
|
|
275
|
+
init_errors();
|
|
276
|
+
init_git();
|
|
277
|
+
init_mappers();
|
|
278
|
+
init_messages();
|
|
279
|
+
init_sessionStorage();
|
|
280
|
+
init_sessionTitle();
|
|
281
|
+
init_words();
|
|
282
|
+
init_bridgeConfig();
|
|
283
|
+
init_bridgeEnv();
|
|
284
|
+
init_bridgeEnabled();
|
|
285
|
+
init_createSession();
|
|
286
|
+
init_debugUtils();
|
|
287
|
+
init_envLessBridgeConfig();
|
|
288
|
+
import { hostname } from "os";
|
|
289
|
+
|
|
290
|
+
// src/bridge/replBridge.ts
|
|
291
|
+
init_bridgeApi();
|
|
292
|
+
init_debug();
|
|
293
|
+
init_rcDebugLog();
|
|
294
|
+
init_diagLogs();
|
|
295
|
+
init_analytics();
|
|
296
|
+
init_cleanupRegistry();
|
|
297
|
+
import { randomUUID } from "crypto";
|
|
298
|
+
init_sessionIdCompat();
|
|
299
|
+
init_concurrentSessions();
|
|
300
|
+
init_trustedDevice();
|
|
301
|
+
init_sessionIngressAuth();
|
|
302
|
+
init_sessionState();
|
|
303
|
+
init_envUtils();
|
|
304
|
+
init_bridgeApi();
|
|
305
|
+
init_debugUtils();
|
|
306
|
+
init_bridgeEnv();
|
|
307
|
+
init_errors();
|
|
308
|
+
init_sleep();
|
|
309
|
+
init_bridgeDebug();
|
|
310
|
+
var POLL_ERROR_INITIAL_DELAY_MS = 2000;
|
|
311
|
+
var POLL_ERROR_MAX_DELAY_MS = 60000;
|
|
312
|
+
var POLL_ERROR_GIVE_UP_MS = 15 * 60 * 1000;
|
|
313
|
+
var initSequence = 0;
|
|
314
|
+
async function initBridgeCore(params) {
|
|
315
|
+
const {
|
|
316
|
+
dir,
|
|
317
|
+
machineName,
|
|
318
|
+
branch,
|
|
319
|
+
gitRepoUrl,
|
|
320
|
+
title,
|
|
321
|
+
baseUrl,
|
|
322
|
+
sessionIngressUrl,
|
|
323
|
+
workerType,
|
|
324
|
+
getAccessToken,
|
|
325
|
+
createSession,
|
|
326
|
+
archiveSession,
|
|
327
|
+
getCurrentTitle = () => title,
|
|
328
|
+
toSDKMessages: toSDKMessages2 = () => {
|
|
329
|
+
throw new Error("BridgeCoreParams.toSDKMessages not provided. Pass it if you use writeMessages() or initialMessages \u2014 daemon callers that only use writeSdkMessages() never hit this path.");
|
|
330
|
+
},
|
|
331
|
+
onAuth401,
|
|
332
|
+
getPollIntervalConfig: getPollIntervalConfig2 = () => DEFAULT_POLL_CONFIG,
|
|
333
|
+
initialHistoryCap = 200,
|
|
334
|
+
initialMessages,
|
|
335
|
+
previouslyFlushedUUIDs,
|
|
336
|
+
onInboundMessage,
|
|
337
|
+
onPermissionResponse,
|
|
338
|
+
onInterrupt,
|
|
339
|
+
onSetModel,
|
|
340
|
+
onSetMaxThinkingTokens,
|
|
341
|
+
onSetPermissionMode,
|
|
342
|
+
onStateChange,
|
|
343
|
+
onUserMessage,
|
|
344
|
+
perpetual,
|
|
345
|
+
initialSSESequenceNum = 0
|
|
346
|
+
} = params;
|
|
347
|
+
const seq = ++initSequence;
|
|
348
|
+
const { writeBridgePointer, clearBridgePointer, readBridgePointer } = await import("./chunk-1a5cep8h.js");
|
|
349
|
+
const rawPrior = perpetual ? await readBridgePointer(dir) : null;
|
|
350
|
+
const prior = rawPrior?.source === "repl" ? rawPrior : null;
|
|
351
|
+
logForDebugging(`[bridge:repl] initBridgeCore #${seq} starting (initialMessages=${initialMessages?.length ?? 0}${prior ? ` perpetual prior=env:${prior.environmentId}` : ""})`);
|
|
352
|
+
const rawApi = createBridgeApiClient({
|
|
353
|
+
baseUrl,
|
|
354
|
+
getAccessToken,
|
|
355
|
+
runnerVersion: "1.0.0",
|
|
356
|
+
onDebug: logForDebugging,
|
|
357
|
+
onAuth401,
|
|
358
|
+
getTrustedDeviceToken
|
|
359
|
+
});
|
|
360
|
+
const api = process.env.USER_TYPE === "ant" ? wrapApiForFaultInjection(rawApi) : rawApi;
|
|
361
|
+
const bridgeConfig = {
|
|
362
|
+
dir,
|
|
363
|
+
machineName,
|
|
364
|
+
branch,
|
|
365
|
+
gitRepoUrl,
|
|
366
|
+
maxSessions: 1,
|
|
367
|
+
spawnMode: "single-session",
|
|
368
|
+
verbose: false,
|
|
369
|
+
sandbox: false,
|
|
370
|
+
bridgeId: randomUUID(),
|
|
371
|
+
workerType,
|
|
372
|
+
environmentId: randomUUID(),
|
|
373
|
+
reuseEnvironmentId: prior?.environmentId,
|
|
374
|
+
apiBaseUrl: baseUrl,
|
|
375
|
+
sessionIngressUrl
|
|
376
|
+
};
|
|
377
|
+
let environmentId;
|
|
378
|
+
let environmentSecret;
|
|
379
|
+
try {
|
|
380
|
+
const reg = await api.registerBridgeEnvironment(bridgeConfig);
|
|
381
|
+
environmentId = reg.environment_id;
|
|
382
|
+
environmentSecret = reg.environment_secret;
|
|
383
|
+
} catch (err) {
|
|
384
|
+
logBridgeSkip("registration_failed", `[bridge:repl] Environment registration failed: ${errorMessage(err)}`);
|
|
385
|
+
if (prior) {
|
|
386
|
+
await clearBridgePointer(dir);
|
|
387
|
+
}
|
|
388
|
+
onStateChange?.("failed", errorMessage(err));
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
logForDebugging(`[bridge:repl] Environment registered: ${environmentId}`);
|
|
392
|
+
logForDiagnosticsNoPII("info", "bridge_repl_env_registered");
|
|
393
|
+
logEvent("tengu_bridge_repl_env_registered", {});
|
|
394
|
+
async function tryReconnectInPlace(requestedEnvId, sessionId) {
|
|
395
|
+
if (environmentId !== requestedEnvId) {
|
|
396
|
+
logForDebugging(`[bridge:repl] Env mismatch (requested ${requestedEnvId}, got ${environmentId}) \u2014 cannot reconnect in place`);
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
const infraId = toInfraSessionId(sessionId);
|
|
400
|
+
const candidates = infraId === sessionId ? [sessionId] : [sessionId, infraId];
|
|
401
|
+
for (const id of candidates) {
|
|
402
|
+
try {
|
|
403
|
+
await api.reconnectSession(environmentId, id);
|
|
404
|
+
logForDebugging(`[bridge:repl] Reconnected session ${id} in place on env ${environmentId}`);
|
|
405
|
+
return true;
|
|
406
|
+
} catch (err) {
|
|
407
|
+
logForDebugging(`[bridge:repl] reconnectSession(${id}) failed: ${errorMessage(err)}`);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
logForDebugging("[bridge:repl] reconnectSession exhausted \u2014 falling through to fresh session");
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
const reusedPriorSession = prior ? await tryReconnectInPlace(prior.environmentId, prior.sessionId) : false;
|
|
414
|
+
if (prior && !reusedPriorSession) {
|
|
415
|
+
await clearBridgePointer(dir);
|
|
416
|
+
}
|
|
417
|
+
let currentSessionId;
|
|
418
|
+
if (reusedPriorSession && prior) {
|
|
419
|
+
currentSessionId = prior.sessionId;
|
|
420
|
+
logForDebugging(`[bridge:repl] Perpetual session reused: ${currentSessionId}`);
|
|
421
|
+
if (initialMessages && previouslyFlushedUUIDs) {
|
|
422
|
+
for (const msg of initialMessages) {
|
|
423
|
+
previouslyFlushedUUIDs.add(msg.uuid);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
} else {
|
|
427
|
+
const createdSessionId = await createSession({
|
|
428
|
+
environmentId,
|
|
429
|
+
title,
|
|
430
|
+
gitRepoUrl,
|
|
431
|
+
branch,
|
|
432
|
+
signal: AbortSignal.timeout(15000)
|
|
433
|
+
});
|
|
434
|
+
if (!createdSessionId) {
|
|
435
|
+
logForDebugging("[bridge:repl] Session creation failed, deregistering environment");
|
|
436
|
+
logEvent("tengu_bridge_repl_session_failed", {});
|
|
437
|
+
await api.deregisterEnvironment(environmentId).catch(() => {});
|
|
438
|
+
onStateChange?.("failed", "Session creation failed");
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
currentSessionId = createdSessionId;
|
|
442
|
+
logForDebugging(`[bridge:repl] Session created: ${currentSessionId}`);
|
|
443
|
+
}
|
|
444
|
+
await writeBridgePointer(dir, {
|
|
445
|
+
sessionId: currentSessionId,
|
|
446
|
+
environmentId,
|
|
447
|
+
source: "repl"
|
|
448
|
+
});
|
|
449
|
+
logForDiagnosticsNoPII("info", "bridge_repl_session_created");
|
|
450
|
+
logEvent("tengu_bridge_repl_started", {
|
|
451
|
+
has_initial_messages: !!(initialMessages && initialMessages.length > 0),
|
|
452
|
+
inProtectedNamespace: isInProtectedNamespace()
|
|
453
|
+
});
|
|
454
|
+
const initialMessageUUIDs = new Set;
|
|
455
|
+
if (initialMessages) {
|
|
456
|
+
for (const msg of initialMessages) {
|
|
457
|
+
initialMessageUUIDs.add(msg.uuid);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
const recentPostedUUIDs = new BoundedUUIDSet(2000);
|
|
461
|
+
for (const uuid of initialMessageUUIDs) {
|
|
462
|
+
recentPostedUUIDs.add(uuid);
|
|
463
|
+
}
|
|
464
|
+
const recentInboundUUIDs = new BoundedUUIDSet(2000);
|
|
465
|
+
const pollController = new AbortController;
|
|
466
|
+
let transport = null;
|
|
467
|
+
setSessionMetadataChangedListener((metadata) => {
|
|
468
|
+
if (pollController.signal.aborted)
|
|
469
|
+
return;
|
|
470
|
+
transport?.reportMetadata(metadata);
|
|
471
|
+
}, { replayCurrent: true });
|
|
472
|
+
let v2Generation = 0;
|
|
473
|
+
let lastTransportSequenceNum = reusedPriorSession ? initialSSESequenceNum : 0;
|
|
474
|
+
let currentWorkId = null;
|
|
475
|
+
let currentIngressToken = null;
|
|
476
|
+
const capacityWake = createCapacityWake(pollController.signal);
|
|
477
|
+
const wakePollLoop = capacityWake.wake;
|
|
478
|
+
const capacitySignal = capacityWake.signal;
|
|
479
|
+
const flushGate = new FlushGate;
|
|
480
|
+
let userMessageCallbackDone = !onUserMessage;
|
|
481
|
+
const MAX_ENVIRONMENT_RECREATIONS = 3;
|
|
482
|
+
let environmentRecreations = 0;
|
|
483
|
+
let reconnectPromise = null;
|
|
484
|
+
async function reconnectEnvironmentWithSession() {
|
|
485
|
+
if (reconnectPromise) {
|
|
486
|
+
return reconnectPromise;
|
|
487
|
+
}
|
|
488
|
+
reconnectPromise = doReconnect();
|
|
489
|
+
try {
|
|
490
|
+
return await reconnectPromise;
|
|
491
|
+
} finally {
|
|
492
|
+
reconnectPromise = null;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
async function doReconnect() {
|
|
496
|
+
environmentRecreations++;
|
|
497
|
+
rcLog(`doReconnect: attempt=${environmentRecreations}/${MAX_ENVIRONMENT_RECREATIONS} envId=${environmentId} sessionId=${currentSessionId} workId=${currentWorkId}`);
|
|
498
|
+
v2Generation++;
|
|
499
|
+
logForDebugging(`[bridge:repl] Reconnecting after env lost (attempt ${environmentRecreations}/${MAX_ENVIRONMENT_RECREATIONS})`);
|
|
500
|
+
if (environmentRecreations > MAX_ENVIRONMENT_RECREATIONS) {
|
|
501
|
+
logForDebugging(`[bridge:repl] Environment reconnect limit reached (${MAX_ENVIRONMENT_RECREATIONS}), giving up`);
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
if (transport) {
|
|
505
|
+
const seq2 = transport.getLastSequenceNum();
|
|
506
|
+
if (seq2 > lastTransportSequenceNum) {
|
|
507
|
+
lastTransportSequenceNum = seq2;
|
|
508
|
+
}
|
|
509
|
+
transport.close();
|
|
510
|
+
transport = null;
|
|
511
|
+
}
|
|
512
|
+
wakePollLoop();
|
|
513
|
+
flushGate.drop();
|
|
514
|
+
if (currentWorkId) {
|
|
515
|
+
const workIdBeingCleared = currentWorkId;
|
|
516
|
+
await api.stopWork(environmentId, workIdBeingCleared, false).catch(() => {});
|
|
517
|
+
if (currentWorkId !== workIdBeingCleared) {
|
|
518
|
+
logForDebugging("[bridge:repl] Poll loop recovered during stopWork await \u2014 deferring to it");
|
|
519
|
+
environmentRecreations = 0;
|
|
520
|
+
return true;
|
|
521
|
+
}
|
|
522
|
+
currentWorkId = null;
|
|
523
|
+
currentIngressToken = null;
|
|
524
|
+
}
|
|
525
|
+
if (pollController.signal.aborted) {
|
|
526
|
+
logForDebugging("[bridge:repl] Reconnect aborted by teardown");
|
|
527
|
+
return false;
|
|
528
|
+
}
|
|
529
|
+
const requestedEnvId = environmentId;
|
|
530
|
+
bridgeConfig.reuseEnvironmentId = requestedEnvId;
|
|
531
|
+
try {
|
|
532
|
+
const reg = await api.registerBridgeEnvironment(bridgeConfig);
|
|
533
|
+
environmentId = reg.environment_id;
|
|
534
|
+
environmentSecret = reg.environment_secret;
|
|
535
|
+
} catch (err) {
|
|
536
|
+
bridgeConfig.reuseEnvironmentId = undefined;
|
|
537
|
+
logForDebugging(`[bridge:repl] Environment re-registration failed: ${errorMessage(err)}`);
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
540
|
+
bridgeConfig.reuseEnvironmentId = undefined;
|
|
541
|
+
logForDebugging(`[bridge:repl] Re-registered: requested=${requestedEnvId} got=${environmentId}`);
|
|
542
|
+
if (pollController.signal.aborted) {
|
|
543
|
+
logForDebugging("[bridge:repl] Reconnect aborted after env registration, cleaning up");
|
|
544
|
+
await api.deregisterEnvironment(environmentId).catch(() => {});
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
if (transport !== null) {
|
|
548
|
+
logForDebugging("[bridge:repl] Poll loop recovered during registerBridgeEnvironment await \u2014 deferring to it");
|
|
549
|
+
environmentRecreations = 0;
|
|
550
|
+
return true;
|
|
551
|
+
}
|
|
552
|
+
if (await tryReconnectInPlace(requestedEnvId, currentSessionId)) {
|
|
553
|
+
logEvent("tengu_bridge_repl_reconnected_in_place", {});
|
|
554
|
+
environmentRecreations = 0;
|
|
555
|
+
return true;
|
|
556
|
+
}
|
|
557
|
+
if (environmentId !== requestedEnvId) {
|
|
558
|
+
logEvent("tengu_bridge_repl_env_expired_fresh_session", {});
|
|
559
|
+
}
|
|
560
|
+
await archiveSession(currentSessionId);
|
|
561
|
+
if (pollController.signal.aborted) {
|
|
562
|
+
logForDebugging("[bridge:repl] Reconnect aborted after archive, cleaning up");
|
|
563
|
+
await api.deregisterEnvironment(environmentId).catch(() => {});
|
|
564
|
+
return false;
|
|
565
|
+
}
|
|
566
|
+
const currentTitle = getCurrentTitle();
|
|
567
|
+
const newSessionId = await createSession({
|
|
568
|
+
environmentId,
|
|
569
|
+
title: currentTitle,
|
|
570
|
+
gitRepoUrl,
|
|
571
|
+
branch,
|
|
572
|
+
signal: AbortSignal.timeout(15000)
|
|
573
|
+
});
|
|
574
|
+
if (!newSessionId) {
|
|
575
|
+
logForDebugging("[bridge:repl] Session creation failed during reconnection");
|
|
576
|
+
return false;
|
|
577
|
+
}
|
|
578
|
+
if (pollController.signal.aborted) {
|
|
579
|
+
logForDebugging("[bridge:repl] Reconnect aborted after session creation, cleaning up");
|
|
580
|
+
await archiveSession(newSessionId);
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
currentSessionId = newSessionId;
|
|
584
|
+
updateSessionBridgeId(toCompatSessionId(newSessionId)).catch(() => {});
|
|
585
|
+
lastTransportSequenceNum = 0;
|
|
586
|
+
recentInboundUUIDs.clear();
|
|
587
|
+
userMessageCallbackDone = !onUserMessage;
|
|
588
|
+
logForDebugging(`[bridge:repl] Re-created session: ${currentSessionId}`);
|
|
589
|
+
await writeBridgePointer(dir, {
|
|
590
|
+
sessionId: currentSessionId,
|
|
591
|
+
environmentId,
|
|
592
|
+
source: "repl"
|
|
593
|
+
});
|
|
594
|
+
previouslyFlushedUUIDs?.clear();
|
|
595
|
+
environmentRecreations = 0;
|
|
596
|
+
return true;
|
|
597
|
+
}
|
|
598
|
+
function getOAuthToken() {
|
|
599
|
+
return getAccessToken();
|
|
600
|
+
}
|
|
601
|
+
function drainFlushGate() {
|
|
602
|
+
const msgs = flushGate.end();
|
|
603
|
+
if (msgs.length === 0)
|
|
604
|
+
return;
|
|
605
|
+
if (!transport) {
|
|
606
|
+
logForDebugging(`[bridge:repl] Cannot drain ${msgs.length} pending message(s): no transport`);
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
for (const msg of msgs) {
|
|
610
|
+
recentPostedUUIDs.add(msg.uuid);
|
|
611
|
+
}
|
|
612
|
+
const sdkMessages = toSDKMessages2(msgs);
|
|
613
|
+
const events = sdkMessages.map((sdkMsg) => ({
|
|
614
|
+
...sdkMsg,
|
|
615
|
+
session_id: currentSessionId
|
|
616
|
+
}));
|
|
617
|
+
logForDebugging(`[bridge:repl] Drained ${msgs.length} pending message(s) after flush`);
|
|
618
|
+
transport.writeBatch(events);
|
|
619
|
+
}
|
|
620
|
+
let doTeardownImpl = null;
|
|
621
|
+
function triggerTeardown() {
|
|
622
|
+
doTeardownImpl?.();
|
|
623
|
+
}
|
|
624
|
+
function handleTransportPermanentClose(closeCode) {
|
|
625
|
+
rcLog(`handleTransportPermanentClose: code=${closeCode} transport=${transport ? "exists" : "null"} pollAborted=${pollController.signal.aborted}`);
|
|
626
|
+
logForDebugging(`[bridge:repl] Transport permanently closed: code=${closeCode}`);
|
|
627
|
+
logEvent("tengu_bridge_repl_ws_closed", {
|
|
628
|
+
code: closeCode
|
|
629
|
+
});
|
|
630
|
+
if (transport) {
|
|
631
|
+
const closedSeq = transport.getLastSequenceNum();
|
|
632
|
+
if (closedSeq > lastTransportSequenceNum) {
|
|
633
|
+
lastTransportSequenceNum = closedSeq;
|
|
634
|
+
}
|
|
635
|
+
transport = null;
|
|
636
|
+
}
|
|
637
|
+
wakePollLoop();
|
|
638
|
+
const dropped = flushGate.drop();
|
|
639
|
+
if (dropped > 0) {
|
|
640
|
+
logForDebugging(`[bridge:repl] Dropping ${dropped} pending message(s) on transport close (code=${closeCode})`, { level: "warn" });
|
|
641
|
+
}
|
|
642
|
+
if (closeCode === 1000) {
|
|
643
|
+
onStateChange?.("failed", "session ended");
|
|
644
|
+
pollController.abort();
|
|
645
|
+
triggerTeardown();
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
onStateChange?.("reconnecting", `Remote Control connection lost (code ${closeCode})`);
|
|
649
|
+
logForDebugging(`[bridge:repl] Transport reconnect budget exhausted (code=${closeCode}), attempting env reconnect`);
|
|
650
|
+
reconnectEnvironmentWithSession().then((success) => {
|
|
651
|
+
if (success)
|
|
652
|
+
return;
|
|
653
|
+
if (pollController.signal.aborted)
|
|
654
|
+
return;
|
|
655
|
+
logForDebugging("[bridge:repl] reconnectEnvironmentWithSession resolved false \u2014 tearing down");
|
|
656
|
+
logEvent("tengu_bridge_repl_reconnect_failed", {
|
|
657
|
+
close_code: closeCode
|
|
658
|
+
});
|
|
659
|
+
onStateChange?.("failed", "reconnection failed");
|
|
660
|
+
triggerTeardown();
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
let sigusr2Handler;
|
|
664
|
+
if (process.env.USER_TYPE === "ant" && process.platform !== "win32") {
|
|
665
|
+
sigusr2Handler = () => {
|
|
666
|
+
logForDebugging("[bridge:repl] SIGUSR2 received \u2014 forcing doReconnect() for testing");
|
|
667
|
+
reconnectEnvironmentWithSession();
|
|
668
|
+
};
|
|
669
|
+
process.on("SIGUSR2", sigusr2Handler);
|
|
670
|
+
}
|
|
671
|
+
let debugFireClose = null;
|
|
672
|
+
if (process.env.USER_TYPE === "ant") {
|
|
673
|
+
registerBridgeDebugHandle({
|
|
674
|
+
fireClose: (code) => {
|
|
675
|
+
if (!debugFireClose) {
|
|
676
|
+
logForDebugging("[bridge:debug] fireClose: no transport wired yet");
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
logForDebugging(`[bridge:debug] fireClose(${code}) \u2014 injecting`);
|
|
680
|
+
debugFireClose(code);
|
|
681
|
+
},
|
|
682
|
+
forceReconnect: () => {
|
|
683
|
+
logForDebugging("[bridge:debug] forceReconnect \u2014 injecting");
|
|
684
|
+
reconnectEnvironmentWithSession();
|
|
685
|
+
},
|
|
686
|
+
injectFault: injectBridgeFault,
|
|
687
|
+
wakePollLoop,
|
|
688
|
+
describe: () => `env=${environmentId} session=${currentSessionId} transport=${transport?.getStateLabel() ?? "null"} workId=${currentWorkId ?? "null"}`
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
const pollOpts = {
|
|
692
|
+
api,
|
|
693
|
+
getCredentials: () => ({ environmentId, environmentSecret }),
|
|
694
|
+
signal: pollController.signal,
|
|
695
|
+
getPollIntervalConfig: getPollIntervalConfig2,
|
|
696
|
+
onStateChange,
|
|
697
|
+
getWsState: () => transport?.getStateLabel() ?? "null",
|
|
698
|
+
isAtCapacity: () => transport !== null,
|
|
699
|
+
capacitySignal,
|
|
700
|
+
onFatalError: triggerTeardown,
|
|
701
|
+
getHeartbeatInfo: () => {
|
|
702
|
+
if (!currentWorkId || !currentIngressToken) {
|
|
703
|
+
return null;
|
|
704
|
+
}
|
|
705
|
+
return {
|
|
706
|
+
environmentId,
|
|
707
|
+
workId: currentWorkId,
|
|
708
|
+
sessionToken: currentIngressToken
|
|
709
|
+
};
|
|
710
|
+
},
|
|
711
|
+
onHeartbeatFatal: (err) => {
|
|
712
|
+
logForDebugging(`[bridge:repl] heartbeatWork fatal (status=${err.status}) \u2014 tearing down work item for fast re-dispatch`);
|
|
713
|
+
if (transport) {
|
|
714
|
+
const seq2 = transport.getLastSequenceNum();
|
|
715
|
+
if (seq2 > lastTransportSequenceNum) {
|
|
716
|
+
lastTransportSequenceNum = seq2;
|
|
717
|
+
}
|
|
718
|
+
transport.close();
|
|
719
|
+
transport = null;
|
|
720
|
+
}
|
|
721
|
+
flushGate.drop();
|
|
722
|
+
if (currentWorkId) {
|
|
723
|
+
api.stopWork(environmentId, currentWorkId, false).catch((e) => {
|
|
724
|
+
logForDebugging(`[bridge:repl] stopWork after heartbeat fatal: ${errorMessage(e)}`);
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
currentWorkId = null;
|
|
728
|
+
currentIngressToken = null;
|
|
729
|
+
wakePollLoop();
|
|
730
|
+
onStateChange?.("reconnecting", "Work item lease expired, fetching fresh token");
|
|
731
|
+
},
|
|
732
|
+
async onEnvironmentLost() {
|
|
733
|
+
const success = await reconnectEnvironmentWithSession();
|
|
734
|
+
if (!success) {
|
|
735
|
+
return null;
|
|
736
|
+
}
|
|
737
|
+
return { environmentId, environmentSecret };
|
|
738
|
+
},
|
|
739
|
+
onWorkReceived: (workSessionId, ingressToken, workId, serverUseCcrV2) => {
|
|
740
|
+
if (transport?.isConnectedStatus()) {
|
|
741
|
+
logForDebugging(`[bridge:repl] Work received while transport connected, replacing with fresh token (workId=${workId})`);
|
|
742
|
+
}
|
|
743
|
+
logForDebugging(`[bridge:repl] Work received: workId=${workId} workSessionId=${workSessionId} currentSessionId=${currentSessionId} match=${sameSessionId(workSessionId, currentSessionId)}`);
|
|
744
|
+
writeBridgePointer(dir, {
|
|
745
|
+
sessionId: currentSessionId,
|
|
746
|
+
environmentId,
|
|
747
|
+
source: "repl"
|
|
748
|
+
});
|
|
749
|
+
if (!sameSessionId(workSessionId, currentSessionId)) {
|
|
750
|
+
logForDebugging(`[bridge:repl] Rejecting foreign session: expected=${currentSessionId} got=${workSessionId}`);
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
currentWorkId = workId;
|
|
754
|
+
currentIngressToken = ingressToken;
|
|
755
|
+
const useCcrV2 = serverUseCcrV2 || isBridgeCcrV2OverrideEnabled();
|
|
756
|
+
let v1OauthToken;
|
|
757
|
+
if (!useCcrV2) {
|
|
758
|
+
v1OauthToken = getOAuthToken();
|
|
759
|
+
if (!v1OauthToken) {
|
|
760
|
+
logForDebugging("[bridge:repl] No OAuth token available for session ingress, skipping work");
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
updateSessionIngressAuthToken(v1OauthToken);
|
|
764
|
+
}
|
|
765
|
+
logEvent("tengu_bridge_repl_work_received", {});
|
|
766
|
+
if (transport) {
|
|
767
|
+
const oldTransport = transport;
|
|
768
|
+
transport = null;
|
|
769
|
+
const oldSeq = oldTransport.getLastSequenceNum();
|
|
770
|
+
if (oldSeq > lastTransportSequenceNum) {
|
|
771
|
+
lastTransportSequenceNum = oldSeq;
|
|
772
|
+
}
|
|
773
|
+
oldTransport.close();
|
|
774
|
+
}
|
|
775
|
+
flushGate.deactivate();
|
|
776
|
+
const onServerControlRequest = (request) => handleServerControlRequest(request, {
|
|
777
|
+
transport,
|
|
778
|
+
sessionId: currentSessionId,
|
|
779
|
+
onInterrupt,
|
|
780
|
+
onSetModel,
|
|
781
|
+
onSetMaxThinkingTokens,
|
|
782
|
+
onSetPermissionMode
|
|
783
|
+
});
|
|
784
|
+
let initialFlushDone = false;
|
|
785
|
+
const wireTransport = (newTransport) => {
|
|
786
|
+
transport = newTransport;
|
|
787
|
+
newTransport.setOnConnect(() => {
|
|
788
|
+
if (transport !== newTransport)
|
|
789
|
+
return;
|
|
790
|
+
logForDebugging("[bridge:repl] Ingress transport connected");
|
|
791
|
+
logEvent("tengu_bridge_repl_ws_connected", {});
|
|
792
|
+
if (!useCcrV2) {
|
|
793
|
+
const freshToken = getOAuthToken();
|
|
794
|
+
if (freshToken) {
|
|
795
|
+
updateSessionIngressAuthToken(freshToken);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
teardownStarted = false;
|
|
799
|
+
if (!initialFlushDone && initialMessages && initialMessages.length > 0) {
|
|
800
|
+
initialFlushDone = true;
|
|
801
|
+
const historyCap = initialHistoryCap;
|
|
802
|
+
const eligibleMessages = initialMessages.filter((m) => isEligibleBridgeMessage(m) && !previouslyFlushedUUIDs?.has(m.uuid));
|
|
803
|
+
const cappedMessages = historyCap > 0 && eligibleMessages.length > historyCap ? eligibleMessages.slice(-historyCap) : eligibleMessages;
|
|
804
|
+
if (cappedMessages.length < eligibleMessages.length) {
|
|
805
|
+
logForDebugging(`[bridge:repl] Capped initial flush: ${eligibleMessages.length} -> ${cappedMessages.length} (cap=${historyCap})`);
|
|
806
|
+
logEvent("tengu_bridge_repl_history_capped", {
|
|
807
|
+
eligible_count: eligibleMessages.length,
|
|
808
|
+
capped_count: cappedMessages.length
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
const sdkMessages = toSDKMessages2(cappedMessages);
|
|
812
|
+
if (sdkMessages.length > 0) {
|
|
813
|
+
logForDebugging(`[bridge:repl] Flushing ${sdkMessages.length} initial message(s) via transport`);
|
|
814
|
+
const events = sdkMessages.map((sdkMsg) => ({
|
|
815
|
+
...sdkMsg,
|
|
816
|
+
session_id: currentSessionId
|
|
817
|
+
}));
|
|
818
|
+
const dropsBefore = newTransport.droppedBatchCount;
|
|
819
|
+
newTransport.writeBatch(events).then(() => {
|
|
820
|
+
if (newTransport.droppedBatchCount > dropsBefore) {
|
|
821
|
+
logForDebugging(`[bridge:repl] Initial flush dropped ${newTransport.droppedBatchCount - dropsBefore} batch(es) \u2014 not marking ${sdkMessages.length} UUID(s) as flushed`);
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
if (previouslyFlushedUUIDs) {
|
|
825
|
+
for (const sdkMsg of sdkMessages) {
|
|
826
|
+
if (sdkMsg.uuid) {
|
|
827
|
+
previouslyFlushedUUIDs.add(sdkMsg.uuid);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
}).catch((e) => logForDebugging(`[bridge:repl] Initial flush failed: ${e}`)).finally(() => {
|
|
832
|
+
if (transport !== newTransport)
|
|
833
|
+
return;
|
|
834
|
+
drainFlushGate();
|
|
835
|
+
onStateChange?.("connected");
|
|
836
|
+
});
|
|
837
|
+
} else {
|
|
838
|
+
drainFlushGate();
|
|
839
|
+
onStateChange?.("connected");
|
|
840
|
+
}
|
|
841
|
+
} else if (!flushGate.active) {
|
|
842
|
+
onStateChange?.("connected");
|
|
843
|
+
}
|
|
844
|
+
});
|
|
845
|
+
newTransport.setOnData((data) => {
|
|
846
|
+
try {
|
|
847
|
+
const parsed = JSON.parse(data);
|
|
848
|
+
rcLog(`ingress: type=${parsed.type}${parsed.type === "control_request" ? ` subtype=${parsed.request?.subtype} request_id=${parsed.request_id}` : ""}${parsed.type === "control_response" ? ` subtype=${parsed.response?.subtype} request_id=${parsed.response?.request_id}` : ""}${parsed.type === "user" ? ` uuid=${parsed.uuid}` : ""}${parsed.type === "keep_alive" ? "" : ` len=${data.length}`}`);
|
|
849
|
+
} catch {
|
|
850
|
+
rcLog(`ingress (non-JSON): ${String(data).slice(0, 200)}`);
|
|
851
|
+
}
|
|
852
|
+
handleIngressMessage(data, recentPostedUUIDs, recentInboundUUIDs, onInboundMessage, onPermissionResponse, onServerControlRequest);
|
|
853
|
+
});
|
|
854
|
+
debugFireClose = handleTransportPermanentClose;
|
|
855
|
+
newTransport.setOnClose((closeCode) => {
|
|
856
|
+
if (transport !== newTransport)
|
|
857
|
+
return;
|
|
858
|
+
rcLog(`transport onClose: code=${closeCode} connected=${newTransport.isConnectedStatus()} state=${newTransport.getStateLabel()} seq=${newTransport.getLastSequenceNum()}`);
|
|
859
|
+
handleTransportPermanentClose(closeCode);
|
|
860
|
+
});
|
|
861
|
+
if (!initialFlushDone && initialMessages && initialMessages.length > 0) {
|
|
862
|
+
flushGate.start();
|
|
863
|
+
}
|
|
864
|
+
newTransport.connect();
|
|
865
|
+
};
|
|
866
|
+
v2Generation++;
|
|
867
|
+
if (useCcrV2) {
|
|
868
|
+
const sessionUrl = buildCCRv2SdkUrl(baseUrl, workSessionId);
|
|
869
|
+
const thisGen = v2Generation;
|
|
870
|
+
logForDebugging(`[bridge:repl] CCR v2: sessionUrl=${sessionUrl} session=${workSessionId} gen=${thisGen}`);
|
|
871
|
+
createV2ReplTransport({
|
|
872
|
+
sessionUrl,
|
|
873
|
+
ingressToken,
|
|
874
|
+
sessionId: workSessionId,
|
|
875
|
+
initialSequenceNum: lastTransportSequenceNum
|
|
876
|
+
}).then((t) => {
|
|
877
|
+
if (pollController.signal.aborted) {
|
|
878
|
+
t.close();
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
if (thisGen !== v2Generation) {
|
|
882
|
+
logForDebugging(`[bridge:repl] CCR v2: discarding stale handshake gen=${thisGen} current=${v2Generation}`);
|
|
883
|
+
t.close();
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
wireTransport(t);
|
|
887
|
+
}, (err) => {
|
|
888
|
+
logForDebugging(`[bridge:repl] CCR v2: createV2ReplTransport failed: ${errorMessage(err)}`, { level: "error" });
|
|
889
|
+
logEvent("tengu_bridge_repl_ccr_v2_init_failed", {});
|
|
890
|
+
if (thisGen !== v2Generation)
|
|
891
|
+
return;
|
|
892
|
+
if (currentWorkId) {
|
|
893
|
+
api.stopWork(environmentId, currentWorkId, false).catch((e) => {
|
|
894
|
+
logForDebugging(`[bridge:repl] stopWork after v2 init failure: ${errorMessage(e)}`);
|
|
895
|
+
});
|
|
896
|
+
currentWorkId = null;
|
|
897
|
+
currentIngressToken = null;
|
|
898
|
+
}
|
|
899
|
+
wakePollLoop();
|
|
900
|
+
});
|
|
901
|
+
} else {
|
|
902
|
+
const wsUrl = buildSdkUrl(sessionIngressUrl, workSessionId);
|
|
903
|
+
logForDebugging(`[bridge:repl] Ingress URL: ${wsUrl}`);
|
|
904
|
+
logForDebugging(`[bridge:repl] Creating HybridTransport: session=${workSessionId}`);
|
|
905
|
+
const oauthToken = v1OauthToken ?? "";
|
|
906
|
+
wireTransport(createV1ReplTransport(new HybridTransport(new URL(wsUrl), {
|
|
907
|
+
Authorization: `Bearer ${oauthToken}`,
|
|
908
|
+
"anthropic-version": "2023-06-01"
|
|
909
|
+
}, workSessionId, () => ({
|
|
910
|
+
Authorization: `Bearer ${getOAuthToken() ?? oauthToken}`,
|
|
911
|
+
"anthropic-version": "2023-06-01"
|
|
912
|
+
}), {
|
|
913
|
+
maxConsecutiveFailures: 50,
|
|
914
|
+
isBridge: true,
|
|
915
|
+
onBatchDropped: () => {
|
|
916
|
+
onStateChange?.("reconnecting", "Lost sync with Remote Control \u2014 events could not be delivered");
|
|
917
|
+
wakePollLoop();
|
|
918
|
+
}
|
|
919
|
+
})));
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
startWorkPollLoop(pollOpts);
|
|
924
|
+
const pointerRefreshTimer = perpetual ? setInterval(() => {
|
|
925
|
+
if (reconnectPromise)
|
|
926
|
+
return;
|
|
927
|
+
writeBridgePointer(dir, {
|
|
928
|
+
sessionId: currentSessionId,
|
|
929
|
+
environmentId,
|
|
930
|
+
source: "repl"
|
|
931
|
+
});
|
|
932
|
+
}, 3600000) : null;
|
|
933
|
+
pointerRefreshTimer?.unref?.();
|
|
934
|
+
const keepAliveIntervalMs = getPollIntervalConfig2().session_keepalive_interval_v2_ms;
|
|
935
|
+
const keepAliveTimer = keepAliveIntervalMs > 0 ? setInterval(() => {
|
|
936
|
+
if (!transport)
|
|
937
|
+
return;
|
|
938
|
+
logForDebugging("[bridge:repl] keep_alive sent");
|
|
939
|
+
transport.write({ type: "keep_alive" }).catch((err) => {
|
|
940
|
+
logForDebugging(`[bridge:repl] keep_alive write failed: ${errorMessage(err)}`);
|
|
941
|
+
});
|
|
942
|
+
}, keepAliveIntervalMs) : null;
|
|
943
|
+
keepAliveTimer?.unref?.();
|
|
944
|
+
let teardownStarted = false;
|
|
945
|
+
doTeardownImpl = async () => {
|
|
946
|
+
if (teardownStarted) {
|
|
947
|
+
logForDebugging(`[bridge:repl] Teardown already in progress, skipping duplicate call env=${environmentId} session=${currentSessionId}`);
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
teardownStarted = true;
|
|
951
|
+
const teardownStart = Date.now();
|
|
952
|
+
logForDebugging(`[bridge:repl] Teardown starting: env=${environmentId} session=${currentSessionId} workId=${currentWorkId ?? "none"} transportState=${transport?.getStateLabel() ?? "null"}`);
|
|
953
|
+
if (pointerRefreshTimer !== null) {
|
|
954
|
+
clearInterval(pointerRefreshTimer);
|
|
955
|
+
}
|
|
956
|
+
if (keepAliveTimer !== null) {
|
|
957
|
+
clearInterval(keepAliveTimer);
|
|
958
|
+
}
|
|
959
|
+
if (sigusr2Handler) {
|
|
960
|
+
process.off("SIGUSR2", sigusr2Handler);
|
|
961
|
+
}
|
|
962
|
+
if (process.env.USER_TYPE === "ant") {
|
|
963
|
+
clearBridgeDebugHandle();
|
|
964
|
+
debugFireClose = null;
|
|
965
|
+
}
|
|
966
|
+
pollController.abort();
|
|
967
|
+
logForDebugging("[bridge:repl] Teardown: poll loop aborted");
|
|
968
|
+
if (transport) {
|
|
969
|
+
const finalSeq = transport.getLastSequenceNum();
|
|
970
|
+
if (finalSeq > lastTransportSequenceNum) {
|
|
971
|
+
lastTransportSequenceNum = finalSeq;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
if (perpetual) {
|
|
975
|
+
transport = null;
|
|
976
|
+
flushGate.drop();
|
|
977
|
+
await writeBridgePointer(dir, {
|
|
978
|
+
sessionId: currentSessionId,
|
|
979
|
+
environmentId,
|
|
980
|
+
source: "repl"
|
|
981
|
+
});
|
|
982
|
+
logForDebugging(`[bridge:repl] Teardown (perpetual): leaving env=${environmentId} session=${currentSessionId} alive on server, duration=${Date.now() - teardownStart}ms`);
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
const teardownTransport = transport;
|
|
986
|
+
transport = null;
|
|
987
|
+
flushGate.drop();
|
|
988
|
+
if (teardownTransport) {
|
|
989
|
+
const resultMsg = {
|
|
990
|
+
...makeResultMessage(currentSessionId),
|
|
991
|
+
session_id: currentSessionId
|
|
992
|
+
};
|
|
993
|
+
teardownTransport.write(resultMsg);
|
|
994
|
+
}
|
|
995
|
+
const stopWorkP = currentWorkId ? api.stopWork(environmentId, currentWorkId, true).then(() => {
|
|
996
|
+
logForDebugging("[bridge:repl] Teardown: stopWork completed");
|
|
997
|
+
}).catch((err) => {
|
|
998
|
+
logForDebugging(`[bridge:repl] Teardown stopWork failed: ${errorMessage(err)}`);
|
|
999
|
+
}) : Promise.resolve();
|
|
1000
|
+
await Promise.all([stopWorkP, archiveSession(currentSessionId)]);
|
|
1001
|
+
teardownTransport?.close();
|
|
1002
|
+
logForDebugging("[bridge:repl] Teardown: transport closed");
|
|
1003
|
+
await api.deregisterEnvironment(environmentId).catch((err) => {
|
|
1004
|
+
logForDebugging(`[bridge:repl] Teardown deregister failed: ${errorMessage(err)}`);
|
|
1005
|
+
});
|
|
1006
|
+
await clearBridgePointer(dir);
|
|
1007
|
+
logForDebugging(`[bridge:repl] Teardown complete: env=${environmentId} duration=${Date.now() - teardownStart}ms`);
|
|
1008
|
+
};
|
|
1009
|
+
const unregister = registerCleanup(() => doTeardownImpl?.());
|
|
1010
|
+
logForDebugging(`[bridge:repl] Ready: env=${environmentId} session=${currentSessionId}`);
|
|
1011
|
+
onStateChange?.("ready");
|
|
1012
|
+
return {
|
|
1013
|
+
get bridgeSessionId() {
|
|
1014
|
+
return currentSessionId;
|
|
1015
|
+
},
|
|
1016
|
+
get environmentId() {
|
|
1017
|
+
return environmentId;
|
|
1018
|
+
},
|
|
1019
|
+
getSSESequenceNum() {
|
|
1020
|
+
const live = transport?.getLastSequenceNum() ?? 0;
|
|
1021
|
+
return Math.max(lastTransportSequenceNum, live);
|
|
1022
|
+
},
|
|
1023
|
+
sessionIngressUrl,
|
|
1024
|
+
writeMessages(messages) {
|
|
1025
|
+
const filtered = messages.filter((m) => isEligibleBridgeMessage(m) && !initialMessageUUIDs.has(m.uuid) && !recentPostedUUIDs.has(m.uuid));
|
|
1026
|
+
if (filtered.length === 0)
|
|
1027
|
+
return;
|
|
1028
|
+
if (!userMessageCallbackDone) {
|
|
1029
|
+
for (const m of filtered) {
|
|
1030
|
+
const text = extractTitleText(m);
|
|
1031
|
+
if (text !== undefined && onUserMessage?.(text, currentSessionId)) {
|
|
1032
|
+
userMessageCallbackDone = true;
|
|
1033
|
+
break;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
if (flushGate.enqueue(...filtered)) {
|
|
1038
|
+
logForDebugging(`[bridge:repl] Queued ${filtered.length} message(s) during initial flush`);
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
|
+
if (!transport) {
|
|
1042
|
+
const types = filtered.map((m) => m.type).join(",");
|
|
1043
|
+
logForDebugging(`[bridge:repl] Transport not configured, dropping ${filtered.length} message(s) [${types}] for session=${currentSessionId}`, { level: "warn" });
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
for (const msg of filtered) {
|
|
1047
|
+
recentPostedUUIDs.add(msg.uuid);
|
|
1048
|
+
}
|
|
1049
|
+
logForDebugging(`[bridge:repl] Sending ${filtered.length} message(s) via transport`);
|
|
1050
|
+
const sdkMessages = toSDKMessages2(filtered);
|
|
1051
|
+
const events = sdkMessages.map((sdkMsg) => ({
|
|
1052
|
+
...sdkMsg,
|
|
1053
|
+
session_id: currentSessionId
|
|
1054
|
+
}));
|
|
1055
|
+
transport.writeBatch(events);
|
|
1056
|
+
},
|
|
1057
|
+
writeSdkMessages(messages) {
|
|
1058
|
+
const filtered = messages.filter((m) => !m.uuid || !recentPostedUUIDs.has(m.uuid));
|
|
1059
|
+
if (filtered.length === 0)
|
|
1060
|
+
return;
|
|
1061
|
+
if (!transport) {
|
|
1062
|
+
logForDebugging(`[bridge:repl] Transport not configured, dropping ${filtered.length} SDK message(s) for session=${currentSessionId}`, { level: "warn" });
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
for (const msg of filtered) {
|
|
1066
|
+
if (msg.uuid)
|
|
1067
|
+
recentPostedUUIDs.add(msg.uuid);
|
|
1068
|
+
}
|
|
1069
|
+
const events = filtered.map((m) => ({ ...m, session_id: currentSessionId }));
|
|
1070
|
+
transport.writeBatch(events);
|
|
1071
|
+
},
|
|
1072
|
+
sendControlRequest(request) {
|
|
1073
|
+
if (!transport) {
|
|
1074
|
+
logForDebugging("[bridge:repl] Transport not configured, skipping control_request");
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
const event = { ...request, session_id: currentSessionId };
|
|
1078
|
+
transport.write(event);
|
|
1079
|
+
logForDebugging(`[bridge:repl] Sent control_request request_id=${request.request_id}`);
|
|
1080
|
+
},
|
|
1081
|
+
sendControlResponse(response) {
|
|
1082
|
+
if (!transport) {
|
|
1083
|
+
logForDebugging("[bridge:repl] Transport not configured, skipping control_response");
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
const event = { ...response, session_id: currentSessionId };
|
|
1087
|
+
transport.write(event);
|
|
1088
|
+
logForDebugging("[bridge:repl] Sent control_response");
|
|
1089
|
+
},
|
|
1090
|
+
sendControlCancelRequest(requestId) {
|
|
1091
|
+
if (!transport) {
|
|
1092
|
+
logForDebugging("[bridge:repl] Transport not configured, skipping control_cancel_request");
|
|
1093
|
+
return;
|
|
1094
|
+
}
|
|
1095
|
+
const event = {
|
|
1096
|
+
type: "control_cancel_request",
|
|
1097
|
+
request_id: requestId,
|
|
1098
|
+
session_id: currentSessionId
|
|
1099
|
+
};
|
|
1100
|
+
transport.write(event);
|
|
1101
|
+
logForDebugging(`[bridge:repl] Sent control_cancel_request request_id=${requestId}`);
|
|
1102
|
+
},
|
|
1103
|
+
sendResult() {
|
|
1104
|
+
if (!transport) {
|
|
1105
|
+
logForDebugging(`[bridge:repl] sendResult: skipping, transport not configured session=${currentSessionId}`);
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
transport.reportState("idle");
|
|
1109
|
+
const resultMsg = {
|
|
1110
|
+
...makeResultMessage(currentSessionId),
|
|
1111
|
+
session_id: currentSessionId
|
|
1112
|
+
};
|
|
1113
|
+
transport.write(resultMsg);
|
|
1114
|
+
logForDebugging(`[bridge:repl] Sent result for session=${currentSessionId}`);
|
|
1115
|
+
},
|
|
1116
|
+
async teardown() {
|
|
1117
|
+
unregister();
|
|
1118
|
+
await doTeardownImpl?.();
|
|
1119
|
+
logForDebugging("[bridge:repl] Torn down");
|
|
1120
|
+
logEvent("tengu_bridge_repl_teardown", {});
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1124
|
+
async function startWorkPollLoop({
|
|
1125
|
+
api,
|
|
1126
|
+
getCredentials,
|
|
1127
|
+
signal,
|
|
1128
|
+
onStateChange,
|
|
1129
|
+
onWorkReceived,
|
|
1130
|
+
onEnvironmentLost,
|
|
1131
|
+
getWsState,
|
|
1132
|
+
isAtCapacity,
|
|
1133
|
+
capacitySignal,
|
|
1134
|
+
onFatalError,
|
|
1135
|
+
getPollIntervalConfig: getPollIntervalConfig2 = () => DEFAULT_POLL_CONFIG,
|
|
1136
|
+
getHeartbeatInfo,
|
|
1137
|
+
onHeartbeatFatal
|
|
1138
|
+
}) {
|
|
1139
|
+
const MAX_ENVIRONMENT_RECREATIONS = 3;
|
|
1140
|
+
logForDebugging(`[bridge:repl] Starting work poll loop for env=${getCredentials().environmentId}`);
|
|
1141
|
+
let consecutiveErrors = 0;
|
|
1142
|
+
let firstErrorTime = null;
|
|
1143
|
+
let lastPollErrorTime = null;
|
|
1144
|
+
let environmentRecreations = 0;
|
|
1145
|
+
let suspensionDetected = false;
|
|
1146
|
+
while (!signal.aborted) {
|
|
1147
|
+
const { environmentId: envId, environmentSecret: envSecret } = getCredentials();
|
|
1148
|
+
const pollConfig = getPollIntervalConfig2();
|
|
1149
|
+
try {
|
|
1150
|
+
const work = await api.pollForWork(envId, envSecret, signal, pollConfig.reclaim_older_than_ms);
|
|
1151
|
+
environmentRecreations = 0;
|
|
1152
|
+
if (consecutiveErrors > 0) {
|
|
1153
|
+
logForDebugging(`[bridge:repl] Poll recovered after ${consecutiveErrors} consecutive error(s)`);
|
|
1154
|
+
consecutiveErrors = 0;
|
|
1155
|
+
firstErrorTime = null;
|
|
1156
|
+
lastPollErrorTime = null;
|
|
1157
|
+
onStateChange?.("ready");
|
|
1158
|
+
}
|
|
1159
|
+
if (!work) {
|
|
1160
|
+
const skipAtCapacityOnce = suspensionDetected;
|
|
1161
|
+
suspensionDetected = false;
|
|
1162
|
+
if (isAtCapacity?.() && capacitySignal && !skipAtCapacityOnce) {
|
|
1163
|
+
const atCapMs = pollConfig.poll_interval_ms_at_capacity;
|
|
1164
|
+
if (pollConfig.non_exclusive_heartbeat_interval_ms > 0 && getHeartbeatInfo) {
|
|
1165
|
+
logEvent("tengu_bridge_heartbeat_mode_entered", {
|
|
1166
|
+
heartbeat_interval_ms: pollConfig.non_exclusive_heartbeat_interval_ms
|
|
1167
|
+
});
|
|
1168
|
+
const pollDeadline = atCapMs > 0 ? Date.now() + atCapMs : null;
|
|
1169
|
+
let needsBackoff = false;
|
|
1170
|
+
let hbCycles = 0;
|
|
1171
|
+
while (!signal.aborted && isAtCapacity() && (pollDeadline === null || Date.now() < pollDeadline)) {
|
|
1172
|
+
const hbConfig = getPollIntervalConfig2();
|
|
1173
|
+
if (hbConfig.non_exclusive_heartbeat_interval_ms <= 0)
|
|
1174
|
+
break;
|
|
1175
|
+
const info = getHeartbeatInfo();
|
|
1176
|
+
if (!info)
|
|
1177
|
+
break;
|
|
1178
|
+
const cap = capacitySignal();
|
|
1179
|
+
try {
|
|
1180
|
+
await api.heartbeatWork(info.environmentId, info.workId, info.sessionToken);
|
|
1181
|
+
} catch (err) {
|
|
1182
|
+
logForDebugging(`[bridge:repl:heartbeat] Failed: ${errorMessage(err)}`);
|
|
1183
|
+
if (err instanceof BridgeFatalError) {
|
|
1184
|
+
cap.cleanup();
|
|
1185
|
+
logEvent("tengu_bridge_heartbeat_error", {
|
|
1186
|
+
status: err.status,
|
|
1187
|
+
error_type: err.status === 401 || err.status === 403 ? "auth_failed" : "fatal"
|
|
1188
|
+
});
|
|
1189
|
+
if (onHeartbeatFatal) {
|
|
1190
|
+
onHeartbeatFatal(err);
|
|
1191
|
+
logForDebugging(`[bridge:repl:heartbeat] Fatal (status=${err.status}), work state cleared \u2014 fast-polling for re-dispatch`);
|
|
1192
|
+
} else {
|
|
1193
|
+
needsBackoff = true;
|
|
1194
|
+
}
|
|
1195
|
+
break;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
hbCycles++;
|
|
1199
|
+
await sleep(hbConfig.non_exclusive_heartbeat_interval_ms, cap.signal);
|
|
1200
|
+
cap.cleanup();
|
|
1201
|
+
}
|
|
1202
|
+
const exitReason = needsBackoff ? "error" : signal.aborted ? "shutdown" : !isAtCapacity() ? "capacity_changed" : pollDeadline !== null && Date.now() >= pollDeadline ? "poll_due" : "config_disabled";
|
|
1203
|
+
logEvent("tengu_bridge_heartbeat_mode_exited", {
|
|
1204
|
+
reason: exitReason,
|
|
1205
|
+
heartbeat_cycles: hbCycles
|
|
1206
|
+
});
|
|
1207
|
+
if (!needsBackoff) {
|
|
1208
|
+
if (exitReason === "poll_due") {
|
|
1209
|
+
logForDebugging(`[bridge:repl] Heartbeat poll_due after ${hbCycles} cycles \u2014 falling through to pollForWork`);
|
|
1210
|
+
}
|
|
1211
|
+
continue;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
const sleepMs = atCapMs > 0 ? atCapMs : pollConfig.non_exclusive_heartbeat_interval_ms;
|
|
1215
|
+
if (sleepMs > 0) {
|
|
1216
|
+
const cap = capacitySignal();
|
|
1217
|
+
const sleepStart = Date.now();
|
|
1218
|
+
await sleep(sleepMs, cap.signal);
|
|
1219
|
+
cap.cleanup();
|
|
1220
|
+
const overrun = Date.now() - sleepStart - sleepMs;
|
|
1221
|
+
if (overrun > 60000) {
|
|
1222
|
+
logForDebugging(`[bridge:repl] At-capacity sleep overran by ${Math.round(overrun / 1000)}s \u2014 process suspension detected, forcing one fast-poll cycle`);
|
|
1223
|
+
logEvent("tengu_bridge_repl_suspension_detected", {
|
|
1224
|
+
overrun_ms: overrun
|
|
1225
|
+
});
|
|
1226
|
+
suspensionDetected = true;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
} else {
|
|
1230
|
+
await sleep(pollConfig.poll_interval_ms_not_at_capacity, signal);
|
|
1231
|
+
}
|
|
1232
|
+
continue;
|
|
1233
|
+
}
|
|
1234
|
+
let secret;
|
|
1235
|
+
try {
|
|
1236
|
+
secret = decodeWorkSecret(work.secret);
|
|
1237
|
+
} catch (err) {
|
|
1238
|
+
logForDebugging(`[bridge:repl] Failed to decode work secret: ${errorMessage(err)}`);
|
|
1239
|
+
logEvent("tengu_bridge_repl_work_secret_failed", {});
|
|
1240
|
+
await api.stopWork(envId, work.id, false).catch(() => {});
|
|
1241
|
+
continue;
|
|
1242
|
+
}
|
|
1243
|
+
logForDebugging(`[bridge:repl] Acknowledging workId=${work.id}`);
|
|
1244
|
+
try {
|
|
1245
|
+
await api.acknowledgeWork(envId, work.id, secret.session_ingress_token);
|
|
1246
|
+
} catch (err) {
|
|
1247
|
+
logForDebugging(`[bridge:repl] Acknowledge failed workId=${work.id}: ${errorMessage(err)}`);
|
|
1248
|
+
}
|
|
1249
|
+
if (work.data.type === "healthcheck") {
|
|
1250
|
+
logForDebugging("[bridge:repl] Healthcheck received");
|
|
1251
|
+
continue;
|
|
1252
|
+
}
|
|
1253
|
+
if (work.data.type === "session") {
|
|
1254
|
+
const workSessionId = work.data.id;
|
|
1255
|
+
try {
|
|
1256
|
+
validateBridgeId(workSessionId, "session_id");
|
|
1257
|
+
} catch {
|
|
1258
|
+
logForDebugging(`[bridge:repl] Invalid session_id in work: ${workSessionId}`);
|
|
1259
|
+
continue;
|
|
1260
|
+
}
|
|
1261
|
+
onWorkReceived(workSessionId, secret.session_ingress_token, work.id, secret.use_code_sessions === true);
|
|
1262
|
+
logForDebugging("[bridge:repl] Work accepted, continuing poll loop");
|
|
1263
|
+
}
|
|
1264
|
+
} catch (err) {
|
|
1265
|
+
if (signal.aborted)
|
|
1266
|
+
break;
|
|
1267
|
+
if (err instanceof BridgeFatalError && err.status === 404 && onEnvironmentLost) {
|
|
1268
|
+
const currentEnvId = getCredentials().environmentId;
|
|
1269
|
+
if (envId !== currentEnvId) {
|
|
1270
|
+
logForDebugging(`[bridge:repl] Stale poll error for old env=${envId}, current env=${currentEnvId} \u2014 skipping onEnvironmentLost`);
|
|
1271
|
+
consecutiveErrors = 0;
|
|
1272
|
+
firstErrorTime = null;
|
|
1273
|
+
continue;
|
|
1274
|
+
}
|
|
1275
|
+
environmentRecreations++;
|
|
1276
|
+
logForDebugging(`[bridge:repl] Environment deleted, attempting re-registration (attempt ${environmentRecreations}/${MAX_ENVIRONMENT_RECREATIONS})`);
|
|
1277
|
+
logEvent("tengu_bridge_repl_env_lost", {
|
|
1278
|
+
attempt: environmentRecreations
|
|
1279
|
+
});
|
|
1280
|
+
if (environmentRecreations > MAX_ENVIRONMENT_RECREATIONS) {
|
|
1281
|
+
logForDebugging(`[bridge:repl] Environment re-registration limit reached (${MAX_ENVIRONMENT_RECREATIONS}), giving up`);
|
|
1282
|
+
onStateChange?.("failed", "Environment deleted and re-registration limit reached");
|
|
1283
|
+
onFatalError?.();
|
|
1284
|
+
break;
|
|
1285
|
+
}
|
|
1286
|
+
onStateChange?.("reconnecting", "environment lost, recreating session");
|
|
1287
|
+
const newCreds = await onEnvironmentLost();
|
|
1288
|
+
if (signal.aborted)
|
|
1289
|
+
break;
|
|
1290
|
+
if (newCreds) {
|
|
1291
|
+
consecutiveErrors = 0;
|
|
1292
|
+
firstErrorTime = null;
|
|
1293
|
+
onStateChange?.("ready");
|
|
1294
|
+
logForDebugging(`[bridge:repl] Re-registered environment: ${newCreds.environmentId}`);
|
|
1295
|
+
continue;
|
|
1296
|
+
}
|
|
1297
|
+
onStateChange?.("failed", "Environment deleted and re-registration failed");
|
|
1298
|
+
onFatalError?.();
|
|
1299
|
+
break;
|
|
1300
|
+
}
|
|
1301
|
+
if (err instanceof BridgeFatalError) {
|
|
1302
|
+
const isExpiry = isExpiredErrorType(err.errorType);
|
|
1303
|
+
const isSuppressible = isSuppressible403(err);
|
|
1304
|
+
logForDebugging(`[bridge:repl] Fatal poll error: ${err.message} (status=${err.status}, type=${err.errorType ?? "unknown"})${isSuppressible ? " (suppressed)" : ""}`);
|
|
1305
|
+
logEvent("tengu_bridge_repl_fatal_error", {
|
|
1306
|
+
status: err.status,
|
|
1307
|
+
error_type: err.errorType
|
|
1308
|
+
});
|
|
1309
|
+
logForDiagnosticsNoPII(isExpiry ? "info" : "error", "bridge_repl_fatal_error", { status: err.status, error_type: err.errorType });
|
|
1310
|
+
if (!isSuppressible) {
|
|
1311
|
+
onStateChange?.("failed", isExpiry ? "session expired \xB7 /remote-control to reconnect" : err.message);
|
|
1312
|
+
}
|
|
1313
|
+
onFatalError?.();
|
|
1314
|
+
break;
|
|
1315
|
+
}
|
|
1316
|
+
const now = Date.now();
|
|
1317
|
+
if (lastPollErrorTime !== null && now - lastPollErrorTime > POLL_ERROR_MAX_DELAY_MS * 2) {
|
|
1318
|
+
logForDebugging(`[bridge:repl] Detected system sleep (${Math.round((now - lastPollErrorTime) / 1000)}s gap), resetting poll error budget`);
|
|
1319
|
+
logForDiagnosticsNoPII("info", "bridge_repl_poll_sleep_detected", {
|
|
1320
|
+
gapMs: now - lastPollErrorTime
|
|
1321
|
+
});
|
|
1322
|
+
consecutiveErrors = 0;
|
|
1323
|
+
firstErrorTime = null;
|
|
1324
|
+
}
|
|
1325
|
+
lastPollErrorTime = now;
|
|
1326
|
+
consecutiveErrors++;
|
|
1327
|
+
if (firstErrorTime === null) {
|
|
1328
|
+
firstErrorTime = now;
|
|
1329
|
+
}
|
|
1330
|
+
const elapsed = now - firstErrorTime;
|
|
1331
|
+
const httpStatus = extractHttpStatus(err);
|
|
1332
|
+
const errMsg = describeAxiosError(err);
|
|
1333
|
+
const wsLabel = getWsState?.() ?? "unknown";
|
|
1334
|
+
logForDebugging(`[bridge:repl] Poll error (attempt ${consecutiveErrors}, elapsed ${Math.round(elapsed / 1000)}s, ws=${wsLabel}): ${errMsg}`);
|
|
1335
|
+
logEvent("tengu_bridge_repl_poll_error", {
|
|
1336
|
+
status: httpStatus,
|
|
1337
|
+
consecutiveErrors,
|
|
1338
|
+
elapsedMs: elapsed
|
|
1339
|
+
});
|
|
1340
|
+
if (consecutiveErrors === 1) {
|
|
1341
|
+
onStateChange?.("reconnecting", errMsg);
|
|
1342
|
+
}
|
|
1343
|
+
if (elapsed >= POLL_ERROR_GIVE_UP_MS) {
|
|
1344
|
+
logForDebugging(`[bridge:repl] Poll failures exceeded ${POLL_ERROR_GIVE_UP_MS / 1000}s (${consecutiveErrors} errors), giving up`);
|
|
1345
|
+
logForDiagnosticsNoPII("info", "bridge_repl_poll_give_up");
|
|
1346
|
+
logEvent("tengu_bridge_repl_poll_give_up", {
|
|
1347
|
+
consecutiveErrors,
|
|
1348
|
+
elapsedMs: elapsed,
|
|
1349
|
+
lastStatus: httpStatus
|
|
1350
|
+
});
|
|
1351
|
+
onStateChange?.("failed", "connection to server lost");
|
|
1352
|
+
break;
|
|
1353
|
+
}
|
|
1354
|
+
const backoff = Math.min(POLL_ERROR_INITIAL_DELAY_MS * 2 ** (consecutiveErrors - 1), POLL_ERROR_MAX_DELAY_MS);
|
|
1355
|
+
if (getPollIntervalConfig2().non_exclusive_heartbeat_interval_ms > 0) {
|
|
1356
|
+
const info = getHeartbeatInfo?.();
|
|
1357
|
+
if (info) {
|
|
1358
|
+
try {
|
|
1359
|
+
await api.heartbeatWork(info.environmentId, info.workId, info.sessionToken);
|
|
1360
|
+
} catch {}
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
await sleep(backoff, signal);
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
logForDebugging(`[bridge:repl] Work poll loop ended (aborted=${signal.aborted}) env=${getCredentials().environmentId}`);
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
// src/bridge/initReplBridge.ts
|
|
1370
|
+
init_sessionIdCompat();
|
|
1371
|
+
async function initReplBridge(options) {
|
|
1372
|
+
const {
|
|
1373
|
+
onInboundMessage,
|
|
1374
|
+
onPermissionResponse,
|
|
1375
|
+
onInterrupt,
|
|
1376
|
+
onSetModel,
|
|
1377
|
+
onSetMaxThinkingTokens,
|
|
1378
|
+
onSetPermissionMode,
|
|
1379
|
+
onStateChange,
|
|
1380
|
+
initialMessages,
|
|
1381
|
+
getMessages,
|
|
1382
|
+
previouslyFlushedUUIDs,
|
|
1383
|
+
initialName,
|
|
1384
|
+
perpetual,
|
|
1385
|
+
outboundOnly,
|
|
1386
|
+
tags
|
|
1387
|
+
} = options ?? {};
|
|
1388
|
+
setCseShimGate(isCseShimEnabled);
|
|
1389
|
+
if (!await isBridgeEnabledBlocking()) {
|
|
1390
|
+
logBridgeSkip("not_enabled", "[bridge:repl] Skipping: bridge not enabled");
|
|
1391
|
+
return null;
|
|
1392
|
+
}
|
|
1393
|
+
if (!getBridgeAccessToken()) {
|
|
1394
|
+
logBridgeSkip("no_oauth", "[bridge:repl] Skipping: no OAuth tokens");
|
|
1395
|
+
onStateChange?.("failed", "/login");
|
|
1396
|
+
return null;
|
|
1397
|
+
}
|
|
1398
|
+
await waitForPolicyLimitsToLoad();
|
|
1399
|
+
if (!isPolicyAllowed("allow_remote_control")) {
|
|
1400
|
+
logBridgeSkip("policy_denied", "[bridge:repl] Skipping: allow_remote_control policy not allowed");
|
|
1401
|
+
onStateChange?.("failed", "disabled by your organization's policy");
|
|
1402
|
+
return null;
|
|
1403
|
+
}
|
|
1404
|
+
if (!getBridgeTokenOverride()) {
|
|
1405
|
+
const cfg = getGlobalConfig();
|
|
1406
|
+
if (cfg.bridgeOauthDeadExpiresAt != null && (cfg.bridgeOauthDeadFailCount ?? 0) >= 3 && getClaudeAIOAuthTokens()?.expiresAt === cfg.bridgeOauthDeadExpiresAt) {
|
|
1407
|
+
logForDebugging(`[bridge:repl] Skipping: cross-process backoff (dead token seen ${cfg.bridgeOauthDeadFailCount} times)`);
|
|
1408
|
+
return null;
|
|
1409
|
+
}
|
|
1410
|
+
await checkAndRefreshOAuthTokenIfNeeded();
|
|
1411
|
+
const tokens = getClaudeAIOAuthTokens();
|
|
1412
|
+
if (tokens && tokens.expiresAt !== null && tokens.expiresAt <= Date.now()) {
|
|
1413
|
+
logBridgeSkip("oauth_expired_unrefreshable", "[bridge:repl] Skipping: OAuth token expired and refresh failed (re-login required)");
|
|
1414
|
+
onStateChange?.("failed", "/login");
|
|
1415
|
+
const deadExpiresAt = tokens.expiresAt;
|
|
1416
|
+
saveGlobalConfig((c) => ({
|
|
1417
|
+
...c,
|
|
1418
|
+
bridgeOauthDeadExpiresAt: deadExpiresAt,
|
|
1419
|
+
bridgeOauthDeadFailCount: c.bridgeOauthDeadExpiresAt === deadExpiresAt ? (c.bridgeOauthDeadFailCount ?? 0) + 1 : 1
|
|
1420
|
+
}));
|
|
1421
|
+
return null;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
const baseUrl = getBridgeBaseUrl();
|
|
1425
|
+
let title = `remote-control-${generateShortWordSlug()}`;
|
|
1426
|
+
let hasTitle = false;
|
|
1427
|
+
let hasExplicitTitle = false;
|
|
1428
|
+
if (initialName) {
|
|
1429
|
+
title = initialName;
|
|
1430
|
+
hasTitle = true;
|
|
1431
|
+
hasExplicitTitle = true;
|
|
1432
|
+
} else {
|
|
1433
|
+
const sessionId = getSessionId();
|
|
1434
|
+
const customTitle = sessionId ? getCurrentSessionTitle(sessionId) : undefined;
|
|
1435
|
+
if (customTitle) {
|
|
1436
|
+
title = customTitle;
|
|
1437
|
+
hasTitle = true;
|
|
1438
|
+
hasExplicitTitle = true;
|
|
1439
|
+
} else if (initialMessages && initialMessages.length > 0) {
|
|
1440
|
+
for (let i = initialMessages.length - 1;i >= 0; i--) {
|
|
1441
|
+
const msg = initialMessages[i];
|
|
1442
|
+
if (msg.type !== "user" || msg.isMeta || msg.toolUseResult || msg.isCompactSummary || msg.origin && msg.origin.kind !== "human" || isSyntheticMessage(msg))
|
|
1443
|
+
continue;
|
|
1444
|
+
const rawContent = getContentText(msg.message.content);
|
|
1445
|
+
if (!rawContent)
|
|
1446
|
+
continue;
|
|
1447
|
+
const derived = deriveTitle(rawContent);
|
|
1448
|
+
if (!derived)
|
|
1449
|
+
continue;
|
|
1450
|
+
title = derived;
|
|
1451
|
+
hasTitle = true;
|
|
1452
|
+
break;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
let userMessageCount = 0;
|
|
1457
|
+
let lastBridgeSessionId;
|
|
1458
|
+
let genSeq = 0;
|
|
1459
|
+
const patch = (derived, bridgeSessionId, atCount) => {
|
|
1460
|
+
hasTitle = true;
|
|
1461
|
+
title = derived;
|
|
1462
|
+
logForDebugging(`[bridge:repl] derived title from message ${atCount}: ${derived}`);
|
|
1463
|
+
updateBridgeSessionTitle(bridgeSessionId, derived, {
|
|
1464
|
+
baseUrl,
|
|
1465
|
+
getAccessToken: getBridgeAccessToken
|
|
1466
|
+
}).catch(() => {});
|
|
1467
|
+
};
|
|
1468
|
+
const generateAndPatch = (input, bridgeSessionId) => {
|
|
1469
|
+
const gen = ++genSeq;
|
|
1470
|
+
const atCount = userMessageCount;
|
|
1471
|
+
generateSessionTitle(input, AbortSignal.timeout(15000)).then((generated) => {
|
|
1472
|
+
if (generated && gen === genSeq && lastBridgeSessionId === bridgeSessionId && !getCurrentSessionTitle(getSessionId())) {
|
|
1473
|
+
patch(generated, bridgeSessionId, atCount);
|
|
1474
|
+
}
|
|
1475
|
+
});
|
|
1476
|
+
};
|
|
1477
|
+
const onUserMessage = (text, bridgeSessionId) => {
|
|
1478
|
+
if (hasExplicitTitle || getCurrentSessionTitle(getSessionId())) {
|
|
1479
|
+
return true;
|
|
1480
|
+
}
|
|
1481
|
+
if (lastBridgeSessionId !== undefined && lastBridgeSessionId !== bridgeSessionId) {
|
|
1482
|
+
userMessageCount = 0;
|
|
1483
|
+
}
|
|
1484
|
+
lastBridgeSessionId = bridgeSessionId;
|
|
1485
|
+
userMessageCount++;
|
|
1486
|
+
if (userMessageCount === 1 && !hasTitle) {
|
|
1487
|
+
const placeholder = deriveTitle(text);
|
|
1488
|
+
if (placeholder)
|
|
1489
|
+
patch(placeholder, bridgeSessionId, userMessageCount);
|
|
1490
|
+
generateAndPatch(text, bridgeSessionId);
|
|
1491
|
+
} else if (userMessageCount === 3) {
|
|
1492
|
+
const msgs = getMessages?.();
|
|
1493
|
+
const input = msgs ? extractConversationText(getMessagesAfterCompactBoundary(msgs)) : text;
|
|
1494
|
+
generateAndPatch(input, bridgeSessionId);
|
|
1495
|
+
}
|
|
1496
|
+
return userMessageCount >= 3;
|
|
1497
|
+
};
|
|
1498
|
+
const initialHistoryCap = getFeatureValue_CACHED_WITH_REFRESH("tengu_bridge_initial_history_cap", 200, 5 * 60 * 1000);
|
|
1499
|
+
const orgUUID = isSelfHostedBridge() ? "self-hosted" : await getOrganizationUUID();
|
|
1500
|
+
if (!orgUUID) {
|
|
1501
|
+
logBridgeSkip("no_org_uuid", "[bridge:repl] Skipping: no org UUID");
|
|
1502
|
+
onStateChange?.("failed", "/login");
|
|
1503
|
+
return null;
|
|
1504
|
+
}
|
|
1505
|
+
if (isEnvLessBridgeEnabled() && !perpetual) {
|
|
1506
|
+
const versionError2 = await checkEnvLessBridgeMinVersion();
|
|
1507
|
+
if (versionError2) {
|
|
1508
|
+
logBridgeSkip("version_too_old", `[bridge:repl] Skipping: ${versionError2}`, true);
|
|
1509
|
+
onStateChange?.("failed", "run `redscope update` to upgrade");
|
|
1510
|
+
return null;
|
|
1511
|
+
}
|
|
1512
|
+
logForDebugging("[bridge:repl] Using env-less bridge path (tengu_bridge_repl_v2)");
|
|
1513
|
+
const { initEnvLessBridgeCore } = await import("./chunk-8hdsk6qc.js");
|
|
1514
|
+
return initEnvLessBridgeCore({
|
|
1515
|
+
baseUrl,
|
|
1516
|
+
orgUUID,
|
|
1517
|
+
title,
|
|
1518
|
+
getAccessToken: getBridgeAccessToken,
|
|
1519
|
+
onAuth401: handleOAuth401Error,
|
|
1520
|
+
toSDKMessages,
|
|
1521
|
+
initialHistoryCap,
|
|
1522
|
+
initialMessages,
|
|
1523
|
+
onInboundMessage,
|
|
1524
|
+
onUserMessage,
|
|
1525
|
+
onPermissionResponse,
|
|
1526
|
+
onInterrupt,
|
|
1527
|
+
onSetModel,
|
|
1528
|
+
onSetMaxThinkingTokens,
|
|
1529
|
+
onSetPermissionMode,
|
|
1530
|
+
onStateChange,
|
|
1531
|
+
outboundOnly,
|
|
1532
|
+
tags
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
const versionError = checkBridgeMinVersion();
|
|
1536
|
+
if (versionError) {
|
|
1537
|
+
logBridgeSkip("version_too_old", `[bridge:repl] Skipping: ${versionError}`);
|
|
1538
|
+
onStateChange?.("failed", "run `redscope update` to upgrade");
|
|
1539
|
+
return null;
|
|
1540
|
+
}
|
|
1541
|
+
const branch = await getBranch();
|
|
1542
|
+
const gitRepoUrl = await getRemoteUrl();
|
|
1543
|
+
const sessionIngressUrl = getBridgeSessionIngressUrl(baseUrl);
|
|
1544
|
+
let workerType = "claude_code";
|
|
1545
|
+
if (true) {
|
|
1546
|
+
const { isAssistantMode } = (init_assistant(), __toCommonJS(exports_assistant));
|
|
1547
|
+
if (isAssistantMode()) {
|
|
1548
|
+
workerType = "claude_code_assistant";
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
return initBridgeCore({
|
|
1552
|
+
dir: getOriginalCwd(),
|
|
1553
|
+
machineName: hostname(),
|
|
1554
|
+
branch,
|
|
1555
|
+
gitRepoUrl,
|
|
1556
|
+
title,
|
|
1557
|
+
baseUrl,
|
|
1558
|
+
sessionIngressUrl,
|
|
1559
|
+
workerType,
|
|
1560
|
+
getAccessToken: getBridgeAccessToken,
|
|
1561
|
+
createSession: (opts) => createBridgeSession({
|
|
1562
|
+
...opts,
|
|
1563
|
+
events: [],
|
|
1564
|
+
baseUrl,
|
|
1565
|
+
getAccessToken: getBridgeAccessToken
|
|
1566
|
+
}),
|
|
1567
|
+
archiveSession: (sessionId) => archiveBridgeSession(sessionId, {
|
|
1568
|
+
baseUrl,
|
|
1569
|
+
getAccessToken: getBridgeAccessToken,
|
|
1570
|
+
timeoutMs: 1500
|
|
1571
|
+
}).catch((err) => {
|
|
1572
|
+
logForDebugging(`[bridge:repl] archiveBridgeSession threw: ${errorMessage(err)}`, { level: "error" });
|
|
1573
|
+
}),
|
|
1574
|
+
getCurrentTitle: () => getCurrentSessionTitle(getSessionId()) ?? title,
|
|
1575
|
+
onUserMessage,
|
|
1576
|
+
toSDKMessages,
|
|
1577
|
+
onAuth401: handleOAuth401Error,
|
|
1578
|
+
getPollIntervalConfig,
|
|
1579
|
+
initialHistoryCap,
|
|
1580
|
+
initialMessages,
|
|
1581
|
+
previouslyFlushedUUIDs,
|
|
1582
|
+
onInboundMessage,
|
|
1583
|
+
onPermissionResponse,
|
|
1584
|
+
onInterrupt,
|
|
1585
|
+
onSetModel,
|
|
1586
|
+
onSetMaxThinkingTokens,
|
|
1587
|
+
onSetPermissionMode,
|
|
1588
|
+
onStateChange,
|
|
1589
|
+
perpetual
|
|
1590
|
+
});
|
|
1591
|
+
}
|
|
1592
|
+
var TITLE_MAX_LEN = 50;
|
|
1593
|
+
function deriveTitle(raw) {
|
|
1594
|
+
const clean = stripDisplayTagsAllowEmpty(raw);
|
|
1595
|
+
const firstSentence = /^(.*?[.!?])\s/.exec(clean)?.[1] ?? clean;
|
|
1596
|
+
const flat = firstSentence.replace(/\s+/g, " ").trim();
|
|
1597
|
+
if (!flat)
|
|
1598
|
+
return;
|
|
1599
|
+
return flat.length > TITLE_MAX_LEN ? flat.slice(0, TITLE_MAX_LEN - 1) + "\u2026" : flat;
|
|
1600
|
+
}
|
|
1601
|
+
export {
|
|
1602
|
+
initReplBridge
|
|
1603
|
+
};
|