jialing-code 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (460) hide show
  1. package/README.md +97 -0
  2. package/dist/chunk-065m026w.js +97 -0
  3. package/dist/chunk-06saje2v.js +39 -0
  4. package/dist/chunk-0731m51q.js +8 -0
  5. package/dist/chunk-0975ccyw.js +265 -0
  6. package/dist/chunk-09n3fjx5.js +67 -0
  7. package/dist/chunk-0bdjdzew.js +41 -0
  8. package/dist/chunk-0ce6kd7y.js +212 -0
  9. package/dist/chunk-0e1xsncc.js +969 -0
  10. package/dist/chunk-0m2861gw.js +154 -0
  11. package/dist/chunk-0paqc2yw.js +15 -0
  12. package/dist/chunk-0rg6yrhy.js +99 -0
  13. package/dist/chunk-0sakxrcf.js +643 -0
  14. package/dist/chunk-0v9hwxvz.js +105 -0
  15. package/dist/chunk-0vkfrmqm.js +690 -0
  16. package/dist/chunk-0vvfnhhv.js +248 -0
  17. package/dist/chunk-0w4rsycj.js +145 -0
  18. package/dist/chunk-0x9b2nmd.js +63 -0
  19. package/dist/chunk-0xjaqda8.js +1124 -0
  20. package/dist/chunk-1141xmr4.js +8 -0
  21. package/dist/chunk-13d1842d.js +154 -0
  22. package/dist/chunk-1921a6yb.js +32 -0
  23. package/dist/chunk-1ad8mk9g.js +527 -0
  24. package/dist/chunk-1ax41pws.js +28 -0
  25. package/dist/chunk-1c8z1b5v.js +16 -0
  26. package/dist/chunk-1cbn5kxf.js +7 -0
  27. package/dist/chunk-1eapde8a.js +726 -0
  28. package/dist/chunk-1h2famwb.js +49 -0
  29. package/dist/chunk-1jggnf7z.js +85 -0
  30. package/dist/chunk-1k92pn9c.js +32 -0
  31. package/dist/chunk-1qakq4sn.js +802 -0
  32. package/dist/chunk-1rvz0433.js +722 -0
  33. package/dist/chunk-1xkekb9y.js +19 -0
  34. package/dist/chunk-238g70xa.js +36 -0
  35. package/dist/chunk-24ge0eqa.js +106 -0
  36. package/dist/chunk-278vghwm.js +5395 -0
  37. package/dist/chunk-27xc1csx.js +104 -0
  38. package/dist/chunk-2a42s11t.js +412 -0
  39. package/dist/chunk-2aa02aw6.js +438 -0
  40. package/dist/chunk-2eykm0j0.js +20 -0
  41. package/dist/chunk-2gzv8nrw.js +205 -0
  42. package/dist/chunk-2k995y2x.js +880 -0
  43. package/dist/chunk-2nayx6q1.js +63 -0
  44. package/dist/chunk-2sd2w2h4.js +44 -0
  45. package/dist/chunk-2tw2ve8h.js +145 -0
  46. package/dist/chunk-30rst83v.js +168 -0
  47. package/dist/chunk-3aavh06g.js +1581 -0
  48. package/dist/chunk-3b0yvt2h.js +469 -0
  49. package/dist/chunk-3be7ka25.js +56 -0
  50. package/dist/chunk-3c25bcsw.js +17 -0
  51. package/dist/chunk-3dyxka97.js +584 -0
  52. package/dist/chunk-3f7rypmf.js +16544 -0
  53. package/dist/chunk-3fsd7f51.js +93 -0
  54. package/dist/chunk-3gqdqmzb.js +75 -0
  55. package/dist/chunk-3h8a89gy.js +46 -0
  56. package/dist/chunk-3m84sret.js +71 -0
  57. package/dist/chunk-3nb7j3js.js +96 -0
  58. package/dist/chunk-3p08nvn2.js +98 -0
  59. package/dist/chunk-3r09htpc.js +318 -0
  60. package/dist/chunk-3r24h7t6.js +113 -0
  61. package/dist/chunk-3rkfxjtq.js +80 -0
  62. package/dist/chunk-3tmk7dc2.js +604 -0
  63. package/dist/chunk-3w6s9m5w.js +16 -0
  64. package/dist/chunk-43qjymy5.js +92 -0
  65. package/dist/chunk-44fpr6jq.js +434 -0
  66. package/dist/chunk-45kxdsp8.js +444 -0
  67. package/dist/chunk-495d85x1.js +8066 -0
  68. package/dist/chunk-4ba796se.js +1095 -0
  69. package/dist/chunk-4g3v8y12.js +23 -0
  70. package/dist/chunk-4h53xj8n.js +3445 -0
  71. package/dist/chunk-4jm600zv.js +13 -0
  72. package/dist/chunk-4jy9dtwk.js +116 -0
  73. package/dist/chunk-4p60dd45.js +55 -0
  74. package/dist/chunk-4z0jsrqg.js +81 -0
  75. package/dist/chunk-4zfkzkt6.js +37 -0
  76. package/dist/chunk-55wgxwa9.js +13877 -0
  77. package/dist/chunk-5dbk24zg.js +890 -0
  78. package/dist/chunk-5hzvp4va.js +115 -0
  79. package/dist/chunk-5kbt1mbt.js +500 -0
  80. package/dist/chunk-5pen7vr8.js +176 -0
  81. package/dist/chunk-5r280eng.js +198 -0
  82. package/dist/chunk-5srym52s.js +88 -0
  83. package/dist/chunk-600kg7k6.js +41 -0
  84. package/dist/chunk-616w0qj3.js +160 -0
  85. package/dist/chunk-62jw1t8c.js +94 -0
  86. package/dist/chunk-62xmt9mk.js +372 -0
  87. package/dist/chunk-64bvg7c3.js +229 -0
  88. package/dist/chunk-65yhe4s0.js +281 -0
  89. package/dist/chunk-6aewh27m.js +102 -0
  90. package/dist/chunk-6bd8brc4.js +48 -0
  91. package/dist/chunk-6dj5t602.js +341 -0
  92. package/dist/chunk-6exxdk1p.js +6956 -0
  93. package/dist/chunk-6f5j8fs0.js +752 -0
  94. package/dist/chunk-6g62sjpf.js +328 -0
  95. package/dist/chunk-6gecq2ta.js +1493 -0
  96. package/dist/chunk-6gr3c3w9.js +378 -0
  97. package/dist/chunk-6kpbgc5w.js +23 -0
  98. package/dist/chunk-6kseqw79.js +154 -0
  99. package/dist/chunk-6mxm1qd0.js +40764 -0
  100. package/dist/chunk-6n2qgm9v.js +8 -0
  101. package/dist/chunk-6tq2v3rk.js +186 -0
  102. package/dist/chunk-6wsdhj3v.js +93 -0
  103. package/dist/chunk-6zw9fhgb.js +4389 -0
  104. package/dist/chunk-71grc1mw.js +111 -0
  105. package/dist/chunk-73rpbt04.js +1947 -0
  106. package/dist/chunk-748feghg.js +604 -0
  107. package/dist/chunk-75e8gtg9.js +84 -0
  108. package/dist/chunk-75th4717.js +780 -0
  109. package/dist/chunk-760252na.js +101 -0
  110. package/dist/chunk-7739pg2c.js +4261 -0
  111. package/dist/chunk-778fnx46.js +472 -0
  112. package/dist/chunk-77g09znh.js +391 -0
  113. package/dist/chunk-7aw745vx.js +40175 -0
  114. package/dist/chunk-7m2nd8da.js +110 -0
  115. package/dist/chunk-7n35vjtw.js +444 -0
  116. package/dist/chunk-7n5ss4sh.js +144 -0
  117. package/dist/chunk-7rjnxcfe.js +107 -0
  118. package/dist/chunk-7sb5axvf.js +122 -0
  119. package/dist/chunk-7wm5s02e.js +216 -0
  120. package/dist/chunk-7ymfj7m3.js +151 -0
  121. package/dist/chunk-7z8j9qfn.js +121 -0
  122. package/dist/chunk-7zsapntc.js +216 -0
  123. package/dist/chunk-805fhkfh.js +908 -0
  124. package/dist/chunk-80k1nj24.js +253 -0
  125. package/dist/chunk-83hfzbx3.js +10 -0
  126. package/dist/chunk-85cypsdd.js +92 -0
  127. package/dist/chunk-8760caxf.js +2644 -0
  128. package/dist/chunk-88f6egg6.js +387 -0
  129. package/dist/chunk-88r7kwgj.js +22 -0
  130. package/dist/chunk-89e1v45e.js +463 -0
  131. package/dist/chunk-8bedvdm1.js +32 -0
  132. package/dist/chunk-8c4x4vdz.js +177 -0
  133. package/dist/chunk-8hq5kk3y.js +44 -0
  134. package/dist/chunk-8ngxagxq.js +18 -0
  135. package/dist/chunk-8tnsngw2.js +31 -0
  136. package/dist/chunk-8wjnca8h.js +307 -0
  137. package/dist/chunk-8y12jxg8.js +10 -0
  138. package/dist/chunk-8ymf4e6z.js +48 -0
  139. package/dist/chunk-90wp6wez.js +10510 -0
  140. package/dist/chunk-92bp5bnf.js +650 -0
  141. package/dist/chunk-92q8sx5z.js +90 -0
  142. package/dist/chunk-958rtmtx.js +10476 -0
  143. package/dist/chunk-9e2kqv5g.js +125 -0
  144. package/dist/chunk-9f4f1hy5.js +281 -0
  145. package/dist/chunk-9gbamk79.js +93 -0
  146. package/dist/chunk-9k5s3ryh.js +167 -0
  147. package/dist/chunk-9xzfqm15.js +97 -0
  148. package/dist/chunk-9zgdvbm6.js +110 -0
  149. package/dist/chunk-a0p3q8jw.js +24 -0
  150. package/dist/chunk-a22sayzp.js +220 -0
  151. package/dist/chunk-a8ejc632.js +3094 -0
  152. package/dist/chunk-a8gj9d9z.js +120 -0
  153. package/dist/chunk-a9vdeb6y.js +258 -0
  154. package/dist/chunk-a9yev47v.js +674 -0
  155. package/dist/chunk-a9zh40sj.js +48 -0
  156. package/dist/chunk-ack5mfba.js +105 -0
  157. package/dist/chunk-ae76ded0.js +30 -0
  158. package/dist/chunk-akjw4dh6.js +538 -0
  159. package/dist/chunk-asc6wz4q.js +1188 -0
  160. package/dist/chunk-atqejh3p.js +273 -0
  161. package/dist/chunk-atv2e6b7.js +61 -0
  162. package/dist/chunk-axvvkwz8.js +1551 -0
  163. package/dist/chunk-azgz7kj9.js +38 -0
  164. package/dist/chunk-b3zave8q.js +275 -0
  165. package/dist/chunk-b4wg70y1.js +54 -0
  166. package/dist/chunk-b8b13qn2.js +100 -0
  167. package/dist/chunk-bg3mt9bm.js +28 -0
  168. package/dist/chunk-bh4jvcjn.js +91 -0
  169. package/dist/chunk-bhdt6k7w.js +15 -0
  170. package/dist/chunk-bm1qb16p.js +17 -0
  171. package/dist/chunk-bpvsd1j1.js +266 -0
  172. package/dist/chunk-bqfnp99q.js +477 -0
  173. package/dist/chunk-bsbmmfyt.js +17 -0
  174. package/dist/chunk-bsbt34jm.js +42 -0
  175. package/dist/chunk-c78akdhr.js +458 -0
  176. package/dist/chunk-cdz5yb0r.js +57 -0
  177. package/dist/chunk-cfv996bs.js +22 -0
  178. package/dist/chunk-cgfdkzhb.js +12 -0
  179. package/dist/chunk-ckh4r5er.js +257 -0
  180. package/dist/chunk-cmgjnvn9.js +89 -0
  181. package/dist/chunk-cpjgvay8.js +687 -0
  182. package/dist/chunk-crfryjx9.js +276 -0
  183. package/dist/chunk-ctw5jwcd.js +213 -0
  184. package/dist/chunk-cvy3vntc.js +65 -0
  185. package/dist/chunk-cwbzz504.js +94 -0
  186. package/dist/chunk-cy2hswr1.js +15 -0
  187. package/dist/chunk-cyejkay3.js +222 -0
  188. package/dist/chunk-d18z9pna.js +106 -0
  189. package/dist/chunk-d5cq0n0v.js +162 -0
  190. package/dist/chunk-db45aryp.js +50 -0
  191. package/dist/chunk-de8nqh0z.js +790 -0
  192. package/dist/chunk-dfw6h350.js +2336 -0
  193. package/dist/chunk-dgqrcy74.js +48 -0
  194. package/dist/chunk-dn75ptgd.js +184 -0
  195. package/dist/chunk-dnh7jtpb.js +37 -0
  196. package/dist/chunk-dpshyv9m.js +90 -0
  197. package/dist/chunk-dt8cdvnm.js +642 -0
  198. package/dist/chunk-dtxby6fr.js +306 -0
  199. package/dist/chunk-dv1wfr85.js +6373 -0
  200. package/dist/chunk-dw363edx.js +1154 -0
  201. package/dist/chunk-dwrdacck.js +62 -0
  202. package/dist/chunk-dxnnv5e3.js +276 -0
  203. package/dist/chunk-e3g8q4cn.js +1646 -0
  204. package/dist/chunk-e3m9k9s2.js +542 -0
  205. package/dist/chunk-e4q49asn.js +155 -0
  206. package/dist/chunk-e5pntxye.js +37 -0
  207. package/dist/chunk-e7393td6.js +42 -0
  208. package/dist/chunk-ead42yrh.js +87 -0
  209. package/dist/chunk-eb90vwvr.js +152 -0
  210. package/dist/chunk-ecvwk9hg.js +250 -0
  211. package/dist/chunk-edjd6aay.js +173 -0
  212. package/dist/chunk-eg0h8mtm.js +130 -0
  213. package/dist/chunk-ehtwnxpg.js +1591 -0
  214. package/dist/chunk-ek686gx1.js +94 -0
  215. package/dist/chunk-eqp1rfft.js +17 -0
  216. package/dist/chunk-evhwt0ar.js +1015 -0
  217. package/dist/chunk-ewadzrm8.js +103 -0
  218. package/dist/chunk-ewsgsw9h.js +172291 -0
  219. package/dist/chunk-f0pa0r7e.js +3198 -0
  220. package/dist/chunk-f2mhrmww.js +62 -0
  221. package/dist/chunk-f39zxvwn.js +401 -0
  222. package/dist/chunk-f46z54tq.js +374 -0
  223. package/dist/chunk-f5ma3nh5.js +3436 -0
  224. package/dist/chunk-f60q23az.js +3038 -0
  225. package/dist/chunk-f6v2nz57.js +107 -0
  226. package/dist/chunk-f6yjan38.js +38 -0
  227. package/dist/chunk-fbv4apne.js +51 -0
  228. package/dist/chunk-fem4s778.js +70 -0
  229. package/dist/chunk-fezm1kn8.js +376 -0
  230. package/dist/chunk-fm1n3ysp.js +6108 -0
  231. package/dist/chunk-frg83bfw.js +225 -0
  232. package/dist/chunk-fscm8db0.js +692 -0
  233. package/dist/chunk-fyc5fepv.js +10 -0
  234. package/dist/chunk-g0j0t6qk.js +26 -0
  235. package/dist/chunk-g0nc1ftf.js +849 -0
  236. package/dist/chunk-g338npwr.js +1061 -0
  237. package/dist/chunk-g3t0act8.js +8 -0
  238. package/dist/chunk-g75w4hw3.js +26 -0
  239. package/dist/chunk-g8vp82en.js +1866 -0
  240. package/dist/chunk-gax0fcbx.js +182 -0
  241. package/dist/chunk-gsz4dh3y.js +606 -0
  242. package/dist/chunk-gtfffm7h.js +440 -0
  243. package/dist/chunk-gver9zb9.js +420 -0
  244. package/dist/chunk-gyj242zr.js +20 -0
  245. package/dist/chunk-h0qngp9w.js +157 -0
  246. package/dist/chunk-h14kemnk.js +123 -0
  247. package/dist/chunk-h8wj1a74.js +8960 -0
  248. package/dist/chunk-h9mcb2eg.js +87 -0
  249. package/dist/chunk-h9nh2980.js +91 -0
  250. package/dist/chunk-hakdhagh.js +16606 -0
  251. package/dist/chunk-hbc6ymdv.js +55 -0
  252. package/dist/chunk-hh7cmy4k.js +20 -0
  253. package/dist/chunk-hjhc4cpt.js +69 -0
  254. package/dist/chunk-hjwez8qc.js +5018 -0
  255. package/dist/chunk-hk9xz7gk.js +118 -0
  256. package/dist/chunk-hqmz36b3.js +552 -0
  257. package/dist/chunk-hrzerbfw.js +1299 -0
  258. package/dist/chunk-hs8ph4p8.js +8 -0
  259. package/dist/chunk-ht1xwrnd.js +716 -0
  260. package/dist/chunk-hvmfg2dc.js +338 -0
  261. package/dist/chunk-hx2tr4ep.js +7189 -0
  262. package/dist/chunk-hzhe8ygc.js +547 -0
  263. package/dist/chunk-j2k4p94p.js +55 -0
  264. package/dist/chunk-j3a4p81y.js +184 -0
  265. package/dist/chunk-j49g6g3s.js +57 -0
  266. package/dist/chunk-j5d5hp9h.js +71 -0
  267. package/dist/chunk-j64ga6ta.js +8035 -0
  268. package/dist/chunk-j7tyxan1.js +116 -0
  269. package/dist/chunk-j8v4774z.js +424 -0
  270. package/dist/chunk-jafes477.js +29 -0
  271. package/dist/chunk-jd32zbps.js +15 -0
  272. package/dist/chunk-jdgeec04.js +4249 -0
  273. package/dist/chunk-jftd4jq5.js +4521 -0
  274. package/dist/chunk-jkxqhv6y.js +812 -0
  275. package/dist/chunk-jmfr6h0n.js +120 -0
  276. package/dist/chunk-jn4aabmx.js +40 -0
  277. package/dist/chunk-jnhkref0.js +30 -0
  278. package/dist/chunk-jsbpm1gz.js +27 -0
  279. package/dist/chunk-jtcyjc3k.js +5802 -0
  280. package/dist/chunk-jx817w05.js +11 -0
  281. package/dist/chunk-jzmz18nn.js +65 -0
  282. package/dist/chunk-k0p9w03v.js +4957 -0
  283. package/dist/chunk-k3dcdnck.js +89 -0
  284. package/dist/chunk-k3wadzcd.js +88 -0
  285. package/dist/chunk-kaeshsk1.js +713 -0
  286. package/dist/chunk-kbkey9ed.js +522 -0
  287. package/dist/chunk-kcwfhqbb.js +196 -0
  288. package/dist/chunk-key6jr7p.js +224 -0
  289. package/dist/chunk-knay8cy9.js +173 -0
  290. package/dist/chunk-kr3rg2y1.js +95 -0
  291. package/dist/chunk-kwekc97v.js +18 -0
  292. package/dist/chunk-m06q12hg.js +61 -0
  293. package/dist/chunk-m2mcpbhk.js +43 -0
  294. package/dist/chunk-m8v220gz.js +71 -0
  295. package/dist/chunk-mgpqy78h.js +208 -0
  296. package/dist/chunk-mkejwh4t.js +16 -0
  297. package/dist/chunk-mptyw5n1.js +107 -0
  298. package/dist/chunk-mqajm0dp.js +66 -0
  299. package/dist/chunk-mrksbgxj.js +490 -0
  300. package/dist/chunk-msjfc5ba.js +246 -0
  301. package/dist/chunk-mt25echc.js +6157 -0
  302. package/dist/chunk-mt3jfnr8.js +277 -0
  303. package/dist/chunk-mtn242d4.js +9300 -0
  304. package/dist/chunk-mzfkvave.js +169 -0
  305. package/dist/chunk-n0qaeaa5.js +256 -0
  306. package/dist/chunk-n1erf6kh.js +22820 -0
  307. package/dist/chunk-n2avk1r2.js +61 -0
  308. package/dist/chunk-n6atnpcq.js +765 -0
  309. package/dist/chunk-n7ttdtk0.js +641 -0
  310. package/dist/chunk-ncnfzby5.js +822 -0
  311. package/dist/chunk-ncnr1jtf.js +2058 -0
  312. package/dist/chunk-nerv0jvx.js +74 -0
  313. package/dist/chunk-ngd2abep.js +90 -0
  314. package/dist/chunk-nka1g8f4.js +773 -0
  315. package/dist/chunk-nnaxkc2z.js +128 -0
  316. package/dist/chunk-npyrtj8j.js +691 -0
  317. package/dist/chunk-nq0fxyxh.js +752 -0
  318. package/dist/chunk-nrmffak7.js +114 -0
  319. package/dist/chunk-nsz546wq.js +1170 -0
  320. package/dist/chunk-nt837qt9.js +21 -0
  321. package/dist/chunk-nv64x1z5.js +86 -0
  322. package/dist/chunk-nxsh6de2.js +1711 -0
  323. package/dist/chunk-nz4getcr.js +40 -0
  324. package/dist/chunk-p1f607pa.js +83 -0
  325. package/dist/chunk-p2816w9z.js +1486 -0
  326. package/dist/chunk-p2d5nh3g.js +342 -0
  327. package/dist/chunk-p4r5y02t.js +90 -0
  328. package/dist/chunk-p7g7pf3f.js +336 -0
  329. package/dist/chunk-pb4ad8r2.js +110 -0
  330. package/dist/chunk-pbrhz0zr.js +716 -0
  331. package/dist/chunk-ps49ymvj.js +43 -0
  332. package/dist/chunk-pwnt3veb.js +103 -0
  333. package/dist/chunk-pwwa7s62.js +11 -0
  334. package/dist/chunk-px3w0kde.js +299 -0
  335. package/dist/chunk-pzn777jb.js +756 -0
  336. package/dist/chunk-q25bjaev.js +15 -0
  337. package/dist/chunk-q5by3da6.js +8 -0
  338. package/dist/chunk-q6av622g.js +38 -0
  339. package/dist/chunk-q6xkvtf2.js +1318 -0
  340. package/dist/chunk-q81jx1tq.js +476 -0
  341. package/dist/chunk-qehb6fk5.js +339 -0
  342. package/dist/chunk-qj1avx1q.js +87 -0
  343. package/dist/chunk-qn2dxr66.js +105 -0
  344. package/dist/chunk-qnfx3qtx.js +617 -0
  345. package/dist/chunk-qp18kd4h.js +48 -0
  346. package/dist/chunk-qp2qdcda.js +100 -0
  347. package/dist/chunk-qpjy9tcf.js +133 -0
  348. package/dist/chunk-qqfa0dqg.js +2343 -0
  349. package/dist/chunk-qwh3htcz.js +202 -0
  350. package/dist/chunk-qz2x630m.js +49145 -0
  351. package/dist/chunk-r3vakcs1.js +496 -0
  352. package/dist/chunk-r66hz8j6.js +34 -0
  353. package/dist/chunk-r6b58y3x.js +17 -0
  354. package/dist/chunk-rekp48rk.js +62 -0
  355. package/dist/chunk-rn0v1hk8.js +34 -0
  356. package/dist/chunk-rs1xrs6m.js +534 -0
  357. package/dist/chunk-rs45skes.js +123 -0
  358. package/dist/chunk-rzszqp82.js +524 -0
  359. package/dist/chunk-s274nv8k.js +8 -0
  360. package/dist/chunk-s3pzvdss.js +50 -0
  361. package/dist/chunk-s9mesaw0.js +26840 -0
  362. package/dist/chunk-sd36yzx8.js +954 -0
  363. package/dist/chunk-sdj9b9wh.js +782 -0
  364. package/dist/chunk-sdw2q69p.js +227 -0
  365. package/dist/chunk-sfgp9cc0.js +130 -0
  366. package/dist/chunk-spqaamnc.js +63 -0
  367. package/dist/chunk-spzrs4df.js +73 -0
  368. package/dist/chunk-sxkr7k43.js +55 -0
  369. package/dist/chunk-szj5wvdy.js +28 -0
  370. package/dist/chunk-t0rgmccj.js +39 -0
  371. package/dist/chunk-t1nnzjgg.js +17 -0
  372. package/dist/chunk-t94fcnt8.js +566 -0
  373. package/dist/chunk-tjaqa99q.js +125 -0
  374. package/dist/chunk-tjq2evtw.js +328 -0
  375. package/dist/chunk-ts2p6bv1.js +224 -0
  376. package/dist/chunk-ttk5dzz8.js +25 -0
  377. package/dist/chunk-tw0q7ynt.js +59 -0
  378. package/dist/chunk-v02jkvgy.js +131 -0
  379. package/dist/chunk-v084bqt3.js +1529 -0
  380. package/dist/chunk-v0amythm.js +164 -0
  381. package/dist/chunk-v1kzp02e.js +785 -0
  382. package/dist/chunk-v1mgv1et.js +15 -0
  383. package/dist/chunk-v399mzxk.js +58 -0
  384. package/dist/chunk-v3gm2day.js +8 -0
  385. package/dist/chunk-v43hrrxp.js +71 -0
  386. package/dist/chunk-v6aqb2aj.js +102 -0
  387. package/dist/chunk-v78fj8by.js +145 -0
  388. package/dist/chunk-v7qmhjdn.js +1921 -0
  389. package/dist/chunk-v9smspw2.js +4301 -0
  390. package/dist/chunk-vdw93s4h.js +2431 -0
  391. package/dist/chunk-vest0y6x.js +3830 -0
  392. package/dist/chunk-vf5sd1nq.js +12 -0
  393. package/dist/chunk-vratq94g.js +349 -0
  394. package/dist/chunk-vrz7t3m3.js +20 -0
  395. package/dist/chunk-vtb185z9.js +70 -0
  396. package/dist/chunk-vx01rvg8.js +654 -0
  397. package/dist/chunk-vyc0rjyx.js +31 -0
  398. package/dist/chunk-vyjeh50y.js +2149 -0
  399. package/dist/chunk-vzpffsza.js +269 -0
  400. package/dist/chunk-w2ef3kxk.js +3353 -0
  401. package/dist/chunk-w2z5pqd3.js +336 -0
  402. package/dist/chunk-w3whm4mn.js +432 -0
  403. package/dist/chunk-w7wgpqcp.js +157 -0
  404. package/dist/chunk-waa00cvb.js +301 -0
  405. package/dist/chunk-wb0qm4es.js +155 -0
  406. package/dist/chunk-wbkahkdc.js +27 -0
  407. package/dist/chunk-wfz0qffj.js +3939 -0
  408. package/dist/chunk-wn0cx0pt.js +283 -0
  409. package/dist/chunk-wv6gzt9c.js +726 -0
  410. package/dist/chunk-wx42ycm4.js +998 -0
  411. package/dist/chunk-wxkpgy05.js +268 -0
  412. package/dist/chunk-wzpdet3m.js +843 -0
  413. package/dist/chunk-x0mwzt38.js +714 -0
  414. package/dist/chunk-x592wbfh.js +244 -0
  415. package/dist/chunk-x5pqsp9r.js +100 -0
  416. package/dist/chunk-x679thag.js +825 -0
  417. package/dist/chunk-x8b7vft8.js +132 -0
  418. package/dist/chunk-x8cftch7.js +119 -0
  419. package/dist/chunk-x9q7r885.js +348 -0
  420. package/dist/chunk-xawkt0vb.js +1585 -0
  421. package/dist/chunk-xdw5dv00.js +8 -0
  422. package/dist/chunk-xe9cc860.js +287 -0
  423. package/dist/chunk-xjr9c3vt.js +101 -0
  424. package/dist/chunk-xk7zaqta.js +21933 -0
  425. package/dist/chunk-xktbmawc.js +678 -0
  426. package/dist/chunk-xn6yw46v.js +140 -0
  427. package/dist/chunk-xsq9ae7x.js +90 -0
  428. package/dist/chunk-xszk7n10.js +14358 -0
  429. package/dist/chunk-xt8a5r1t.js +84 -0
  430. package/dist/chunk-xydyndkv.js +195 -0
  431. package/dist/chunk-xzt10yc5.js +60 -0
  432. package/dist/chunk-y04y95dr.js +91 -0
  433. package/dist/chunk-y1784krc.js +19 -0
  434. package/dist/chunk-y1x32h3x.js +128 -0
  435. package/dist/chunk-y3s7aww5.js +99 -0
  436. package/dist/chunk-y47cg3kz.js +42 -0
  437. package/dist/chunk-y7kzvepn.js +469 -0
  438. package/dist/chunk-y89kbsyc.js +287 -0
  439. package/dist/chunk-yd87p1c3.js +159 -0
  440. package/dist/chunk-yf3yw8fw.js +105 -0
  441. package/dist/chunk-ygbf0ezx.js +1391 -0
  442. package/dist/chunk-yjbxnshv.js +208 -0
  443. package/dist/chunk-ynednmqd.js +192 -0
  444. package/dist/chunk-yvhez44y.js +259 -0
  445. package/dist/chunk-ywxd4qw4.js +22 -0
  446. package/dist/chunk-yzrmgpy4.js +117 -0
  447. package/dist/chunk-z0b2vb24.js +862 -0
  448. package/dist/chunk-z1zj044v.js +655 -0
  449. package/dist/chunk-z2dp53wn.js +17 -0
  450. package/dist/chunk-z3w0xasa.js +165 -0
  451. package/dist/chunk-z7ycmrb3.js +644 -0
  452. package/dist/chunk-zh11tdkb.js +347 -0
  453. package/dist/chunk-zk2wsm7d.js +15 -0
  454. package/dist/chunk-zqfqcf22.js +229 -0
  455. package/dist/chunk-zqk2j8px.js +699 -0
  456. package/dist/chunk-zqvsc10j.js +2833 -0
  457. package/dist/chunk-zsfxha74.js +17655 -0
  458. package/dist/chunk-zvc4snyb.js +117 -0
  459. package/dist/cli.js +194 -0
  460. package/package.json +173 -0
@@ -0,0 +1,1529 @@
1
+ // @bun
2
+ import {
3
+ HybridTransport
4
+ } from "./chunk-cpjgvay8.js";
5
+ import {
6
+ FlushGate,
7
+ checkEnvLessBridgeMinVersion,
8
+ createV1ReplTransport,
9
+ createV2ReplTransport
10
+ } from "./chunk-dxnnv5e3.js";
11
+ import"./chunk-asc6wz4q.js";
12
+ import {
13
+ BoundedUUIDSet,
14
+ extractTitleText,
15
+ handleIngressMessage,
16
+ handleServerControlRequest,
17
+ isEligibleBridgeMessage,
18
+ makeResultMessage
19
+ } from "./chunk-mt3jfnr8.js";
20
+ import"./chunk-nt837qt9.js";
21
+ import {
22
+ createCapacityWake
23
+ } from "./chunk-ae76ded0.js";
24
+ import {
25
+ DEFAULT_POLL_CONFIG,
26
+ getPollIntervalConfig
27
+ } from "./chunk-atv2e6b7.js";
28
+ import {
29
+ buildCCRv2SdkUrl,
30
+ buildSdkUrl,
31
+ decodeWorkSecret,
32
+ sameSessionId
33
+ } from "./chunk-cvy3vntc.js";
34
+ import"./chunk-eb90vwvr.js";
35
+ import {
36
+ init_mappers,
37
+ toSDKMessages
38
+ } from "./chunk-64bvg7c3.js";
39
+ import {
40
+ archiveBridgeSession,
41
+ createBridgeSession,
42
+ init_createSession,
43
+ updateBridgeSessionTitle
44
+ } from "./chunk-ecvwk9hg.js";
45
+ import {
46
+ extractConversationText,
47
+ generateSessionTitle,
48
+ init_sessionTitle
49
+ } from "./chunk-sfgp9cc0.js";
50
+ import {
51
+ getBridgeAccessToken,
52
+ getBridgeBaseUrl,
53
+ getBridgeTokenOverride,
54
+ init_bridgeConfig
55
+ } from "./chunk-1k92pn9c.js";
56
+ import {
57
+ checkBridgeMinVersion,
58
+ init_bridgeEnabled,
59
+ isBridgeEnabledBlocking,
60
+ isCseShimEnabled,
61
+ isEnvLessBridgeEnabled
62
+ } from "./chunk-db45aryp.js";
63
+ import {
64
+ BridgeFatalError,
65
+ clearBridgeDebugHandle,
66
+ createBridgeApiClient,
67
+ generateShortWordSlug,
68
+ getContentText,
69
+ getCurrentSessionTitle,
70
+ getMessagesAfterCompactBoundary,
71
+ init_bridgeApi,
72
+ init_bridgeDebug,
73
+ init_concurrentSessions,
74
+ init_messages1 as init_messages,
75
+ init_policyLimits,
76
+ init_sessionStorage,
77
+ init_words,
78
+ injectBridgeFault,
79
+ isExpiredErrorType,
80
+ isPolicyAllowed,
81
+ isSuppressible403,
82
+ isSyntheticMessage,
83
+ registerBridgeDebugHandle,
84
+ updateSessionBridgeId,
85
+ validateBridgeId,
86
+ waitForPolicyLimitsToLoad,
87
+ wrapApiForFaultInjection
88
+ } from "./chunk-ewsgsw9h.js";
89
+ import"./chunk-z1zj044v.js";
90
+ import"./chunk-t0rgmccj.js";
91
+ import {
92
+ init_sessionIngressAuth,
93
+ updateSessionIngressAuthToken
94
+ } from "./chunk-key6jr7p.js";
95
+ import {
96
+ getTrustedDeviceToken,
97
+ init_trustedDevice
98
+ } from "./chunk-0m2861gw.js";
99
+ import"./chunk-0x9b2nmd.js";
100
+ import"./chunk-89e1v45e.js";
101
+ import"./chunk-2gzv8nrw.js";
102
+ import"./chunk-ehtwnxpg.js";
103
+ import"./chunk-3be7ka25.js";
104
+ import"./chunk-x679thag.js";
105
+ import"./chunk-cgfdkzhb.js";
106
+ import"./chunk-bhdt6k7w.js";
107
+ import"./chunk-45kxdsp8.js";
108
+ import"./chunk-5dbk24zg.js";
109
+ import"./chunk-msjfc5ba.js";
110
+ import"./chunk-7zsapntc.js";
111
+ import"./chunk-0rg6yrhy.js";
112
+ import"./chunk-9gbamk79.js";
113
+ import"./chunk-x0mwzt38.js";
114
+ import {
115
+ describeAxiosError,
116
+ extractHttpStatus,
117
+ init_debugUtils,
118
+ init_sessionIdCompat,
119
+ logBridgeSkip,
120
+ setCseShimGate,
121
+ toCompatSessionId,
122
+ toInfraSessionId
123
+ } from "./chunk-9e2kqv5g.js";
124
+ import"./chunk-1qakq4sn.js";
125
+ import"./chunk-s9mesaw0.js";
126
+ import"./chunk-7m2nd8da.js";
127
+ import"./chunk-ps49ymvj.js";
128
+ import"./chunk-g338npwr.js";
129
+ import"./chunk-zk2wsm7d.js";
130
+ import"./chunk-tw0q7ynt.js";
131
+ import"./chunk-xe9cc860.js";
132
+ import"./chunk-m06q12hg.js";
133
+ import"./chunk-ygbf0ezx.js";
134
+ import"./chunk-spqaamnc.js";
135
+ import"./chunk-4jm600zv.js";
136
+ import"./chunk-qz2x630m.js";
137
+ import"./chunk-7sb5axvf.js";
138
+ import"./chunk-v9smspw2.js";
139
+ import {
140
+ checkAndRefreshOAuthTokenIfNeeded,
141
+ getClaudeAIOAuthTokens,
142
+ getFeatureValue_CACHED_WITH_REFRESH,
143
+ getGlobalConfig,
144
+ getOrganizationUUID,
145
+ handleOAuth401Error,
146
+ init_auth,
147
+ init_client,
148
+ init_config1 as init_config,
149
+ init_growthbook,
150
+ init_sleep,
151
+ saveGlobalConfig,
152
+ sleep
153
+ } from "./chunk-3f7rypmf.js";
154
+ import"./chunk-e3g8q4cn.js";
155
+ import"./chunk-ctw5jwcd.js";
156
+ import"./chunk-0e1xsncc.js";
157
+ import"./chunk-vratq94g.js";
158
+ import"./chunk-g0j0t6qk.js";
159
+ import"./chunk-6kpbgc5w.js";
160
+ import"./chunk-3c25bcsw.js";
161
+ import"./chunk-tjaqa99q.js";
162
+ import"./chunk-55wgxwa9.js";
163
+ import"./chunk-w2z5pqd3.js";
164
+ import"./chunk-7ymfj7m3.js";
165
+ import"./chunk-f5ma3nh5.js";
166
+ import"./chunk-v1kzp02e.js";
167
+ import"./chunk-1eapde8a.js";
168
+ import"./chunk-p2816w9z.js";
169
+ import"./chunk-0vkfrmqm.js";
170
+ import"./chunk-0xjaqda8.js";
171
+ import"./chunk-1rvz0433.js";
172
+ import"./chunk-cdz5yb0r.js";
173
+ import {
174
+ init_analytics,
175
+ logEvent
176
+ } from "./chunk-f2mhrmww.js";
177
+ import"./chunk-7z8j9qfn.js";
178
+ import {
179
+ getBranch,
180
+ getRemoteUrl,
181
+ init_diagLogs,
182
+ init_git,
183
+ logForDiagnosticsNoPII
184
+ } from "./chunk-hrzerbfw.js";
185
+ import"./chunk-d18z9pna.js";
186
+ import"./chunk-qnfx3qtx.js";
187
+ import"./chunk-hjhc4cpt.js";
188
+ import"./chunk-vyc0rjyx.js";
189
+ import"./chunk-hx2tr4ep.js";
190
+ import {
191
+ init_displayTags,
192
+ stripDisplayTagsAllowEmpty
193
+ } from "./chunk-p7g7pf3f.js";
194
+ import"./chunk-8tnsngw2.js";
195
+ import"./chunk-8bedvdm1.js";
196
+ import"./chunk-7wm5s02e.js";
197
+ import {
198
+ errorMessage,
199
+ init_cleanupRegistry,
200
+ init_debug,
201
+ init_errors,
202
+ logForDebugging,
203
+ registerCleanup
204
+ } from "./chunk-nxsh6de2.js";
205
+ import"./chunk-fbv4apne.js";
206
+ import {
207
+ init_envUtils,
208
+ isEnvTruthy,
209
+ isInProtectedNamespace
210
+ } from "./chunk-3r24h7t6.js";
211
+ import {
212
+ getOriginalCwd,
213
+ getSessionId,
214
+ init_state
215
+ } from "./chunk-qqfa0dqg.js";
216
+ import"./chunk-hqmz36b3.js";
217
+ import"./chunk-4g3v8y12.js";
218
+ import"./chunk-7739pg2c.js";
219
+ import"./chunk-xszk7n10.js";
220
+ import"./chunk-sdj9b9wh.js";
221
+ import {
222
+ __require
223
+ } from "./chunk-qp2qdcda.js";
224
+
225
+ // src/bridge/initReplBridge.ts
226
+ init_state();
227
+ init_growthbook();
228
+ init_client();
229
+ init_policyLimits();
230
+ init_auth();
231
+ init_config();
232
+ init_debug();
233
+ init_displayTags();
234
+ init_errors();
235
+ init_git();
236
+ init_mappers();
237
+ init_messages();
238
+ init_sessionStorage();
239
+ init_sessionTitle();
240
+ init_words();
241
+ init_bridgeConfig();
242
+ init_bridgeEnabled();
243
+ init_createSession();
244
+ init_debugUtils();
245
+ import { hostname } from "os";
246
+
247
+ // src/bridge/replBridge.ts
248
+ init_bridgeApi();
249
+ init_debug();
250
+ init_diagLogs();
251
+ init_analytics();
252
+ init_cleanupRegistry();
253
+ import { randomUUID } from "crypto";
254
+ init_sessionIdCompat();
255
+ init_concurrentSessions();
256
+ init_trustedDevice();
257
+ init_sessionIngressAuth();
258
+ init_envUtils();
259
+ init_bridgeApi();
260
+ init_debugUtils();
261
+ init_errors();
262
+ init_sleep();
263
+ init_bridgeDebug();
264
+ var POLL_ERROR_INITIAL_DELAY_MS = 2000;
265
+ var POLL_ERROR_MAX_DELAY_MS = 60000;
266
+ var POLL_ERROR_GIVE_UP_MS = 15 * 60 * 1000;
267
+ var initSequence = 0;
268
+ async function initBridgeCore(params) {
269
+ const {
270
+ dir,
271
+ machineName,
272
+ branch,
273
+ gitRepoUrl,
274
+ title,
275
+ baseUrl,
276
+ sessionIngressUrl,
277
+ workerType,
278
+ getAccessToken,
279
+ createSession,
280
+ archiveSession,
281
+ getCurrentTitle = () => title,
282
+ toSDKMessages: toSDKMessages2 = () => {
283
+ 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.");
284
+ },
285
+ onAuth401,
286
+ getPollIntervalConfig: getPollIntervalConfig2 = () => DEFAULT_POLL_CONFIG,
287
+ initialHistoryCap = 200,
288
+ initialMessages,
289
+ previouslyFlushedUUIDs,
290
+ onInboundMessage,
291
+ onPermissionResponse,
292
+ onInterrupt,
293
+ onSetModel,
294
+ onSetMaxThinkingTokens,
295
+ onSetPermissionMode,
296
+ onStateChange,
297
+ onUserMessage,
298
+ perpetual,
299
+ initialSSESequenceNum = 0
300
+ } = params;
301
+ const seq = ++initSequence;
302
+ const { writeBridgePointer, clearBridgePointer, readBridgePointer } = await import("./chunk-2tw2ve8h.js");
303
+ const rawPrior = perpetual ? await readBridgePointer(dir) : null;
304
+ const prior = rawPrior?.source === "repl" ? rawPrior : null;
305
+ logForDebugging(`[bridge:repl] initBridgeCore #${seq} starting (initialMessages=${initialMessages?.length ?? 0}${prior ? ` perpetual prior=env:${prior.environmentId}` : ""})`);
306
+ const rawApi = createBridgeApiClient({
307
+ baseUrl,
308
+ getAccessToken,
309
+ runnerVersion: MACRO.VERSION,
310
+ onDebug: logForDebugging,
311
+ onAuth401,
312
+ getTrustedDeviceToken
313
+ });
314
+ const api = process.env.USER_TYPE === "ant" ? wrapApiForFaultInjection(rawApi) : rawApi;
315
+ const bridgeConfig = {
316
+ dir,
317
+ machineName,
318
+ branch,
319
+ gitRepoUrl,
320
+ maxSessions: 1,
321
+ spawnMode: "single-session",
322
+ verbose: false,
323
+ sandbox: false,
324
+ bridgeId: randomUUID(),
325
+ workerType,
326
+ environmentId: randomUUID(),
327
+ reuseEnvironmentId: prior?.environmentId,
328
+ apiBaseUrl: baseUrl,
329
+ sessionIngressUrl
330
+ };
331
+ let environmentId;
332
+ let environmentSecret;
333
+ try {
334
+ const reg = await api.registerBridgeEnvironment(bridgeConfig);
335
+ environmentId = reg.environment_id;
336
+ environmentSecret = reg.environment_secret;
337
+ } catch (err) {
338
+ logBridgeSkip("registration_failed", `[bridge:repl] Environment registration failed: ${errorMessage(err)}`);
339
+ if (prior) {
340
+ await clearBridgePointer(dir);
341
+ }
342
+ onStateChange?.("failed", errorMessage(err));
343
+ return null;
344
+ }
345
+ logForDebugging(`[bridge:repl] Environment registered: ${environmentId}`);
346
+ logForDiagnosticsNoPII("info", "bridge_repl_env_registered");
347
+ logEvent("tengu_bridge_repl_env_registered", {});
348
+ async function tryReconnectInPlace(requestedEnvId, sessionId) {
349
+ if (environmentId !== requestedEnvId) {
350
+ logForDebugging(`[bridge:repl] Env mismatch (requested ${requestedEnvId}, got ${environmentId}) \u2014 cannot reconnect in place`);
351
+ return false;
352
+ }
353
+ const infraId = toInfraSessionId(sessionId);
354
+ const candidates = infraId === sessionId ? [sessionId] : [sessionId, infraId];
355
+ for (const id of candidates) {
356
+ try {
357
+ await api.reconnectSession(environmentId, id);
358
+ logForDebugging(`[bridge:repl] Reconnected session ${id} in place on env ${environmentId}`);
359
+ return true;
360
+ } catch (err) {
361
+ logForDebugging(`[bridge:repl] reconnectSession(${id}) failed: ${errorMessage(err)}`);
362
+ }
363
+ }
364
+ logForDebugging("[bridge:repl] reconnectSession exhausted \u2014 falling through to fresh session");
365
+ return false;
366
+ }
367
+ const reusedPriorSession = prior ? await tryReconnectInPlace(prior.environmentId, prior.sessionId) : false;
368
+ if (prior && !reusedPriorSession) {
369
+ await clearBridgePointer(dir);
370
+ }
371
+ let currentSessionId;
372
+ if (reusedPriorSession && prior) {
373
+ currentSessionId = prior.sessionId;
374
+ logForDebugging(`[bridge:repl] Perpetual session reused: ${currentSessionId}`);
375
+ if (initialMessages && previouslyFlushedUUIDs) {
376
+ for (const msg of initialMessages) {
377
+ previouslyFlushedUUIDs.add(msg.uuid);
378
+ }
379
+ }
380
+ } else {
381
+ const createdSessionId = await createSession({
382
+ environmentId,
383
+ title,
384
+ gitRepoUrl,
385
+ branch,
386
+ signal: AbortSignal.timeout(15000)
387
+ });
388
+ if (!createdSessionId) {
389
+ logForDebugging("[bridge:repl] Session creation failed, deregistering environment");
390
+ logEvent("tengu_bridge_repl_session_failed", {});
391
+ await api.deregisterEnvironment(environmentId).catch(() => {});
392
+ onStateChange?.("failed", "Session creation failed");
393
+ return null;
394
+ }
395
+ currentSessionId = createdSessionId;
396
+ logForDebugging(`[bridge:repl] Session created: ${currentSessionId}`);
397
+ }
398
+ await writeBridgePointer(dir, {
399
+ sessionId: currentSessionId,
400
+ environmentId,
401
+ source: "repl"
402
+ });
403
+ logForDiagnosticsNoPII("info", "bridge_repl_session_created");
404
+ logEvent("tengu_bridge_repl_started", {
405
+ has_initial_messages: !!(initialMessages && initialMessages.length > 0),
406
+ inProtectedNamespace: isInProtectedNamespace()
407
+ });
408
+ const initialMessageUUIDs = new Set;
409
+ if (initialMessages) {
410
+ for (const msg of initialMessages) {
411
+ initialMessageUUIDs.add(msg.uuid);
412
+ }
413
+ }
414
+ const recentPostedUUIDs = new BoundedUUIDSet(2000);
415
+ for (const uuid of initialMessageUUIDs) {
416
+ recentPostedUUIDs.add(uuid);
417
+ }
418
+ const recentInboundUUIDs = new BoundedUUIDSet(2000);
419
+ const pollController = new AbortController;
420
+ let transport = null;
421
+ let v2Generation = 0;
422
+ let lastTransportSequenceNum = reusedPriorSession ? initialSSESequenceNum : 0;
423
+ let currentWorkId = null;
424
+ let currentIngressToken = null;
425
+ const capacityWake = createCapacityWake(pollController.signal);
426
+ const wakePollLoop = capacityWake.wake;
427
+ const capacitySignal = capacityWake.signal;
428
+ const flushGate = new FlushGate;
429
+ let userMessageCallbackDone = !onUserMessage;
430
+ const MAX_ENVIRONMENT_RECREATIONS = 3;
431
+ let environmentRecreations = 0;
432
+ let reconnectPromise = null;
433
+ async function reconnectEnvironmentWithSession() {
434
+ if (reconnectPromise) {
435
+ return reconnectPromise;
436
+ }
437
+ reconnectPromise = doReconnect();
438
+ try {
439
+ return await reconnectPromise;
440
+ } finally {
441
+ reconnectPromise = null;
442
+ }
443
+ }
444
+ async function doReconnect() {
445
+ environmentRecreations++;
446
+ v2Generation++;
447
+ logForDebugging(`[bridge:repl] Reconnecting after env lost (attempt ${environmentRecreations}/${MAX_ENVIRONMENT_RECREATIONS})`);
448
+ if (environmentRecreations > MAX_ENVIRONMENT_RECREATIONS) {
449
+ logForDebugging(`[bridge:repl] Environment reconnect limit reached (${MAX_ENVIRONMENT_RECREATIONS}), giving up`);
450
+ return false;
451
+ }
452
+ if (transport) {
453
+ const seq2 = transport.getLastSequenceNum();
454
+ if (seq2 > lastTransportSequenceNum) {
455
+ lastTransportSequenceNum = seq2;
456
+ }
457
+ transport.close();
458
+ transport = null;
459
+ }
460
+ wakePollLoop();
461
+ flushGate.drop();
462
+ if (currentWorkId) {
463
+ const workIdBeingCleared = currentWorkId;
464
+ await api.stopWork(environmentId, workIdBeingCleared, false).catch(() => {});
465
+ if (currentWorkId !== workIdBeingCleared) {
466
+ logForDebugging("[bridge:repl] Poll loop recovered during stopWork await \u2014 deferring to it");
467
+ environmentRecreations = 0;
468
+ return true;
469
+ }
470
+ currentWorkId = null;
471
+ currentIngressToken = null;
472
+ }
473
+ if (pollController.signal.aborted) {
474
+ logForDebugging("[bridge:repl] Reconnect aborted by teardown");
475
+ return false;
476
+ }
477
+ const requestedEnvId = environmentId;
478
+ bridgeConfig.reuseEnvironmentId = requestedEnvId;
479
+ try {
480
+ const reg = await api.registerBridgeEnvironment(bridgeConfig);
481
+ environmentId = reg.environment_id;
482
+ environmentSecret = reg.environment_secret;
483
+ } catch (err) {
484
+ bridgeConfig.reuseEnvironmentId = undefined;
485
+ logForDebugging(`[bridge:repl] Environment re-registration failed: ${errorMessage(err)}`);
486
+ return false;
487
+ }
488
+ bridgeConfig.reuseEnvironmentId = undefined;
489
+ logForDebugging(`[bridge:repl] Re-registered: requested=${requestedEnvId} got=${environmentId}`);
490
+ if (pollController.signal.aborted) {
491
+ logForDebugging("[bridge:repl] Reconnect aborted after env registration, cleaning up");
492
+ await api.deregisterEnvironment(environmentId).catch(() => {});
493
+ return false;
494
+ }
495
+ if (transport !== null) {
496
+ logForDebugging("[bridge:repl] Poll loop recovered during registerBridgeEnvironment await \u2014 deferring to it");
497
+ environmentRecreations = 0;
498
+ return true;
499
+ }
500
+ if (await tryReconnectInPlace(requestedEnvId, currentSessionId)) {
501
+ logEvent("tengu_bridge_repl_reconnected_in_place", {});
502
+ environmentRecreations = 0;
503
+ return true;
504
+ }
505
+ if (environmentId !== requestedEnvId) {
506
+ logEvent("tengu_bridge_repl_env_expired_fresh_session", {});
507
+ }
508
+ await archiveSession(currentSessionId);
509
+ if (pollController.signal.aborted) {
510
+ logForDebugging("[bridge:repl] Reconnect aborted after archive, cleaning up");
511
+ await api.deregisterEnvironment(environmentId).catch(() => {});
512
+ return false;
513
+ }
514
+ const currentTitle = getCurrentTitle();
515
+ const newSessionId = await createSession({
516
+ environmentId,
517
+ title: currentTitle,
518
+ gitRepoUrl,
519
+ branch,
520
+ signal: AbortSignal.timeout(15000)
521
+ });
522
+ if (!newSessionId) {
523
+ logForDebugging("[bridge:repl] Session creation failed during reconnection");
524
+ return false;
525
+ }
526
+ if (pollController.signal.aborted) {
527
+ logForDebugging("[bridge:repl] Reconnect aborted after session creation, cleaning up");
528
+ await archiveSession(newSessionId);
529
+ return false;
530
+ }
531
+ currentSessionId = newSessionId;
532
+ updateSessionBridgeId(toCompatSessionId(newSessionId)).catch(() => {});
533
+ lastTransportSequenceNum = 0;
534
+ recentInboundUUIDs.clear();
535
+ userMessageCallbackDone = !onUserMessage;
536
+ logForDebugging(`[bridge:repl] Re-created session: ${currentSessionId}`);
537
+ await writeBridgePointer(dir, {
538
+ sessionId: currentSessionId,
539
+ environmentId,
540
+ source: "repl"
541
+ });
542
+ previouslyFlushedUUIDs?.clear();
543
+ environmentRecreations = 0;
544
+ return true;
545
+ }
546
+ function getOAuthToken() {
547
+ return getAccessToken();
548
+ }
549
+ function drainFlushGate() {
550
+ const msgs = flushGate.end();
551
+ if (msgs.length === 0)
552
+ return;
553
+ if (!transport) {
554
+ logForDebugging(`[bridge:repl] Cannot drain ${msgs.length} pending message(s): no transport`);
555
+ return;
556
+ }
557
+ for (const msg of msgs) {
558
+ recentPostedUUIDs.add(msg.uuid);
559
+ }
560
+ const sdkMessages = toSDKMessages2(msgs);
561
+ const events = sdkMessages.map((sdkMsg) => ({
562
+ ...sdkMsg,
563
+ session_id: currentSessionId
564
+ }));
565
+ logForDebugging(`[bridge:repl] Drained ${msgs.length} pending message(s) after flush`);
566
+ transport.writeBatch(events);
567
+ }
568
+ let doTeardownImpl = null;
569
+ function triggerTeardown() {
570
+ doTeardownImpl?.();
571
+ }
572
+ function handleTransportPermanentClose(closeCode) {
573
+ logForDebugging(`[bridge:repl] Transport permanently closed: code=${closeCode}`);
574
+ logEvent("tengu_bridge_repl_ws_closed", {
575
+ code: closeCode
576
+ });
577
+ if (transport) {
578
+ const closedSeq = transport.getLastSequenceNum();
579
+ if (closedSeq > lastTransportSequenceNum) {
580
+ lastTransportSequenceNum = closedSeq;
581
+ }
582
+ transport = null;
583
+ }
584
+ wakePollLoop();
585
+ const dropped = flushGate.drop();
586
+ if (dropped > 0) {
587
+ logForDebugging(`[bridge:repl] Dropping ${dropped} pending message(s) on transport close (code=${closeCode})`, { level: "warn" });
588
+ }
589
+ if (closeCode === 1000) {
590
+ onStateChange?.("failed", "session ended");
591
+ pollController.abort();
592
+ triggerTeardown();
593
+ return;
594
+ }
595
+ onStateChange?.("reconnecting", `Remote Control connection lost (code ${closeCode})`);
596
+ logForDebugging(`[bridge:repl] Transport reconnect budget exhausted (code=${closeCode}), attempting env reconnect`);
597
+ reconnectEnvironmentWithSession().then((success) => {
598
+ if (success)
599
+ return;
600
+ if (pollController.signal.aborted)
601
+ return;
602
+ logForDebugging("[bridge:repl] reconnectEnvironmentWithSession resolved false \u2014 tearing down");
603
+ logEvent("tengu_bridge_repl_reconnect_failed", {
604
+ close_code: closeCode
605
+ });
606
+ onStateChange?.("failed", "reconnection failed");
607
+ triggerTeardown();
608
+ });
609
+ }
610
+ let sigusr2Handler;
611
+ if (process.env.USER_TYPE === "ant" && process.platform !== "win32") {
612
+ sigusr2Handler = () => {
613
+ logForDebugging("[bridge:repl] SIGUSR2 received \u2014 forcing doReconnect() for testing");
614
+ reconnectEnvironmentWithSession();
615
+ };
616
+ process.on("SIGUSR2", sigusr2Handler);
617
+ }
618
+ let debugFireClose = null;
619
+ if (process.env.USER_TYPE === "ant") {
620
+ registerBridgeDebugHandle({
621
+ fireClose: (code) => {
622
+ if (!debugFireClose) {
623
+ logForDebugging("[bridge:debug] fireClose: no transport wired yet");
624
+ return;
625
+ }
626
+ logForDebugging(`[bridge:debug] fireClose(${code}) \u2014 injecting`);
627
+ debugFireClose(code);
628
+ },
629
+ forceReconnect: () => {
630
+ logForDebugging("[bridge:debug] forceReconnect \u2014 injecting");
631
+ reconnectEnvironmentWithSession();
632
+ },
633
+ injectFault: injectBridgeFault,
634
+ wakePollLoop,
635
+ describe: () => `env=${environmentId} session=${currentSessionId} transport=${transport?.getStateLabel() ?? "null"} workId=${currentWorkId ?? "null"}`
636
+ });
637
+ }
638
+ const pollOpts = {
639
+ api,
640
+ getCredentials: () => ({ environmentId, environmentSecret }),
641
+ signal: pollController.signal,
642
+ getPollIntervalConfig: getPollIntervalConfig2,
643
+ onStateChange,
644
+ getWsState: () => transport?.getStateLabel() ?? "null",
645
+ isAtCapacity: () => transport !== null,
646
+ capacitySignal,
647
+ onFatalError: triggerTeardown,
648
+ getHeartbeatInfo: () => {
649
+ if (!currentWorkId || !currentIngressToken) {
650
+ return null;
651
+ }
652
+ return {
653
+ environmentId,
654
+ workId: currentWorkId,
655
+ sessionToken: currentIngressToken
656
+ };
657
+ },
658
+ onHeartbeatFatal: (err) => {
659
+ logForDebugging(`[bridge:repl] heartbeatWork fatal (status=${err.status}) \u2014 tearing down work item for fast re-dispatch`);
660
+ if (transport) {
661
+ const seq2 = transport.getLastSequenceNum();
662
+ if (seq2 > lastTransportSequenceNum) {
663
+ lastTransportSequenceNum = seq2;
664
+ }
665
+ transport.close();
666
+ transport = null;
667
+ }
668
+ flushGate.drop();
669
+ if (currentWorkId) {
670
+ api.stopWork(environmentId, currentWorkId, false).catch((e) => {
671
+ logForDebugging(`[bridge:repl] stopWork after heartbeat fatal: ${errorMessage(e)}`);
672
+ });
673
+ }
674
+ currentWorkId = null;
675
+ currentIngressToken = null;
676
+ wakePollLoop();
677
+ onStateChange?.("reconnecting", "Work item lease expired, fetching fresh token");
678
+ },
679
+ async onEnvironmentLost() {
680
+ const success = await reconnectEnvironmentWithSession();
681
+ if (!success) {
682
+ return null;
683
+ }
684
+ return { environmentId, environmentSecret };
685
+ },
686
+ onWorkReceived: (workSessionId, ingressToken, workId, serverUseCcrV2) => {
687
+ if (transport?.isConnectedStatus()) {
688
+ logForDebugging(`[bridge:repl] Work received while transport connected, replacing with fresh token (workId=${workId})`);
689
+ }
690
+ logForDebugging(`[bridge:repl] Work received: workId=${workId} workSessionId=${workSessionId} currentSessionId=${currentSessionId} match=${sameSessionId(workSessionId, currentSessionId)}`);
691
+ writeBridgePointer(dir, {
692
+ sessionId: currentSessionId,
693
+ environmentId,
694
+ source: "repl"
695
+ });
696
+ if (!sameSessionId(workSessionId, currentSessionId)) {
697
+ logForDebugging(`[bridge:repl] Rejecting foreign session: expected=${currentSessionId} got=${workSessionId}`);
698
+ return;
699
+ }
700
+ currentWorkId = workId;
701
+ currentIngressToken = ingressToken;
702
+ const useCcrV2 = serverUseCcrV2 || isEnvTruthy(process.env.CLAUDE_BRIDGE_USE_CCR_V2);
703
+ let v1OauthToken;
704
+ if (!useCcrV2) {
705
+ v1OauthToken = getOAuthToken();
706
+ if (!v1OauthToken) {
707
+ logForDebugging("[bridge:repl] No OAuth token available for session ingress, skipping work");
708
+ return;
709
+ }
710
+ updateSessionIngressAuthToken(v1OauthToken);
711
+ }
712
+ logEvent("tengu_bridge_repl_work_received", {});
713
+ if (transport) {
714
+ const oldTransport = transport;
715
+ transport = null;
716
+ const oldSeq = oldTransport.getLastSequenceNum();
717
+ if (oldSeq > lastTransportSequenceNum) {
718
+ lastTransportSequenceNum = oldSeq;
719
+ }
720
+ oldTransport.close();
721
+ }
722
+ flushGate.deactivate();
723
+ const onServerControlRequest = (request) => handleServerControlRequest(request, {
724
+ transport,
725
+ sessionId: currentSessionId,
726
+ onInterrupt,
727
+ onSetModel,
728
+ onSetMaxThinkingTokens,
729
+ onSetPermissionMode
730
+ });
731
+ let initialFlushDone = false;
732
+ const wireTransport = (newTransport) => {
733
+ transport = newTransport;
734
+ newTransport.setOnConnect(() => {
735
+ if (transport !== newTransport)
736
+ return;
737
+ logForDebugging("[bridge:repl] Ingress transport connected");
738
+ logEvent("tengu_bridge_repl_ws_connected", {});
739
+ if (!useCcrV2) {
740
+ const freshToken = getOAuthToken();
741
+ if (freshToken) {
742
+ updateSessionIngressAuthToken(freshToken);
743
+ }
744
+ }
745
+ teardownStarted = false;
746
+ if (!initialFlushDone && initialMessages && initialMessages.length > 0) {
747
+ initialFlushDone = true;
748
+ const historyCap = initialHistoryCap;
749
+ const eligibleMessages = initialMessages.filter((m) => isEligibleBridgeMessage(m) && !previouslyFlushedUUIDs?.has(m.uuid));
750
+ const cappedMessages = historyCap > 0 && eligibleMessages.length > historyCap ? eligibleMessages.slice(-historyCap) : eligibleMessages;
751
+ if (cappedMessages.length < eligibleMessages.length) {
752
+ logForDebugging(`[bridge:repl] Capped initial flush: ${eligibleMessages.length} -> ${cappedMessages.length} (cap=${historyCap})`);
753
+ logEvent("tengu_bridge_repl_history_capped", {
754
+ eligible_count: eligibleMessages.length,
755
+ capped_count: cappedMessages.length
756
+ });
757
+ }
758
+ const sdkMessages = toSDKMessages2(cappedMessages);
759
+ if (sdkMessages.length > 0) {
760
+ logForDebugging(`[bridge:repl] Flushing ${sdkMessages.length} initial message(s) via transport`);
761
+ const events = sdkMessages.map((sdkMsg) => ({
762
+ ...sdkMsg,
763
+ session_id: currentSessionId
764
+ }));
765
+ const dropsBefore = newTransport.droppedBatchCount;
766
+ newTransport.writeBatch(events).then(() => {
767
+ if (newTransport.droppedBatchCount > dropsBefore) {
768
+ logForDebugging(`[bridge:repl] Initial flush dropped ${newTransport.droppedBatchCount - dropsBefore} batch(es) \u2014 not marking ${sdkMessages.length} UUID(s) as flushed`);
769
+ return;
770
+ }
771
+ if (previouslyFlushedUUIDs) {
772
+ for (const sdkMsg of sdkMessages) {
773
+ if (sdkMsg.uuid) {
774
+ previouslyFlushedUUIDs.add(sdkMsg.uuid);
775
+ }
776
+ }
777
+ }
778
+ }).catch((e) => logForDebugging(`[bridge:repl] Initial flush failed: ${e}`)).finally(() => {
779
+ if (transport !== newTransport)
780
+ return;
781
+ drainFlushGate();
782
+ onStateChange?.("connected");
783
+ });
784
+ } else {
785
+ drainFlushGate();
786
+ onStateChange?.("connected");
787
+ }
788
+ } else if (!flushGate.active) {
789
+ onStateChange?.("connected");
790
+ }
791
+ });
792
+ newTransport.setOnData((data) => {
793
+ handleIngressMessage(data, recentPostedUUIDs, recentInboundUUIDs, onInboundMessage, onPermissionResponse, onServerControlRequest);
794
+ });
795
+ debugFireClose = handleTransportPermanentClose;
796
+ newTransport.setOnClose((closeCode) => {
797
+ if (transport !== newTransport)
798
+ return;
799
+ handleTransportPermanentClose(closeCode);
800
+ });
801
+ if (!initialFlushDone && initialMessages && initialMessages.length > 0) {
802
+ flushGate.start();
803
+ }
804
+ newTransport.connect();
805
+ };
806
+ v2Generation++;
807
+ if (useCcrV2) {
808
+ const sessionUrl = buildCCRv2SdkUrl(baseUrl, workSessionId);
809
+ const thisGen = v2Generation;
810
+ logForDebugging(`[bridge:repl] CCR v2: sessionUrl=${sessionUrl} session=${workSessionId} gen=${thisGen}`);
811
+ createV2ReplTransport({
812
+ sessionUrl,
813
+ ingressToken,
814
+ sessionId: workSessionId,
815
+ initialSequenceNum: lastTransportSequenceNum
816
+ }).then((t) => {
817
+ if (pollController.signal.aborted) {
818
+ t.close();
819
+ return;
820
+ }
821
+ if (thisGen !== v2Generation) {
822
+ logForDebugging(`[bridge:repl] CCR v2: discarding stale handshake gen=${thisGen} current=${v2Generation}`);
823
+ t.close();
824
+ return;
825
+ }
826
+ wireTransport(t);
827
+ }, (err) => {
828
+ logForDebugging(`[bridge:repl] CCR v2: createV2ReplTransport failed: ${errorMessage(err)}`, { level: "error" });
829
+ logEvent("tengu_bridge_repl_ccr_v2_init_failed", {});
830
+ if (thisGen !== v2Generation)
831
+ return;
832
+ if (currentWorkId) {
833
+ api.stopWork(environmentId, currentWorkId, false).catch((e) => {
834
+ logForDebugging(`[bridge:repl] stopWork after v2 init failure: ${errorMessage(e)}`);
835
+ });
836
+ currentWorkId = null;
837
+ currentIngressToken = null;
838
+ }
839
+ wakePollLoop();
840
+ });
841
+ } else {
842
+ const wsUrl = buildSdkUrl(sessionIngressUrl, workSessionId);
843
+ logForDebugging(`[bridge:repl] Ingress URL: ${wsUrl}`);
844
+ logForDebugging(`[bridge:repl] Creating HybridTransport: session=${workSessionId}`);
845
+ const oauthToken = v1OauthToken ?? "";
846
+ wireTransport(createV1ReplTransport(new HybridTransport(new URL(wsUrl), {
847
+ Authorization: `Bearer ${oauthToken}`,
848
+ "anthropic-version": "2023-06-01"
849
+ }, workSessionId, () => ({
850
+ Authorization: `Bearer ${getOAuthToken() ?? oauthToken}`,
851
+ "anthropic-version": "2023-06-01"
852
+ }), {
853
+ maxConsecutiveFailures: 50,
854
+ isBridge: true,
855
+ onBatchDropped: () => {
856
+ onStateChange?.("reconnecting", "Lost sync with Remote Control \u2014 events could not be delivered");
857
+ wakePollLoop();
858
+ }
859
+ })));
860
+ }
861
+ }
862
+ };
863
+ startWorkPollLoop(pollOpts);
864
+ const pointerRefreshTimer = perpetual ? setInterval(() => {
865
+ if (reconnectPromise)
866
+ return;
867
+ writeBridgePointer(dir, {
868
+ sessionId: currentSessionId,
869
+ environmentId,
870
+ source: "repl"
871
+ });
872
+ }, 3600000) : null;
873
+ pointerRefreshTimer?.unref?.();
874
+ const keepAliveIntervalMs = getPollIntervalConfig2().session_keepalive_interval_v2_ms;
875
+ const keepAliveTimer = keepAliveIntervalMs > 0 ? setInterval(() => {
876
+ if (!transport)
877
+ return;
878
+ logForDebugging("[bridge:repl] keep_alive sent");
879
+ transport.write({ type: "keep_alive" }).catch((err) => {
880
+ logForDebugging(`[bridge:repl] keep_alive write failed: ${errorMessage(err)}`);
881
+ });
882
+ }, keepAliveIntervalMs) : null;
883
+ keepAliveTimer?.unref?.();
884
+ let teardownStarted = false;
885
+ doTeardownImpl = async () => {
886
+ if (teardownStarted) {
887
+ logForDebugging(`[bridge:repl] Teardown already in progress, skipping duplicate call env=${environmentId} session=${currentSessionId}`);
888
+ return;
889
+ }
890
+ teardownStarted = true;
891
+ const teardownStart = Date.now();
892
+ logForDebugging(`[bridge:repl] Teardown starting: env=${environmentId} session=${currentSessionId} workId=${currentWorkId ?? "none"} transportState=${transport?.getStateLabel() ?? "null"}`);
893
+ if (pointerRefreshTimer !== null) {
894
+ clearInterval(pointerRefreshTimer);
895
+ }
896
+ if (keepAliveTimer !== null) {
897
+ clearInterval(keepAliveTimer);
898
+ }
899
+ if (sigusr2Handler) {
900
+ process.off("SIGUSR2", sigusr2Handler);
901
+ }
902
+ if (process.env.USER_TYPE === "ant") {
903
+ clearBridgeDebugHandle();
904
+ debugFireClose = null;
905
+ }
906
+ pollController.abort();
907
+ logForDebugging("[bridge:repl] Teardown: poll loop aborted");
908
+ if (transport) {
909
+ const finalSeq = transport.getLastSequenceNum();
910
+ if (finalSeq > lastTransportSequenceNum) {
911
+ lastTransportSequenceNum = finalSeq;
912
+ }
913
+ }
914
+ if (perpetual) {
915
+ transport = null;
916
+ flushGate.drop();
917
+ await writeBridgePointer(dir, {
918
+ sessionId: currentSessionId,
919
+ environmentId,
920
+ source: "repl"
921
+ });
922
+ logForDebugging(`[bridge:repl] Teardown (perpetual): leaving env=${environmentId} session=${currentSessionId} alive on server, duration=${Date.now() - teardownStart}ms`);
923
+ return;
924
+ }
925
+ const teardownTransport = transport;
926
+ transport = null;
927
+ flushGate.drop();
928
+ if (teardownTransport) {
929
+ teardownTransport.write(makeResultMessage(currentSessionId));
930
+ }
931
+ const stopWorkP = currentWorkId ? api.stopWork(environmentId, currentWorkId, true).then(() => {
932
+ logForDebugging("[bridge:repl] Teardown: stopWork completed");
933
+ }).catch((err) => {
934
+ logForDebugging(`[bridge:repl] Teardown stopWork failed: ${errorMessage(err)}`);
935
+ }) : Promise.resolve();
936
+ await Promise.all([stopWorkP, archiveSession(currentSessionId)]);
937
+ teardownTransport?.close();
938
+ logForDebugging("[bridge:repl] Teardown: transport closed");
939
+ await api.deregisterEnvironment(environmentId).catch((err) => {
940
+ logForDebugging(`[bridge:repl] Teardown deregister failed: ${errorMessage(err)}`);
941
+ });
942
+ await clearBridgePointer(dir);
943
+ logForDebugging(`[bridge:repl] Teardown complete: env=${environmentId} duration=${Date.now() - teardownStart}ms`);
944
+ };
945
+ const unregister = registerCleanup(() => doTeardownImpl?.());
946
+ logForDebugging(`[bridge:repl] Ready: env=${environmentId} session=${currentSessionId}`);
947
+ onStateChange?.("ready");
948
+ return {
949
+ get bridgeSessionId() {
950
+ return currentSessionId;
951
+ },
952
+ get environmentId() {
953
+ return environmentId;
954
+ },
955
+ getSSESequenceNum() {
956
+ const live = transport?.getLastSequenceNum() ?? 0;
957
+ return Math.max(lastTransportSequenceNum, live);
958
+ },
959
+ sessionIngressUrl,
960
+ writeMessages(messages) {
961
+ const filtered = messages.filter((m) => isEligibleBridgeMessage(m) && !initialMessageUUIDs.has(m.uuid) && !recentPostedUUIDs.has(m.uuid));
962
+ if (filtered.length === 0)
963
+ return;
964
+ if (!userMessageCallbackDone) {
965
+ for (const m of filtered) {
966
+ const text = extractTitleText(m);
967
+ if (text !== undefined && onUserMessage?.(text, currentSessionId)) {
968
+ userMessageCallbackDone = true;
969
+ break;
970
+ }
971
+ }
972
+ }
973
+ if (flushGate.enqueue(...filtered)) {
974
+ logForDebugging(`[bridge:repl] Queued ${filtered.length} message(s) during initial flush`);
975
+ return;
976
+ }
977
+ if (!transport) {
978
+ const types = filtered.map((m) => m.type).join(",");
979
+ logForDebugging(`[bridge:repl] Transport not configured, dropping ${filtered.length} message(s) [${types}] for session=${currentSessionId}`, { level: "warn" });
980
+ return;
981
+ }
982
+ for (const msg of filtered) {
983
+ recentPostedUUIDs.add(msg.uuid);
984
+ }
985
+ logForDebugging(`[bridge:repl] Sending ${filtered.length} message(s) via transport`);
986
+ const sdkMessages = toSDKMessages2(filtered);
987
+ const events = sdkMessages.map((sdkMsg) => ({
988
+ ...sdkMsg,
989
+ session_id: currentSessionId
990
+ }));
991
+ transport.writeBatch(events);
992
+ },
993
+ writeSdkMessages(messages) {
994
+ const filtered = messages.filter((m) => !m.uuid || !recentPostedUUIDs.has(m.uuid));
995
+ if (filtered.length === 0)
996
+ return;
997
+ if (!transport) {
998
+ logForDebugging(`[bridge:repl] Transport not configured, dropping ${filtered.length} SDK message(s) for session=${currentSessionId}`, { level: "warn" });
999
+ return;
1000
+ }
1001
+ for (const msg of filtered) {
1002
+ if (msg.uuid)
1003
+ recentPostedUUIDs.add(msg.uuid);
1004
+ }
1005
+ const events = filtered.map((m) => ({ ...m, session_id: currentSessionId }));
1006
+ transport.writeBatch(events);
1007
+ },
1008
+ sendControlRequest(request) {
1009
+ if (!transport) {
1010
+ logForDebugging("[bridge:repl] Transport not configured, skipping control_request");
1011
+ return;
1012
+ }
1013
+ const event = { ...request, session_id: currentSessionId };
1014
+ transport.write(event);
1015
+ logForDebugging(`[bridge:repl] Sent control_request request_id=${request.request_id}`);
1016
+ },
1017
+ sendControlResponse(response) {
1018
+ if (!transport) {
1019
+ logForDebugging("[bridge:repl] Transport not configured, skipping control_response");
1020
+ return;
1021
+ }
1022
+ const event = { ...response, session_id: currentSessionId };
1023
+ transport.write(event);
1024
+ logForDebugging("[bridge:repl] Sent control_response");
1025
+ },
1026
+ sendControlCancelRequest(requestId) {
1027
+ if (!transport) {
1028
+ logForDebugging("[bridge:repl] Transport not configured, skipping control_cancel_request");
1029
+ return;
1030
+ }
1031
+ const event = {
1032
+ type: "control_cancel_request",
1033
+ request_id: requestId,
1034
+ session_id: currentSessionId
1035
+ };
1036
+ transport.write(event);
1037
+ logForDebugging(`[bridge:repl] Sent control_cancel_request request_id=${requestId}`);
1038
+ },
1039
+ sendResult() {
1040
+ if (!transport) {
1041
+ logForDebugging(`[bridge:repl] sendResult: skipping, transport not configured session=${currentSessionId}`);
1042
+ return;
1043
+ }
1044
+ transport.write(makeResultMessage(currentSessionId));
1045
+ logForDebugging(`[bridge:repl] Sent result for session=${currentSessionId}`);
1046
+ },
1047
+ async teardown() {
1048
+ unregister();
1049
+ await doTeardownImpl?.();
1050
+ logForDebugging("[bridge:repl] Torn down");
1051
+ logEvent("tengu_bridge_repl_teardown", {});
1052
+ }
1053
+ };
1054
+ }
1055
+ async function startWorkPollLoop({
1056
+ api,
1057
+ getCredentials,
1058
+ signal,
1059
+ onStateChange,
1060
+ onWorkReceived,
1061
+ onEnvironmentLost,
1062
+ getWsState,
1063
+ isAtCapacity,
1064
+ capacitySignal,
1065
+ onFatalError,
1066
+ getPollIntervalConfig: getPollIntervalConfig2 = () => DEFAULT_POLL_CONFIG,
1067
+ getHeartbeatInfo,
1068
+ onHeartbeatFatal
1069
+ }) {
1070
+ const MAX_ENVIRONMENT_RECREATIONS = 3;
1071
+ logForDebugging(`[bridge:repl] Starting work poll loop for env=${getCredentials().environmentId}`);
1072
+ let consecutiveErrors = 0;
1073
+ let firstErrorTime = null;
1074
+ let lastPollErrorTime = null;
1075
+ let environmentRecreations = 0;
1076
+ let suspensionDetected = false;
1077
+ while (!signal.aborted) {
1078
+ const { environmentId: envId, environmentSecret: envSecret } = getCredentials();
1079
+ const pollConfig = getPollIntervalConfig2();
1080
+ try {
1081
+ const work = await api.pollForWork(envId, envSecret, signal, pollConfig.reclaim_older_than_ms);
1082
+ environmentRecreations = 0;
1083
+ if (consecutiveErrors > 0) {
1084
+ logForDebugging(`[bridge:repl] Poll recovered after ${consecutiveErrors} consecutive error(s)`);
1085
+ consecutiveErrors = 0;
1086
+ firstErrorTime = null;
1087
+ lastPollErrorTime = null;
1088
+ onStateChange?.("ready");
1089
+ }
1090
+ if (!work) {
1091
+ const skipAtCapacityOnce = suspensionDetected;
1092
+ suspensionDetected = false;
1093
+ if (isAtCapacity?.() && capacitySignal && !skipAtCapacityOnce) {
1094
+ const atCapMs = pollConfig.poll_interval_ms_at_capacity;
1095
+ if (pollConfig.non_exclusive_heartbeat_interval_ms > 0 && getHeartbeatInfo) {
1096
+ logEvent("tengu_bridge_heartbeat_mode_entered", {
1097
+ heartbeat_interval_ms: pollConfig.non_exclusive_heartbeat_interval_ms
1098
+ });
1099
+ const pollDeadline = atCapMs > 0 ? Date.now() + atCapMs : null;
1100
+ let needsBackoff = false;
1101
+ let hbCycles = 0;
1102
+ while (!signal.aborted && isAtCapacity() && (pollDeadline === null || Date.now() < pollDeadline)) {
1103
+ const hbConfig = getPollIntervalConfig2();
1104
+ if (hbConfig.non_exclusive_heartbeat_interval_ms <= 0)
1105
+ break;
1106
+ const info = getHeartbeatInfo();
1107
+ if (!info)
1108
+ break;
1109
+ const cap = capacitySignal();
1110
+ try {
1111
+ await api.heartbeatWork(info.environmentId, info.workId, info.sessionToken);
1112
+ } catch (err) {
1113
+ logForDebugging(`[bridge:repl:heartbeat] Failed: ${errorMessage(err)}`);
1114
+ if (err instanceof BridgeFatalError) {
1115
+ cap.cleanup();
1116
+ logEvent("tengu_bridge_heartbeat_error", {
1117
+ status: err.status,
1118
+ error_type: err.status === 401 || err.status === 403 ? "auth_failed" : "fatal"
1119
+ });
1120
+ if (onHeartbeatFatal) {
1121
+ onHeartbeatFatal(err);
1122
+ logForDebugging(`[bridge:repl:heartbeat] Fatal (status=${err.status}), work state cleared \u2014 fast-polling for re-dispatch`);
1123
+ } else {
1124
+ needsBackoff = true;
1125
+ }
1126
+ break;
1127
+ }
1128
+ }
1129
+ hbCycles++;
1130
+ await sleep(hbConfig.non_exclusive_heartbeat_interval_ms, cap.signal);
1131
+ cap.cleanup();
1132
+ }
1133
+ const exitReason = needsBackoff ? "error" : signal.aborted ? "shutdown" : !isAtCapacity() ? "capacity_changed" : pollDeadline !== null && Date.now() >= pollDeadline ? "poll_due" : "config_disabled";
1134
+ logEvent("tengu_bridge_heartbeat_mode_exited", {
1135
+ reason: exitReason,
1136
+ heartbeat_cycles: hbCycles
1137
+ });
1138
+ if (!needsBackoff) {
1139
+ if (exitReason === "poll_due") {
1140
+ logForDebugging(`[bridge:repl] Heartbeat poll_due after ${hbCycles} cycles \u2014 falling through to pollForWork`);
1141
+ }
1142
+ continue;
1143
+ }
1144
+ }
1145
+ const sleepMs = atCapMs > 0 ? atCapMs : pollConfig.non_exclusive_heartbeat_interval_ms;
1146
+ if (sleepMs > 0) {
1147
+ const cap = capacitySignal();
1148
+ const sleepStart = Date.now();
1149
+ await sleep(sleepMs, cap.signal);
1150
+ cap.cleanup();
1151
+ const overrun = Date.now() - sleepStart - sleepMs;
1152
+ if (overrun > 60000) {
1153
+ logForDebugging(`[bridge:repl] At-capacity sleep overran by ${Math.round(overrun / 1000)}s \u2014 process suspension detected, forcing one fast-poll cycle`);
1154
+ logEvent("tengu_bridge_repl_suspension_detected", {
1155
+ overrun_ms: overrun
1156
+ });
1157
+ suspensionDetected = true;
1158
+ }
1159
+ }
1160
+ } else {
1161
+ await sleep(pollConfig.poll_interval_ms_not_at_capacity, signal);
1162
+ }
1163
+ continue;
1164
+ }
1165
+ let secret;
1166
+ try {
1167
+ secret = decodeWorkSecret(work.secret);
1168
+ } catch (err) {
1169
+ logForDebugging(`[bridge:repl] Failed to decode work secret: ${errorMessage(err)}`);
1170
+ logEvent("tengu_bridge_repl_work_secret_failed", {});
1171
+ await api.stopWork(envId, work.id, false).catch(() => {});
1172
+ continue;
1173
+ }
1174
+ logForDebugging(`[bridge:repl] Acknowledging workId=${work.id}`);
1175
+ try {
1176
+ await api.acknowledgeWork(envId, work.id, secret.session_ingress_token);
1177
+ } catch (err) {
1178
+ logForDebugging(`[bridge:repl] Acknowledge failed workId=${work.id}: ${errorMessage(err)}`);
1179
+ }
1180
+ if (work.data.type === "healthcheck") {
1181
+ logForDebugging("[bridge:repl] Healthcheck received");
1182
+ continue;
1183
+ }
1184
+ if (work.data.type === "session") {
1185
+ const workSessionId = work.data.id;
1186
+ try {
1187
+ validateBridgeId(workSessionId, "session_id");
1188
+ } catch {
1189
+ logForDebugging(`[bridge:repl] Invalid session_id in work: ${workSessionId}`);
1190
+ continue;
1191
+ }
1192
+ onWorkReceived(workSessionId, secret.session_ingress_token, work.id, secret.use_code_sessions === true);
1193
+ logForDebugging("[bridge:repl] Work accepted, continuing poll loop");
1194
+ }
1195
+ } catch (err) {
1196
+ if (signal.aborted)
1197
+ break;
1198
+ if (err instanceof BridgeFatalError && err.status === 404 && onEnvironmentLost) {
1199
+ const currentEnvId = getCredentials().environmentId;
1200
+ if (envId !== currentEnvId) {
1201
+ logForDebugging(`[bridge:repl] Stale poll error for old env=${envId}, current env=${currentEnvId} \u2014 skipping onEnvironmentLost`);
1202
+ consecutiveErrors = 0;
1203
+ firstErrorTime = null;
1204
+ continue;
1205
+ }
1206
+ environmentRecreations++;
1207
+ logForDebugging(`[bridge:repl] Environment deleted, attempting re-registration (attempt ${environmentRecreations}/${MAX_ENVIRONMENT_RECREATIONS})`);
1208
+ logEvent("tengu_bridge_repl_env_lost", {
1209
+ attempt: environmentRecreations
1210
+ });
1211
+ if (environmentRecreations > MAX_ENVIRONMENT_RECREATIONS) {
1212
+ logForDebugging(`[bridge:repl] Environment re-registration limit reached (${MAX_ENVIRONMENT_RECREATIONS}), giving up`);
1213
+ onStateChange?.("failed", "Environment deleted and re-registration limit reached");
1214
+ onFatalError?.();
1215
+ break;
1216
+ }
1217
+ onStateChange?.("reconnecting", "environment lost, recreating session");
1218
+ const newCreds = await onEnvironmentLost();
1219
+ if (signal.aborted)
1220
+ break;
1221
+ if (newCreds) {
1222
+ consecutiveErrors = 0;
1223
+ firstErrorTime = null;
1224
+ onStateChange?.("ready");
1225
+ logForDebugging(`[bridge:repl] Re-registered environment: ${newCreds.environmentId}`);
1226
+ continue;
1227
+ }
1228
+ onStateChange?.("failed", "Environment deleted and re-registration failed");
1229
+ onFatalError?.();
1230
+ break;
1231
+ }
1232
+ if (err instanceof BridgeFatalError) {
1233
+ const isExpiry = isExpiredErrorType(err.errorType);
1234
+ const isSuppressible = isSuppressible403(err);
1235
+ logForDebugging(`[bridge:repl] Fatal poll error: ${err.message} (status=${err.status}, type=${err.errorType ?? "unknown"})${isSuppressible ? " (suppressed)" : ""}`);
1236
+ logEvent("tengu_bridge_repl_fatal_error", {
1237
+ status: err.status,
1238
+ error_type: err.errorType
1239
+ });
1240
+ logForDiagnosticsNoPII(isExpiry ? "info" : "error", "bridge_repl_fatal_error", { status: err.status, error_type: err.errorType });
1241
+ if (!isSuppressible) {
1242
+ onStateChange?.("failed", isExpiry ? "session expired \xB7 /remote-control to reconnect" : err.message);
1243
+ }
1244
+ onFatalError?.();
1245
+ break;
1246
+ }
1247
+ const now = Date.now();
1248
+ if (lastPollErrorTime !== null && now - lastPollErrorTime > POLL_ERROR_MAX_DELAY_MS * 2) {
1249
+ logForDebugging(`[bridge:repl] Detected system sleep (${Math.round((now - lastPollErrorTime) / 1000)}s gap), resetting poll error budget`);
1250
+ logForDiagnosticsNoPII("info", "bridge_repl_poll_sleep_detected", {
1251
+ gapMs: now - lastPollErrorTime
1252
+ });
1253
+ consecutiveErrors = 0;
1254
+ firstErrorTime = null;
1255
+ }
1256
+ lastPollErrorTime = now;
1257
+ consecutiveErrors++;
1258
+ if (firstErrorTime === null) {
1259
+ firstErrorTime = now;
1260
+ }
1261
+ const elapsed = now - firstErrorTime;
1262
+ const httpStatus = extractHttpStatus(err);
1263
+ const errMsg = describeAxiosError(err);
1264
+ const wsLabel = getWsState?.() ?? "unknown";
1265
+ logForDebugging(`[bridge:repl] Poll error (attempt ${consecutiveErrors}, elapsed ${Math.round(elapsed / 1000)}s, ws=${wsLabel}): ${errMsg}`);
1266
+ logEvent("tengu_bridge_repl_poll_error", {
1267
+ status: httpStatus,
1268
+ consecutiveErrors,
1269
+ elapsedMs: elapsed
1270
+ });
1271
+ if (consecutiveErrors === 1) {
1272
+ onStateChange?.("reconnecting", errMsg);
1273
+ }
1274
+ if (elapsed >= POLL_ERROR_GIVE_UP_MS) {
1275
+ logForDebugging(`[bridge:repl] Poll failures exceeded ${POLL_ERROR_GIVE_UP_MS / 1000}s (${consecutiveErrors} errors), giving up`);
1276
+ logForDiagnosticsNoPII("info", "bridge_repl_poll_give_up");
1277
+ logEvent("tengu_bridge_repl_poll_give_up", {
1278
+ consecutiveErrors,
1279
+ elapsedMs: elapsed,
1280
+ lastStatus: httpStatus
1281
+ });
1282
+ onStateChange?.("failed", "connection to server lost");
1283
+ break;
1284
+ }
1285
+ const backoff = Math.min(POLL_ERROR_INITIAL_DELAY_MS * 2 ** (consecutiveErrors - 1), POLL_ERROR_MAX_DELAY_MS);
1286
+ if (getPollIntervalConfig2().non_exclusive_heartbeat_interval_ms > 0) {
1287
+ const info = getHeartbeatInfo?.();
1288
+ if (info) {
1289
+ try {
1290
+ await api.heartbeatWork(info.environmentId, info.workId, info.sessionToken);
1291
+ } catch {}
1292
+ }
1293
+ }
1294
+ await sleep(backoff, signal);
1295
+ }
1296
+ }
1297
+ logForDebugging(`[bridge:repl] Work poll loop ended (aborted=${signal.aborted}) env=${getCredentials().environmentId}`);
1298
+ }
1299
+
1300
+ // src/bridge/initReplBridge.ts
1301
+ init_sessionIdCompat();
1302
+ async function initReplBridge(options) {
1303
+ const {
1304
+ onInboundMessage,
1305
+ onPermissionResponse,
1306
+ onInterrupt,
1307
+ onSetModel,
1308
+ onSetMaxThinkingTokens,
1309
+ onSetPermissionMode,
1310
+ onStateChange,
1311
+ initialMessages,
1312
+ getMessages,
1313
+ previouslyFlushedUUIDs,
1314
+ initialName,
1315
+ perpetual,
1316
+ outboundOnly,
1317
+ tags
1318
+ } = options ?? {};
1319
+ setCseShimGate(isCseShimEnabled);
1320
+ if (!await isBridgeEnabledBlocking()) {
1321
+ logBridgeSkip("not_enabled", "[bridge:repl] Skipping: bridge not enabled");
1322
+ return null;
1323
+ }
1324
+ if (!getBridgeAccessToken()) {
1325
+ logBridgeSkip("no_oauth", "[bridge:repl] Skipping: no OAuth tokens");
1326
+ onStateChange?.("failed", "/login");
1327
+ return null;
1328
+ }
1329
+ await waitForPolicyLimitsToLoad();
1330
+ if (!isPolicyAllowed("allow_remote_control")) {
1331
+ logBridgeSkip("policy_denied", "[bridge:repl] Skipping: allow_remote_control policy not allowed");
1332
+ onStateChange?.("failed", "disabled by your organization's policy");
1333
+ return null;
1334
+ }
1335
+ if (!getBridgeTokenOverride()) {
1336
+ const cfg = getGlobalConfig();
1337
+ if (cfg.bridgeOauthDeadExpiresAt != null && (cfg.bridgeOauthDeadFailCount ?? 0) >= 3 && getClaudeAIOAuthTokens()?.expiresAt === cfg.bridgeOauthDeadExpiresAt) {
1338
+ logForDebugging(`[bridge:repl] Skipping: cross-process backoff (dead token seen ${cfg.bridgeOauthDeadFailCount} times)`);
1339
+ return null;
1340
+ }
1341
+ await checkAndRefreshOAuthTokenIfNeeded();
1342
+ const tokens = getClaudeAIOAuthTokens();
1343
+ if (tokens && tokens.expiresAt !== null && tokens.expiresAt <= Date.now()) {
1344
+ logBridgeSkip("oauth_expired_unrefreshable", "[bridge:repl] Skipping: OAuth token expired and refresh failed (re-login required)");
1345
+ onStateChange?.("failed", "/login");
1346
+ const deadExpiresAt = tokens.expiresAt;
1347
+ saveGlobalConfig((c) => ({
1348
+ ...c,
1349
+ bridgeOauthDeadExpiresAt: deadExpiresAt,
1350
+ bridgeOauthDeadFailCount: c.bridgeOauthDeadExpiresAt === deadExpiresAt ? (c.bridgeOauthDeadFailCount ?? 0) + 1 : 1
1351
+ }));
1352
+ return null;
1353
+ }
1354
+ }
1355
+ const baseUrl = getBridgeBaseUrl();
1356
+ let title = `remote-control-${generateShortWordSlug()}`;
1357
+ let hasTitle = false;
1358
+ let hasExplicitTitle = false;
1359
+ if (initialName) {
1360
+ title = initialName;
1361
+ hasTitle = true;
1362
+ hasExplicitTitle = true;
1363
+ } else {
1364
+ const sessionId = getSessionId();
1365
+ const customTitle = sessionId ? getCurrentSessionTitle(sessionId) : undefined;
1366
+ if (customTitle) {
1367
+ title = customTitle;
1368
+ hasTitle = true;
1369
+ hasExplicitTitle = true;
1370
+ } else if (initialMessages && initialMessages.length > 0) {
1371
+ for (let i = initialMessages.length - 1;i >= 0; i--) {
1372
+ const msg = initialMessages[i];
1373
+ if (msg.type !== "user" || msg.isMeta || msg.toolUseResult || msg.isCompactSummary || msg.origin && msg.origin.kind !== "human" || isSyntheticMessage(msg))
1374
+ continue;
1375
+ const rawContent = getContentText(msg.message.content);
1376
+ if (!rawContent)
1377
+ continue;
1378
+ const derived = deriveTitle(rawContent);
1379
+ if (!derived)
1380
+ continue;
1381
+ title = derived;
1382
+ hasTitle = true;
1383
+ break;
1384
+ }
1385
+ }
1386
+ }
1387
+ let userMessageCount = 0;
1388
+ let lastBridgeSessionId;
1389
+ let genSeq = 0;
1390
+ const patch = (derived, bridgeSessionId, atCount) => {
1391
+ hasTitle = true;
1392
+ title = derived;
1393
+ logForDebugging(`[bridge:repl] derived title from message ${atCount}: ${derived}`);
1394
+ updateBridgeSessionTitle(bridgeSessionId, derived, {
1395
+ baseUrl,
1396
+ getAccessToken: getBridgeAccessToken
1397
+ }).catch(() => {});
1398
+ };
1399
+ const generateAndPatch = (input, bridgeSessionId) => {
1400
+ const gen = ++genSeq;
1401
+ const atCount = userMessageCount;
1402
+ generateSessionTitle(input, AbortSignal.timeout(15000)).then((generated) => {
1403
+ if (generated && gen === genSeq && lastBridgeSessionId === bridgeSessionId && !getCurrentSessionTitle(getSessionId())) {
1404
+ patch(generated, bridgeSessionId, atCount);
1405
+ }
1406
+ });
1407
+ };
1408
+ const onUserMessage = (text, bridgeSessionId) => {
1409
+ if (hasExplicitTitle || getCurrentSessionTitle(getSessionId())) {
1410
+ return true;
1411
+ }
1412
+ if (lastBridgeSessionId !== undefined && lastBridgeSessionId !== bridgeSessionId) {
1413
+ userMessageCount = 0;
1414
+ }
1415
+ lastBridgeSessionId = bridgeSessionId;
1416
+ userMessageCount++;
1417
+ if (userMessageCount === 1 && !hasTitle) {
1418
+ const placeholder = deriveTitle(text);
1419
+ if (placeholder)
1420
+ patch(placeholder, bridgeSessionId, userMessageCount);
1421
+ generateAndPatch(text, bridgeSessionId);
1422
+ } else if (userMessageCount === 3) {
1423
+ const msgs = getMessages?.();
1424
+ const input = msgs ? extractConversationText(getMessagesAfterCompactBoundary(msgs)) : text;
1425
+ generateAndPatch(input, bridgeSessionId);
1426
+ }
1427
+ return userMessageCount >= 3;
1428
+ };
1429
+ const initialHistoryCap = getFeatureValue_CACHED_WITH_REFRESH("tengu_bridge_initial_history_cap", 200, 5 * 60 * 1000);
1430
+ const orgUUID = await getOrganizationUUID();
1431
+ if (!orgUUID) {
1432
+ logBridgeSkip("no_org_uuid", "[bridge:repl] Skipping: no org UUID");
1433
+ onStateChange?.("failed", "/login");
1434
+ return null;
1435
+ }
1436
+ if (isEnvLessBridgeEnabled() && !perpetual) {
1437
+ const versionError2 = await checkEnvLessBridgeMinVersion();
1438
+ if (versionError2) {
1439
+ logBridgeSkip("version_too_old", `[bridge:repl] Skipping: ${versionError2}`, true);
1440
+ onStateChange?.("failed", "run `claude update` to upgrade");
1441
+ return null;
1442
+ }
1443
+ logForDebugging("[bridge:repl] Using env-less bridge path (tengu_bridge_repl_v2)");
1444
+ const { initEnvLessBridgeCore } = await import("./chunk-xktbmawc.js");
1445
+ return initEnvLessBridgeCore({
1446
+ baseUrl,
1447
+ orgUUID,
1448
+ title,
1449
+ getAccessToken: getBridgeAccessToken,
1450
+ onAuth401: handleOAuth401Error,
1451
+ toSDKMessages,
1452
+ initialHistoryCap,
1453
+ initialMessages,
1454
+ onInboundMessage,
1455
+ onUserMessage,
1456
+ onPermissionResponse,
1457
+ onInterrupt,
1458
+ onSetModel,
1459
+ onSetMaxThinkingTokens,
1460
+ onSetPermissionMode,
1461
+ onStateChange,
1462
+ outboundOnly,
1463
+ tags
1464
+ });
1465
+ }
1466
+ const versionError = checkBridgeMinVersion();
1467
+ if (versionError) {
1468
+ logBridgeSkip("version_too_old", `[bridge:repl] Skipping: ${versionError}`);
1469
+ onStateChange?.("failed", "run `claude update` to upgrade");
1470
+ return null;
1471
+ }
1472
+ const branch = await getBranch();
1473
+ const gitRepoUrl = await getRemoteUrl();
1474
+ const sessionIngressUrl = process.env.USER_TYPE === "ant" && process.env.CLAUDE_BRIDGE_SESSION_INGRESS_URL ? process.env.CLAUDE_BRIDGE_SESSION_INGRESS_URL : baseUrl;
1475
+ let workerType = "claude_code";
1476
+ if (false) {}
1477
+ return initBridgeCore({
1478
+ dir: getOriginalCwd(),
1479
+ machineName: hostname(),
1480
+ branch,
1481
+ gitRepoUrl,
1482
+ title,
1483
+ baseUrl,
1484
+ sessionIngressUrl,
1485
+ workerType,
1486
+ getAccessToken: getBridgeAccessToken,
1487
+ createSession: (opts) => createBridgeSession({
1488
+ ...opts,
1489
+ events: [],
1490
+ baseUrl,
1491
+ getAccessToken: getBridgeAccessToken
1492
+ }),
1493
+ archiveSession: (sessionId) => archiveBridgeSession(sessionId, {
1494
+ baseUrl,
1495
+ getAccessToken: getBridgeAccessToken,
1496
+ timeoutMs: 1500
1497
+ }).catch((err) => {
1498
+ logForDebugging(`[bridge:repl] archiveBridgeSession threw: ${errorMessage(err)}`, { level: "error" });
1499
+ }),
1500
+ getCurrentTitle: () => getCurrentSessionTitle(getSessionId()) ?? title,
1501
+ onUserMessage,
1502
+ toSDKMessages,
1503
+ onAuth401: handleOAuth401Error,
1504
+ getPollIntervalConfig,
1505
+ initialHistoryCap,
1506
+ initialMessages,
1507
+ previouslyFlushedUUIDs,
1508
+ onInboundMessage,
1509
+ onPermissionResponse,
1510
+ onInterrupt,
1511
+ onSetModel,
1512
+ onSetMaxThinkingTokens,
1513
+ onSetPermissionMode,
1514
+ onStateChange,
1515
+ perpetual
1516
+ });
1517
+ }
1518
+ var TITLE_MAX_LEN = 50;
1519
+ function deriveTitle(raw) {
1520
+ const clean = stripDisplayTagsAllowEmpty(raw);
1521
+ const firstSentence = /^(.*?[.!?])\s/.exec(clean)?.[1] ?? clean;
1522
+ const flat = firstSentence.replace(/\s+/g, " ").trim();
1523
+ if (!flat)
1524
+ return;
1525
+ return flat.length > TITLE_MAX_LEN ? flat.slice(0, TITLE_MAX_LEN - 1) + "\u2026" : flat;
1526
+ }
1527
+ export {
1528
+ initReplBridge
1529
+ };