jialing-code 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -0
- package/dist/chunk-065m026w.js +97 -0
- package/dist/chunk-06saje2v.js +39 -0
- package/dist/chunk-0731m51q.js +8 -0
- package/dist/chunk-0975ccyw.js +265 -0
- package/dist/chunk-09n3fjx5.js +67 -0
- package/dist/chunk-0bdjdzew.js +41 -0
- package/dist/chunk-0ce6kd7y.js +212 -0
- package/dist/chunk-0e1xsncc.js +969 -0
- package/dist/chunk-0m2861gw.js +154 -0
- package/dist/chunk-0paqc2yw.js +15 -0
- package/dist/chunk-0rg6yrhy.js +99 -0
- package/dist/chunk-0sakxrcf.js +643 -0
- package/dist/chunk-0v9hwxvz.js +105 -0
- package/dist/chunk-0vkfrmqm.js +690 -0
- package/dist/chunk-0vvfnhhv.js +248 -0
- package/dist/chunk-0w4rsycj.js +145 -0
- package/dist/chunk-0x9b2nmd.js +63 -0
- package/dist/chunk-0xjaqda8.js +1124 -0
- package/dist/chunk-1141xmr4.js +8 -0
- package/dist/chunk-13d1842d.js +154 -0
- package/dist/chunk-1921a6yb.js +32 -0
- package/dist/chunk-1ad8mk9g.js +527 -0
- package/dist/chunk-1ax41pws.js +28 -0
- package/dist/chunk-1c8z1b5v.js +16 -0
- package/dist/chunk-1cbn5kxf.js +7 -0
- package/dist/chunk-1eapde8a.js +726 -0
- package/dist/chunk-1h2famwb.js +49 -0
- package/dist/chunk-1jggnf7z.js +85 -0
- package/dist/chunk-1k92pn9c.js +32 -0
- package/dist/chunk-1qakq4sn.js +802 -0
- package/dist/chunk-1rvz0433.js +722 -0
- package/dist/chunk-1xkekb9y.js +19 -0
- package/dist/chunk-238g70xa.js +36 -0
- package/dist/chunk-24ge0eqa.js +106 -0
- package/dist/chunk-278vghwm.js +5395 -0
- package/dist/chunk-27xc1csx.js +104 -0
- package/dist/chunk-2a42s11t.js +412 -0
- package/dist/chunk-2aa02aw6.js +438 -0
- package/dist/chunk-2eykm0j0.js +20 -0
- package/dist/chunk-2gzv8nrw.js +205 -0
- package/dist/chunk-2k995y2x.js +880 -0
- package/dist/chunk-2nayx6q1.js +63 -0
- package/dist/chunk-2sd2w2h4.js +44 -0
- package/dist/chunk-2tw2ve8h.js +145 -0
- package/dist/chunk-30rst83v.js +168 -0
- package/dist/chunk-3aavh06g.js +1581 -0
- package/dist/chunk-3b0yvt2h.js +469 -0
- package/dist/chunk-3be7ka25.js +56 -0
- package/dist/chunk-3c25bcsw.js +17 -0
- package/dist/chunk-3dyxka97.js +584 -0
- package/dist/chunk-3f7rypmf.js +16544 -0
- package/dist/chunk-3fsd7f51.js +93 -0
- package/dist/chunk-3gqdqmzb.js +75 -0
- package/dist/chunk-3h8a89gy.js +46 -0
- package/dist/chunk-3m84sret.js +71 -0
- package/dist/chunk-3nb7j3js.js +96 -0
- package/dist/chunk-3p08nvn2.js +98 -0
- package/dist/chunk-3r09htpc.js +318 -0
- package/dist/chunk-3r24h7t6.js +113 -0
- package/dist/chunk-3rkfxjtq.js +80 -0
- package/dist/chunk-3tmk7dc2.js +604 -0
- package/dist/chunk-3w6s9m5w.js +16 -0
- package/dist/chunk-43qjymy5.js +92 -0
- package/dist/chunk-44fpr6jq.js +434 -0
- package/dist/chunk-45kxdsp8.js +444 -0
- package/dist/chunk-495d85x1.js +8066 -0
- package/dist/chunk-4ba796se.js +1095 -0
- package/dist/chunk-4g3v8y12.js +23 -0
- package/dist/chunk-4h53xj8n.js +3445 -0
- package/dist/chunk-4jm600zv.js +13 -0
- package/dist/chunk-4jy9dtwk.js +116 -0
- package/dist/chunk-4p60dd45.js +55 -0
- package/dist/chunk-4z0jsrqg.js +81 -0
- package/dist/chunk-4zfkzkt6.js +37 -0
- package/dist/chunk-55wgxwa9.js +13877 -0
- package/dist/chunk-5dbk24zg.js +890 -0
- package/dist/chunk-5hzvp4va.js +115 -0
- package/dist/chunk-5kbt1mbt.js +500 -0
- package/dist/chunk-5pen7vr8.js +176 -0
- package/dist/chunk-5r280eng.js +198 -0
- package/dist/chunk-5srym52s.js +88 -0
- package/dist/chunk-600kg7k6.js +41 -0
- package/dist/chunk-616w0qj3.js +160 -0
- package/dist/chunk-62jw1t8c.js +94 -0
- package/dist/chunk-62xmt9mk.js +372 -0
- package/dist/chunk-64bvg7c3.js +229 -0
- package/dist/chunk-65yhe4s0.js +281 -0
- package/dist/chunk-6aewh27m.js +102 -0
- package/dist/chunk-6bd8brc4.js +48 -0
- package/dist/chunk-6dj5t602.js +341 -0
- package/dist/chunk-6exxdk1p.js +6956 -0
- package/dist/chunk-6f5j8fs0.js +752 -0
- package/dist/chunk-6g62sjpf.js +328 -0
- package/dist/chunk-6gecq2ta.js +1493 -0
- package/dist/chunk-6gr3c3w9.js +378 -0
- package/dist/chunk-6kpbgc5w.js +23 -0
- package/dist/chunk-6kseqw79.js +154 -0
- package/dist/chunk-6mxm1qd0.js +40764 -0
- package/dist/chunk-6n2qgm9v.js +8 -0
- package/dist/chunk-6tq2v3rk.js +186 -0
- package/dist/chunk-6wsdhj3v.js +93 -0
- package/dist/chunk-6zw9fhgb.js +4389 -0
- package/dist/chunk-71grc1mw.js +111 -0
- package/dist/chunk-73rpbt04.js +1947 -0
- package/dist/chunk-748feghg.js +604 -0
- package/dist/chunk-75e8gtg9.js +84 -0
- package/dist/chunk-75th4717.js +780 -0
- package/dist/chunk-760252na.js +101 -0
- package/dist/chunk-7739pg2c.js +4261 -0
- package/dist/chunk-778fnx46.js +472 -0
- package/dist/chunk-77g09znh.js +391 -0
- package/dist/chunk-7aw745vx.js +40175 -0
- package/dist/chunk-7m2nd8da.js +110 -0
- package/dist/chunk-7n35vjtw.js +444 -0
- package/dist/chunk-7n5ss4sh.js +144 -0
- package/dist/chunk-7rjnxcfe.js +107 -0
- package/dist/chunk-7sb5axvf.js +122 -0
- package/dist/chunk-7wm5s02e.js +216 -0
- package/dist/chunk-7ymfj7m3.js +151 -0
- package/dist/chunk-7z8j9qfn.js +121 -0
- package/dist/chunk-7zsapntc.js +216 -0
- package/dist/chunk-805fhkfh.js +908 -0
- package/dist/chunk-80k1nj24.js +253 -0
- package/dist/chunk-83hfzbx3.js +10 -0
- package/dist/chunk-85cypsdd.js +92 -0
- package/dist/chunk-8760caxf.js +2644 -0
- package/dist/chunk-88f6egg6.js +387 -0
- package/dist/chunk-88r7kwgj.js +22 -0
- package/dist/chunk-89e1v45e.js +463 -0
- package/dist/chunk-8bedvdm1.js +32 -0
- package/dist/chunk-8c4x4vdz.js +177 -0
- package/dist/chunk-8hq5kk3y.js +44 -0
- package/dist/chunk-8ngxagxq.js +18 -0
- package/dist/chunk-8tnsngw2.js +31 -0
- package/dist/chunk-8wjnca8h.js +307 -0
- package/dist/chunk-8y12jxg8.js +10 -0
- package/dist/chunk-8ymf4e6z.js +48 -0
- package/dist/chunk-90wp6wez.js +10510 -0
- package/dist/chunk-92bp5bnf.js +650 -0
- package/dist/chunk-92q8sx5z.js +90 -0
- package/dist/chunk-958rtmtx.js +10476 -0
- package/dist/chunk-9e2kqv5g.js +125 -0
- package/dist/chunk-9f4f1hy5.js +281 -0
- package/dist/chunk-9gbamk79.js +93 -0
- package/dist/chunk-9k5s3ryh.js +167 -0
- package/dist/chunk-9xzfqm15.js +97 -0
- package/dist/chunk-9zgdvbm6.js +110 -0
- package/dist/chunk-a0p3q8jw.js +24 -0
- package/dist/chunk-a22sayzp.js +220 -0
- package/dist/chunk-a8ejc632.js +3094 -0
- package/dist/chunk-a8gj9d9z.js +120 -0
- package/dist/chunk-a9vdeb6y.js +258 -0
- package/dist/chunk-a9yev47v.js +674 -0
- package/dist/chunk-a9zh40sj.js +48 -0
- package/dist/chunk-ack5mfba.js +105 -0
- package/dist/chunk-ae76ded0.js +30 -0
- package/dist/chunk-akjw4dh6.js +538 -0
- package/dist/chunk-asc6wz4q.js +1188 -0
- package/dist/chunk-atqejh3p.js +273 -0
- package/dist/chunk-atv2e6b7.js +61 -0
- package/dist/chunk-axvvkwz8.js +1551 -0
- package/dist/chunk-azgz7kj9.js +38 -0
- package/dist/chunk-b3zave8q.js +275 -0
- package/dist/chunk-b4wg70y1.js +54 -0
- package/dist/chunk-b8b13qn2.js +100 -0
- package/dist/chunk-bg3mt9bm.js +28 -0
- package/dist/chunk-bh4jvcjn.js +91 -0
- package/dist/chunk-bhdt6k7w.js +15 -0
- package/dist/chunk-bm1qb16p.js +17 -0
- package/dist/chunk-bpvsd1j1.js +266 -0
- package/dist/chunk-bqfnp99q.js +477 -0
- package/dist/chunk-bsbmmfyt.js +17 -0
- package/dist/chunk-bsbt34jm.js +42 -0
- package/dist/chunk-c78akdhr.js +458 -0
- package/dist/chunk-cdz5yb0r.js +57 -0
- package/dist/chunk-cfv996bs.js +22 -0
- package/dist/chunk-cgfdkzhb.js +12 -0
- package/dist/chunk-ckh4r5er.js +257 -0
- package/dist/chunk-cmgjnvn9.js +89 -0
- package/dist/chunk-cpjgvay8.js +687 -0
- package/dist/chunk-crfryjx9.js +276 -0
- package/dist/chunk-ctw5jwcd.js +213 -0
- package/dist/chunk-cvy3vntc.js +65 -0
- package/dist/chunk-cwbzz504.js +94 -0
- package/dist/chunk-cy2hswr1.js +15 -0
- package/dist/chunk-cyejkay3.js +222 -0
- package/dist/chunk-d18z9pna.js +106 -0
- package/dist/chunk-d5cq0n0v.js +162 -0
- package/dist/chunk-db45aryp.js +50 -0
- package/dist/chunk-de8nqh0z.js +790 -0
- package/dist/chunk-dfw6h350.js +2336 -0
- package/dist/chunk-dgqrcy74.js +48 -0
- package/dist/chunk-dn75ptgd.js +184 -0
- package/dist/chunk-dnh7jtpb.js +37 -0
- package/dist/chunk-dpshyv9m.js +90 -0
- package/dist/chunk-dt8cdvnm.js +642 -0
- package/dist/chunk-dtxby6fr.js +306 -0
- package/dist/chunk-dv1wfr85.js +6373 -0
- package/dist/chunk-dw363edx.js +1154 -0
- package/dist/chunk-dwrdacck.js +62 -0
- package/dist/chunk-dxnnv5e3.js +276 -0
- package/dist/chunk-e3g8q4cn.js +1646 -0
- package/dist/chunk-e3m9k9s2.js +542 -0
- package/dist/chunk-e4q49asn.js +155 -0
- package/dist/chunk-e5pntxye.js +37 -0
- package/dist/chunk-e7393td6.js +42 -0
- package/dist/chunk-ead42yrh.js +87 -0
- package/dist/chunk-eb90vwvr.js +152 -0
- package/dist/chunk-ecvwk9hg.js +250 -0
- package/dist/chunk-edjd6aay.js +173 -0
- package/dist/chunk-eg0h8mtm.js +130 -0
- package/dist/chunk-ehtwnxpg.js +1591 -0
- package/dist/chunk-ek686gx1.js +94 -0
- package/dist/chunk-eqp1rfft.js +17 -0
- package/dist/chunk-evhwt0ar.js +1015 -0
- package/dist/chunk-ewadzrm8.js +103 -0
- package/dist/chunk-ewsgsw9h.js +172291 -0
- package/dist/chunk-f0pa0r7e.js +3198 -0
- package/dist/chunk-f2mhrmww.js +62 -0
- package/dist/chunk-f39zxvwn.js +401 -0
- package/dist/chunk-f46z54tq.js +374 -0
- package/dist/chunk-f5ma3nh5.js +3436 -0
- package/dist/chunk-f60q23az.js +3038 -0
- package/dist/chunk-f6v2nz57.js +107 -0
- package/dist/chunk-f6yjan38.js +38 -0
- package/dist/chunk-fbv4apne.js +51 -0
- package/dist/chunk-fem4s778.js +70 -0
- package/dist/chunk-fezm1kn8.js +376 -0
- package/dist/chunk-fm1n3ysp.js +6108 -0
- package/dist/chunk-frg83bfw.js +225 -0
- package/dist/chunk-fscm8db0.js +692 -0
- package/dist/chunk-fyc5fepv.js +10 -0
- package/dist/chunk-g0j0t6qk.js +26 -0
- package/dist/chunk-g0nc1ftf.js +849 -0
- package/dist/chunk-g338npwr.js +1061 -0
- package/dist/chunk-g3t0act8.js +8 -0
- package/dist/chunk-g75w4hw3.js +26 -0
- package/dist/chunk-g8vp82en.js +1866 -0
- package/dist/chunk-gax0fcbx.js +182 -0
- package/dist/chunk-gsz4dh3y.js +606 -0
- package/dist/chunk-gtfffm7h.js +440 -0
- package/dist/chunk-gver9zb9.js +420 -0
- package/dist/chunk-gyj242zr.js +20 -0
- package/dist/chunk-h0qngp9w.js +157 -0
- package/dist/chunk-h14kemnk.js +123 -0
- package/dist/chunk-h8wj1a74.js +8960 -0
- package/dist/chunk-h9mcb2eg.js +87 -0
- package/dist/chunk-h9nh2980.js +91 -0
- package/dist/chunk-hakdhagh.js +16606 -0
- package/dist/chunk-hbc6ymdv.js +55 -0
- package/dist/chunk-hh7cmy4k.js +20 -0
- package/dist/chunk-hjhc4cpt.js +69 -0
- package/dist/chunk-hjwez8qc.js +5018 -0
- package/dist/chunk-hk9xz7gk.js +118 -0
- package/dist/chunk-hqmz36b3.js +552 -0
- package/dist/chunk-hrzerbfw.js +1299 -0
- package/dist/chunk-hs8ph4p8.js +8 -0
- package/dist/chunk-ht1xwrnd.js +716 -0
- package/dist/chunk-hvmfg2dc.js +338 -0
- package/dist/chunk-hx2tr4ep.js +7189 -0
- package/dist/chunk-hzhe8ygc.js +547 -0
- package/dist/chunk-j2k4p94p.js +55 -0
- package/dist/chunk-j3a4p81y.js +184 -0
- package/dist/chunk-j49g6g3s.js +57 -0
- package/dist/chunk-j5d5hp9h.js +71 -0
- package/dist/chunk-j64ga6ta.js +8035 -0
- package/dist/chunk-j7tyxan1.js +116 -0
- package/dist/chunk-j8v4774z.js +424 -0
- package/dist/chunk-jafes477.js +29 -0
- package/dist/chunk-jd32zbps.js +15 -0
- package/dist/chunk-jdgeec04.js +4249 -0
- package/dist/chunk-jftd4jq5.js +4521 -0
- package/dist/chunk-jkxqhv6y.js +812 -0
- package/dist/chunk-jmfr6h0n.js +120 -0
- package/dist/chunk-jn4aabmx.js +40 -0
- package/dist/chunk-jnhkref0.js +30 -0
- package/dist/chunk-jsbpm1gz.js +27 -0
- package/dist/chunk-jtcyjc3k.js +5802 -0
- package/dist/chunk-jx817w05.js +11 -0
- package/dist/chunk-jzmz18nn.js +65 -0
- package/dist/chunk-k0p9w03v.js +4957 -0
- package/dist/chunk-k3dcdnck.js +89 -0
- package/dist/chunk-k3wadzcd.js +88 -0
- package/dist/chunk-kaeshsk1.js +713 -0
- package/dist/chunk-kbkey9ed.js +522 -0
- package/dist/chunk-kcwfhqbb.js +196 -0
- package/dist/chunk-key6jr7p.js +224 -0
- package/dist/chunk-knay8cy9.js +173 -0
- package/dist/chunk-kr3rg2y1.js +95 -0
- package/dist/chunk-kwekc97v.js +18 -0
- package/dist/chunk-m06q12hg.js +61 -0
- package/dist/chunk-m2mcpbhk.js +43 -0
- package/dist/chunk-m8v220gz.js +71 -0
- package/dist/chunk-mgpqy78h.js +208 -0
- package/dist/chunk-mkejwh4t.js +16 -0
- package/dist/chunk-mptyw5n1.js +107 -0
- package/dist/chunk-mqajm0dp.js +66 -0
- package/dist/chunk-mrksbgxj.js +490 -0
- package/dist/chunk-msjfc5ba.js +246 -0
- package/dist/chunk-mt25echc.js +6157 -0
- package/dist/chunk-mt3jfnr8.js +277 -0
- package/dist/chunk-mtn242d4.js +9300 -0
- package/dist/chunk-mzfkvave.js +169 -0
- package/dist/chunk-n0qaeaa5.js +256 -0
- package/dist/chunk-n1erf6kh.js +22820 -0
- package/dist/chunk-n2avk1r2.js +61 -0
- package/dist/chunk-n6atnpcq.js +765 -0
- package/dist/chunk-n7ttdtk0.js +641 -0
- package/dist/chunk-ncnfzby5.js +822 -0
- package/dist/chunk-ncnr1jtf.js +2058 -0
- package/dist/chunk-nerv0jvx.js +74 -0
- package/dist/chunk-ngd2abep.js +90 -0
- package/dist/chunk-nka1g8f4.js +773 -0
- package/dist/chunk-nnaxkc2z.js +128 -0
- package/dist/chunk-npyrtj8j.js +691 -0
- package/dist/chunk-nq0fxyxh.js +752 -0
- package/dist/chunk-nrmffak7.js +114 -0
- package/dist/chunk-nsz546wq.js +1170 -0
- package/dist/chunk-nt837qt9.js +21 -0
- package/dist/chunk-nv64x1z5.js +86 -0
- package/dist/chunk-nxsh6de2.js +1711 -0
- package/dist/chunk-nz4getcr.js +40 -0
- package/dist/chunk-p1f607pa.js +83 -0
- package/dist/chunk-p2816w9z.js +1486 -0
- package/dist/chunk-p2d5nh3g.js +342 -0
- package/dist/chunk-p4r5y02t.js +90 -0
- package/dist/chunk-p7g7pf3f.js +336 -0
- package/dist/chunk-pb4ad8r2.js +110 -0
- package/dist/chunk-pbrhz0zr.js +716 -0
- package/dist/chunk-ps49ymvj.js +43 -0
- package/dist/chunk-pwnt3veb.js +103 -0
- package/dist/chunk-pwwa7s62.js +11 -0
- package/dist/chunk-px3w0kde.js +299 -0
- package/dist/chunk-pzn777jb.js +756 -0
- package/dist/chunk-q25bjaev.js +15 -0
- package/dist/chunk-q5by3da6.js +8 -0
- package/dist/chunk-q6av622g.js +38 -0
- package/dist/chunk-q6xkvtf2.js +1318 -0
- package/dist/chunk-q81jx1tq.js +476 -0
- package/dist/chunk-qehb6fk5.js +339 -0
- package/dist/chunk-qj1avx1q.js +87 -0
- package/dist/chunk-qn2dxr66.js +105 -0
- package/dist/chunk-qnfx3qtx.js +617 -0
- package/dist/chunk-qp18kd4h.js +48 -0
- package/dist/chunk-qp2qdcda.js +100 -0
- package/dist/chunk-qpjy9tcf.js +133 -0
- package/dist/chunk-qqfa0dqg.js +2343 -0
- package/dist/chunk-qwh3htcz.js +202 -0
- package/dist/chunk-qz2x630m.js +49145 -0
- package/dist/chunk-r3vakcs1.js +496 -0
- package/dist/chunk-r66hz8j6.js +34 -0
- package/dist/chunk-r6b58y3x.js +17 -0
- package/dist/chunk-rekp48rk.js +62 -0
- package/dist/chunk-rn0v1hk8.js +34 -0
- package/dist/chunk-rs1xrs6m.js +534 -0
- package/dist/chunk-rs45skes.js +123 -0
- package/dist/chunk-rzszqp82.js +524 -0
- package/dist/chunk-s274nv8k.js +8 -0
- package/dist/chunk-s3pzvdss.js +50 -0
- package/dist/chunk-s9mesaw0.js +26840 -0
- package/dist/chunk-sd36yzx8.js +954 -0
- package/dist/chunk-sdj9b9wh.js +782 -0
- package/dist/chunk-sdw2q69p.js +227 -0
- package/dist/chunk-sfgp9cc0.js +130 -0
- package/dist/chunk-spqaamnc.js +63 -0
- package/dist/chunk-spzrs4df.js +73 -0
- package/dist/chunk-sxkr7k43.js +55 -0
- package/dist/chunk-szj5wvdy.js +28 -0
- package/dist/chunk-t0rgmccj.js +39 -0
- package/dist/chunk-t1nnzjgg.js +17 -0
- package/dist/chunk-t94fcnt8.js +566 -0
- package/dist/chunk-tjaqa99q.js +125 -0
- package/dist/chunk-tjq2evtw.js +328 -0
- package/dist/chunk-ts2p6bv1.js +224 -0
- package/dist/chunk-ttk5dzz8.js +25 -0
- package/dist/chunk-tw0q7ynt.js +59 -0
- package/dist/chunk-v02jkvgy.js +131 -0
- package/dist/chunk-v084bqt3.js +1529 -0
- package/dist/chunk-v0amythm.js +164 -0
- package/dist/chunk-v1kzp02e.js +785 -0
- package/dist/chunk-v1mgv1et.js +15 -0
- package/dist/chunk-v399mzxk.js +58 -0
- package/dist/chunk-v3gm2day.js +8 -0
- package/dist/chunk-v43hrrxp.js +71 -0
- package/dist/chunk-v6aqb2aj.js +102 -0
- package/dist/chunk-v78fj8by.js +145 -0
- package/dist/chunk-v7qmhjdn.js +1921 -0
- package/dist/chunk-v9smspw2.js +4301 -0
- package/dist/chunk-vdw93s4h.js +2431 -0
- package/dist/chunk-vest0y6x.js +3830 -0
- package/dist/chunk-vf5sd1nq.js +12 -0
- package/dist/chunk-vratq94g.js +349 -0
- package/dist/chunk-vrz7t3m3.js +20 -0
- package/dist/chunk-vtb185z9.js +70 -0
- package/dist/chunk-vx01rvg8.js +654 -0
- package/dist/chunk-vyc0rjyx.js +31 -0
- package/dist/chunk-vyjeh50y.js +2149 -0
- package/dist/chunk-vzpffsza.js +269 -0
- package/dist/chunk-w2ef3kxk.js +3353 -0
- package/dist/chunk-w2z5pqd3.js +336 -0
- package/dist/chunk-w3whm4mn.js +432 -0
- package/dist/chunk-w7wgpqcp.js +157 -0
- package/dist/chunk-waa00cvb.js +301 -0
- package/dist/chunk-wb0qm4es.js +155 -0
- package/dist/chunk-wbkahkdc.js +27 -0
- package/dist/chunk-wfz0qffj.js +3939 -0
- package/dist/chunk-wn0cx0pt.js +283 -0
- package/dist/chunk-wv6gzt9c.js +726 -0
- package/dist/chunk-wx42ycm4.js +998 -0
- package/dist/chunk-wxkpgy05.js +268 -0
- package/dist/chunk-wzpdet3m.js +843 -0
- package/dist/chunk-x0mwzt38.js +714 -0
- package/dist/chunk-x592wbfh.js +244 -0
- package/dist/chunk-x5pqsp9r.js +100 -0
- package/dist/chunk-x679thag.js +825 -0
- package/dist/chunk-x8b7vft8.js +132 -0
- package/dist/chunk-x8cftch7.js +119 -0
- package/dist/chunk-x9q7r885.js +348 -0
- package/dist/chunk-xawkt0vb.js +1585 -0
- package/dist/chunk-xdw5dv00.js +8 -0
- package/dist/chunk-xe9cc860.js +287 -0
- package/dist/chunk-xjr9c3vt.js +101 -0
- package/dist/chunk-xk7zaqta.js +21933 -0
- package/dist/chunk-xktbmawc.js +678 -0
- package/dist/chunk-xn6yw46v.js +140 -0
- package/dist/chunk-xsq9ae7x.js +90 -0
- package/dist/chunk-xszk7n10.js +14358 -0
- package/dist/chunk-xt8a5r1t.js +84 -0
- package/dist/chunk-xydyndkv.js +195 -0
- package/dist/chunk-xzt10yc5.js +60 -0
- package/dist/chunk-y04y95dr.js +91 -0
- package/dist/chunk-y1784krc.js +19 -0
- package/dist/chunk-y1x32h3x.js +128 -0
- package/dist/chunk-y3s7aww5.js +99 -0
- package/dist/chunk-y47cg3kz.js +42 -0
- package/dist/chunk-y7kzvepn.js +469 -0
- package/dist/chunk-y89kbsyc.js +287 -0
- package/dist/chunk-yd87p1c3.js +159 -0
- package/dist/chunk-yf3yw8fw.js +105 -0
- package/dist/chunk-ygbf0ezx.js +1391 -0
- package/dist/chunk-yjbxnshv.js +208 -0
- package/dist/chunk-ynednmqd.js +192 -0
- package/dist/chunk-yvhez44y.js +259 -0
- package/dist/chunk-ywxd4qw4.js +22 -0
- package/dist/chunk-yzrmgpy4.js +117 -0
- package/dist/chunk-z0b2vb24.js +862 -0
- package/dist/chunk-z1zj044v.js +655 -0
- package/dist/chunk-z2dp53wn.js +17 -0
- package/dist/chunk-z3w0xasa.js +165 -0
- package/dist/chunk-z7ycmrb3.js +644 -0
- package/dist/chunk-zh11tdkb.js +347 -0
- package/dist/chunk-zk2wsm7d.js +15 -0
- package/dist/chunk-zqfqcf22.js +229 -0
- package/dist/chunk-zqk2j8px.js +699 -0
- package/dist/chunk-zqvsc10j.js +2833 -0
- package/dist/chunk-zsfxha74.js +17655 -0
- package/dist/chunk-zvc4snyb.js +117 -0
- package/dist/cli.js +194 -0
- package/package.json +173 -0
|
@@ -0,0 +1,4261 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
__esm
|
|
4
|
+
} from "./chunk-qp2qdcda.js";
|
|
5
|
+
|
|
6
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/tslib.mjs
|
|
7
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
8
|
+
if (kind === "m")
|
|
9
|
+
throw new TypeError("Private method is not writable");
|
|
10
|
+
if (kind === "a" && !f)
|
|
11
|
+
throw new TypeError("Private accessor was defined without a setter");
|
|
12
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
13
|
+
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
14
|
+
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
15
|
+
}
|
|
16
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
17
|
+
if (kind === "a" && !f)
|
|
18
|
+
throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
20
|
+
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
21
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
22
|
+
}
|
|
23
|
+
var init_tslib = () => {};
|
|
24
|
+
|
|
25
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/utils/uuid.mjs
|
|
26
|
+
var uuid4 = function() {
|
|
27
|
+
const { crypto } = globalThis;
|
|
28
|
+
if (crypto?.randomUUID) {
|
|
29
|
+
uuid4 = crypto.randomUUID.bind(crypto);
|
|
30
|
+
return crypto.randomUUID();
|
|
31
|
+
}
|
|
32
|
+
const u8 = new Uint8Array(1);
|
|
33
|
+
const randomByte = crypto ? () => crypto.getRandomValues(u8)[0] : () => Math.random() * 255 & 255;
|
|
34
|
+
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c) => (+c ^ randomByte() & 15 >> +c / 4).toString(16));
|
|
35
|
+
};
|
|
36
|
+
var init_uuid = () => {};
|
|
37
|
+
|
|
38
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/errors.mjs
|
|
39
|
+
function isAbortError(err) {
|
|
40
|
+
return typeof err === "object" && err !== null && (("name" in err) && err.name === "AbortError" || ("message" in err) && String(err.message).includes("FetchRequestCanceledException"));
|
|
41
|
+
}
|
|
42
|
+
var castToError = (err) => {
|
|
43
|
+
if (err instanceof Error)
|
|
44
|
+
return err;
|
|
45
|
+
if (typeof err === "object" && err !== null) {
|
|
46
|
+
try {
|
|
47
|
+
if (Object.prototype.toString.call(err) === "[object Error]") {
|
|
48
|
+
const error = new Error(err.message, err.cause ? { cause: err.cause } : {});
|
|
49
|
+
if (err.stack)
|
|
50
|
+
error.stack = err.stack;
|
|
51
|
+
if (err.cause && !error.cause)
|
|
52
|
+
error.cause = err.cause;
|
|
53
|
+
if (err.name)
|
|
54
|
+
error.name = err.name;
|
|
55
|
+
return error;
|
|
56
|
+
}
|
|
57
|
+
} catch {}
|
|
58
|
+
try {
|
|
59
|
+
return new Error(JSON.stringify(err));
|
|
60
|
+
} catch {}
|
|
61
|
+
}
|
|
62
|
+
return new Error(err);
|
|
63
|
+
};
|
|
64
|
+
var init_errors = () => {};
|
|
65
|
+
|
|
66
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/core/error.mjs
|
|
67
|
+
var AnthropicError, APIError, APIUserAbortError, APIConnectionError, APIConnectionTimeoutError, BadRequestError, AuthenticationError, PermissionDeniedError, NotFoundError, ConflictError, UnprocessableEntityError, RateLimitError, InternalServerError;
|
|
68
|
+
var init_error = __esm(() => {
|
|
69
|
+
init_errors();
|
|
70
|
+
AnthropicError = class AnthropicError extends Error {
|
|
71
|
+
};
|
|
72
|
+
APIError = class APIError extends AnthropicError {
|
|
73
|
+
constructor(status, error, message, headers) {
|
|
74
|
+
super(`${APIError.makeMessage(status, error, message)}`);
|
|
75
|
+
this.status = status;
|
|
76
|
+
this.headers = headers;
|
|
77
|
+
this.requestID = headers?.get("request-id");
|
|
78
|
+
this.error = error;
|
|
79
|
+
}
|
|
80
|
+
static makeMessage(status, error, message) {
|
|
81
|
+
const msg = error?.message ? typeof error.message === "string" ? error.message : JSON.stringify(error.message) : error ? JSON.stringify(error) : message;
|
|
82
|
+
if (status && msg) {
|
|
83
|
+
return `${status} ${msg}`;
|
|
84
|
+
}
|
|
85
|
+
if (status) {
|
|
86
|
+
return `${status} status code (no body)`;
|
|
87
|
+
}
|
|
88
|
+
if (msg) {
|
|
89
|
+
return msg;
|
|
90
|
+
}
|
|
91
|
+
return "(no status code or body)";
|
|
92
|
+
}
|
|
93
|
+
static generate(status, errorResponse, message, headers) {
|
|
94
|
+
if (!status || !headers) {
|
|
95
|
+
return new APIConnectionError({ message, cause: castToError(errorResponse) });
|
|
96
|
+
}
|
|
97
|
+
const error = errorResponse;
|
|
98
|
+
if (status === 400) {
|
|
99
|
+
return new BadRequestError(status, error, message, headers);
|
|
100
|
+
}
|
|
101
|
+
if (status === 401) {
|
|
102
|
+
return new AuthenticationError(status, error, message, headers);
|
|
103
|
+
}
|
|
104
|
+
if (status === 403) {
|
|
105
|
+
return new PermissionDeniedError(status, error, message, headers);
|
|
106
|
+
}
|
|
107
|
+
if (status === 404) {
|
|
108
|
+
return new NotFoundError(status, error, message, headers);
|
|
109
|
+
}
|
|
110
|
+
if (status === 409) {
|
|
111
|
+
return new ConflictError(status, error, message, headers);
|
|
112
|
+
}
|
|
113
|
+
if (status === 422) {
|
|
114
|
+
return new UnprocessableEntityError(status, error, message, headers);
|
|
115
|
+
}
|
|
116
|
+
if (status === 429) {
|
|
117
|
+
return new RateLimitError(status, error, message, headers);
|
|
118
|
+
}
|
|
119
|
+
if (status >= 500) {
|
|
120
|
+
return new InternalServerError(status, error, message, headers);
|
|
121
|
+
}
|
|
122
|
+
return new APIError(status, error, message, headers);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
APIUserAbortError = class APIUserAbortError extends APIError {
|
|
126
|
+
constructor({ message } = {}) {
|
|
127
|
+
super(undefined, undefined, message || "Request was aborted.", undefined);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
APIConnectionError = class APIConnectionError extends APIError {
|
|
131
|
+
constructor({ message, cause }) {
|
|
132
|
+
super(undefined, undefined, message || "Connection error.", undefined);
|
|
133
|
+
if (cause)
|
|
134
|
+
this.cause = cause;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
APIConnectionTimeoutError = class APIConnectionTimeoutError extends APIConnectionError {
|
|
138
|
+
constructor({ message } = {}) {
|
|
139
|
+
super({ message: message ?? "Request timed out." });
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
BadRequestError = class BadRequestError extends APIError {
|
|
143
|
+
};
|
|
144
|
+
AuthenticationError = class AuthenticationError extends APIError {
|
|
145
|
+
};
|
|
146
|
+
PermissionDeniedError = class PermissionDeniedError extends APIError {
|
|
147
|
+
};
|
|
148
|
+
NotFoundError = class NotFoundError extends APIError {
|
|
149
|
+
};
|
|
150
|
+
ConflictError = class ConflictError extends APIError {
|
|
151
|
+
};
|
|
152
|
+
UnprocessableEntityError = class UnprocessableEntityError extends APIError {
|
|
153
|
+
};
|
|
154
|
+
RateLimitError = class RateLimitError extends APIError {
|
|
155
|
+
};
|
|
156
|
+
InternalServerError = class InternalServerError extends APIError {
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/utils/values.mjs
|
|
161
|
+
function maybeObj(x) {
|
|
162
|
+
if (typeof x !== "object") {
|
|
163
|
+
return {};
|
|
164
|
+
}
|
|
165
|
+
return x ?? {};
|
|
166
|
+
}
|
|
167
|
+
function isEmptyObj(obj) {
|
|
168
|
+
if (!obj)
|
|
169
|
+
return true;
|
|
170
|
+
for (const _k in obj)
|
|
171
|
+
return false;
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
function hasOwn(obj, key) {
|
|
175
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
176
|
+
}
|
|
177
|
+
var startsWithSchemeRegexp, isAbsoluteURL = (url) => {
|
|
178
|
+
return startsWithSchemeRegexp.test(url);
|
|
179
|
+
}, isArray = (val) => (isArray = Array.isArray, isArray(val)), isReadonlyArray, validatePositiveInteger = (name, n) => {
|
|
180
|
+
if (typeof n !== "number" || !Number.isInteger(n)) {
|
|
181
|
+
throw new AnthropicError(`${name} must be an integer`);
|
|
182
|
+
}
|
|
183
|
+
if (n < 0) {
|
|
184
|
+
throw new AnthropicError(`${name} must be a positive integer`);
|
|
185
|
+
}
|
|
186
|
+
return n;
|
|
187
|
+
}, safeJSON = (text) => {
|
|
188
|
+
try {
|
|
189
|
+
return JSON.parse(text);
|
|
190
|
+
} catch (err) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
var init_values = __esm(() => {
|
|
195
|
+
init_error();
|
|
196
|
+
startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
|
|
197
|
+
isReadonlyArray = isArray;
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/utils/sleep.mjs
|
|
201
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
202
|
+
var init_sleep = () => {};
|
|
203
|
+
|
|
204
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/version.mjs
|
|
205
|
+
var VERSION = "0.80.0";
|
|
206
|
+
var init_version = () => {};
|
|
207
|
+
|
|
208
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/detect-platform.mjs
|
|
209
|
+
function getDetectedPlatform() {
|
|
210
|
+
if (typeof Deno !== "undefined" && Deno.build != null) {
|
|
211
|
+
return "deno";
|
|
212
|
+
}
|
|
213
|
+
if (typeof EdgeRuntime !== "undefined") {
|
|
214
|
+
return "edge";
|
|
215
|
+
}
|
|
216
|
+
if (Object.prototype.toString.call(typeof globalThis.process !== "undefined" ? globalThis.process : 0) === "[object process]") {
|
|
217
|
+
return "node";
|
|
218
|
+
}
|
|
219
|
+
return "unknown";
|
|
220
|
+
}
|
|
221
|
+
function getBrowserInfo() {
|
|
222
|
+
if (typeof navigator === "undefined" || !navigator) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
const browserPatterns = [
|
|
226
|
+
{ key: "edge", pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
227
|
+
{ key: "ie", pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
228
|
+
{ key: "ie", pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
229
|
+
{ key: "chrome", pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
230
|
+
{ key: "firefox", pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
231
|
+
{ key: "safari", pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ }
|
|
232
|
+
];
|
|
233
|
+
for (const { key, pattern } of browserPatterns) {
|
|
234
|
+
const match = pattern.exec(navigator.userAgent);
|
|
235
|
+
if (match) {
|
|
236
|
+
const major = match[1] || 0;
|
|
237
|
+
const minor = match[2] || 0;
|
|
238
|
+
const patch = match[3] || 0;
|
|
239
|
+
return { browser: key, version: `${major}.${minor}.${patch}` };
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
var isRunningInBrowser = () => {
|
|
245
|
+
return typeof window !== "undefined" && typeof window.document !== "undefined" && typeof navigator !== "undefined";
|
|
246
|
+
}, getPlatformProperties = () => {
|
|
247
|
+
const detectedPlatform = getDetectedPlatform();
|
|
248
|
+
if (detectedPlatform === "deno") {
|
|
249
|
+
return {
|
|
250
|
+
"X-Stainless-Lang": "js",
|
|
251
|
+
"X-Stainless-Package-Version": VERSION,
|
|
252
|
+
"X-Stainless-OS": normalizePlatform(Deno.build.os),
|
|
253
|
+
"X-Stainless-Arch": normalizeArch(Deno.build.arch),
|
|
254
|
+
"X-Stainless-Runtime": "deno",
|
|
255
|
+
"X-Stainless-Runtime-Version": typeof Deno.version === "string" ? Deno.version : Deno.version?.deno ?? "unknown"
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
if (typeof EdgeRuntime !== "undefined") {
|
|
259
|
+
return {
|
|
260
|
+
"X-Stainless-Lang": "js",
|
|
261
|
+
"X-Stainless-Package-Version": VERSION,
|
|
262
|
+
"X-Stainless-OS": "Unknown",
|
|
263
|
+
"X-Stainless-Arch": `other:${EdgeRuntime}`,
|
|
264
|
+
"X-Stainless-Runtime": "edge",
|
|
265
|
+
"X-Stainless-Runtime-Version": globalThis.process.version
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
if (detectedPlatform === "node") {
|
|
269
|
+
return {
|
|
270
|
+
"X-Stainless-Lang": "js",
|
|
271
|
+
"X-Stainless-Package-Version": VERSION,
|
|
272
|
+
"X-Stainless-OS": normalizePlatform(globalThis.process.platform ?? "unknown"),
|
|
273
|
+
"X-Stainless-Arch": normalizeArch(globalThis.process.arch ?? "unknown"),
|
|
274
|
+
"X-Stainless-Runtime": "node",
|
|
275
|
+
"X-Stainless-Runtime-Version": globalThis.process.version ?? "unknown"
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
const browserInfo = getBrowserInfo();
|
|
279
|
+
if (browserInfo) {
|
|
280
|
+
return {
|
|
281
|
+
"X-Stainless-Lang": "js",
|
|
282
|
+
"X-Stainless-Package-Version": VERSION,
|
|
283
|
+
"X-Stainless-OS": "Unknown",
|
|
284
|
+
"X-Stainless-Arch": "unknown",
|
|
285
|
+
"X-Stainless-Runtime": `browser:${browserInfo.browser}`,
|
|
286
|
+
"X-Stainless-Runtime-Version": browserInfo.version
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
"X-Stainless-Lang": "js",
|
|
291
|
+
"X-Stainless-Package-Version": VERSION,
|
|
292
|
+
"X-Stainless-OS": "Unknown",
|
|
293
|
+
"X-Stainless-Arch": "unknown",
|
|
294
|
+
"X-Stainless-Runtime": "unknown",
|
|
295
|
+
"X-Stainless-Runtime-Version": "unknown"
|
|
296
|
+
};
|
|
297
|
+
}, normalizeArch = (arch) => {
|
|
298
|
+
if (arch === "x32")
|
|
299
|
+
return "x32";
|
|
300
|
+
if (arch === "x86_64" || arch === "x64")
|
|
301
|
+
return "x64";
|
|
302
|
+
if (arch === "arm")
|
|
303
|
+
return "arm";
|
|
304
|
+
if (arch === "aarch64" || arch === "arm64")
|
|
305
|
+
return "arm64";
|
|
306
|
+
if (arch)
|
|
307
|
+
return `other:${arch}`;
|
|
308
|
+
return "unknown";
|
|
309
|
+
}, normalizePlatform = (platform) => {
|
|
310
|
+
platform = platform.toLowerCase();
|
|
311
|
+
if (platform.includes("ios"))
|
|
312
|
+
return "iOS";
|
|
313
|
+
if (platform === "android")
|
|
314
|
+
return "Android";
|
|
315
|
+
if (platform === "darwin")
|
|
316
|
+
return "MacOS";
|
|
317
|
+
if (platform === "win32")
|
|
318
|
+
return "Windows";
|
|
319
|
+
if (platform === "freebsd")
|
|
320
|
+
return "FreeBSD";
|
|
321
|
+
if (platform === "openbsd")
|
|
322
|
+
return "OpenBSD";
|
|
323
|
+
if (platform === "linux")
|
|
324
|
+
return "Linux";
|
|
325
|
+
if (platform)
|
|
326
|
+
return `Other:${platform}`;
|
|
327
|
+
return "Unknown";
|
|
328
|
+
}, _platformHeaders, getPlatformHeaders = () => {
|
|
329
|
+
return _platformHeaders ?? (_platformHeaders = getPlatformProperties());
|
|
330
|
+
};
|
|
331
|
+
var init_detect_platform = __esm(() => {
|
|
332
|
+
init_version();
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/shims.mjs
|
|
336
|
+
function getDefaultFetch() {
|
|
337
|
+
if (typeof fetch !== "undefined") {
|
|
338
|
+
return fetch;
|
|
339
|
+
}
|
|
340
|
+
throw new Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new Anthropic({ fetch })` or polyfill the global, `globalThis.fetch = fetch`");
|
|
341
|
+
}
|
|
342
|
+
function makeReadableStream(...args) {
|
|
343
|
+
const ReadableStream = globalThis.ReadableStream;
|
|
344
|
+
if (typeof ReadableStream === "undefined") {
|
|
345
|
+
throw new Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");
|
|
346
|
+
}
|
|
347
|
+
return new ReadableStream(...args);
|
|
348
|
+
}
|
|
349
|
+
function ReadableStreamFrom(iterable) {
|
|
350
|
+
let iter = Symbol.asyncIterator in iterable ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();
|
|
351
|
+
return makeReadableStream({
|
|
352
|
+
start() {},
|
|
353
|
+
async pull(controller) {
|
|
354
|
+
const { done, value } = await iter.next();
|
|
355
|
+
if (done) {
|
|
356
|
+
controller.close();
|
|
357
|
+
} else {
|
|
358
|
+
controller.enqueue(value);
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
async cancel() {
|
|
362
|
+
await iter.return?.();
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
function ReadableStreamToAsyncIterable(stream) {
|
|
367
|
+
if (stream[Symbol.asyncIterator])
|
|
368
|
+
return stream;
|
|
369
|
+
const reader = stream.getReader();
|
|
370
|
+
return {
|
|
371
|
+
async next() {
|
|
372
|
+
try {
|
|
373
|
+
const result = await reader.read();
|
|
374
|
+
if (result?.done)
|
|
375
|
+
reader.releaseLock();
|
|
376
|
+
return result;
|
|
377
|
+
} catch (e) {
|
|
378
|
+
reader.releaseLock();
|
|
379
|
+
throw e;
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
async return() {
|
|
383
|
+
const cancelPromise = reader.cancel();
|
|
384
|
+
reader.releaseLock();
|
|
385
|
+
await cancelPromise;
|
|
386
|
+
return { done: true, value: undefined };
|
|
387
|
+
},
|
|
388
|
+
[Symbol.asyncIterator]() {
|
|
389
|
+
return this;
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
async function CancelReadableStream(stream) {
|
|
394
|
+
if (stream === null || typeof stream !== "object")
|
|
395
|
+
return;
|
|
396
|
+
if (stream[Symbol.asyncIterator]) {
|
|
397
|
+
await stream[Symbol.asyncIterator]().return?.();
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const reader = stream.getReader();
|
|
401
|
+
const cancelPromise = reader.cancel();
|
|
402
|
+
reader.releaseLock();
|
|
403
|
+
await cancelPromise;
|
|
404
|
+
}
|
|
405
|
+
var init_shims = () => {};
|
|
406
|
+
|
|
407
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/request-options.mjs
|
|
408
|
+
var FallbackEncoder = ({ headers, body }) => {
|
|
409
|
+
return {
|
|
410
|
+
bodyHeaders: {
|
|
411
|
+
"content-type": "application/json"
|
|
412
|
+
},
|
|
413
|
+
body: JSON.stringify(body)
|
|
414
|
+
};
|
|
415
|
+
};
|
|
416
|
+
var init_request_options = () => {};
|
|
417
|
+
|
|
418
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/utils/query.mjs
|
|
419
|
+
function stringifyQuery(query) {
|
|
420
|
+
return Object.entries(query).filter(([_, value]) => typeof value !== "undefined").map(([key, value]) => {
|
|
421
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
422
|
+
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
423
|
+
}
|
|
424
|
+
if (value === null) {
|
|
425
|
+
return `${encodeURIComponent(key)}=`;
|
|
426
|
+
}
|
|
427
|
+
throw new AnthropicError(`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`);
|
|
428
|
+
}).join("&");
|
|
429
|
+
}
|
|
430
|
+
var init_query = __esm(() => {
|
|
431
|
+
init_error();
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/utils/bytes.mjs
|
|
435
|
+
function concatBytes(buffers) {
|
|
436
|
+
let length = 0;
|
|
437
|
+
for (const buffer of buffers) {
|
|
438
|
+
length += buffer.length;
|
|
439
|
+
}
|
|
440
|
+
const output = new Uint8Array(length);
|
|
441
|
+
let index = 0;
|
|
442
|
+
for (const buffer of buffers) {
|
|
443
|
+
output.set(buffer, index);
|
|
444
|
+
index += buffer.length;
|
|
445
|
+
}
|
|
446
|
+
return output;
|
|
447
|
+
}
|
|
448
|
+
function encodeUTF8(str) {
|
|
449
|
+
let encoder;
|
|
450
|
+
return (encodeUTF8_ ?? (encoder = new globalThis.TextEncoder, encodeUTF8_ = encoder.encode.bind(encoder)))(str);
|
|
451
|
+
}
|
|
452
|
+
function decodeUTF8(bytes) {
|
|
453
|
+
let decoder;
|
|
454
|
+
return (decodeUTF8_ ?? (decoder = new globalThis.TextDecoder, decodeUTF8_ = decoder.decode.bind(decoder)))(bytes);
|
|
455
|
+
}
|
|
456
|
+
var encodeUTF8_, decodeUTF8_;
|
|
457
|
+
var init_bytes = () => {};
|
|
458
|
+
|
|
459
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/decoders/line.mjs
|
|
460
|
+
class LineDecoder {
|
|
461
|
+
constructor() {
|
|
462
|
+
_LineDecoder_buffer.set(this, undefined);
|
|
463
|
+
_LineDecoder_carriageReturnIndex.set(this, undefined);
|
|
464
|
+
__classPrivateFieldSet(this, _LineDecoder_buffer, new Uint8Array, "f");
|
|
465
|
+
__classPrivateFieldSet(this, _LineDecoder_carriageReturnIndex, null, "f");
|
|
466
|
+
}
|
|
467
|
+
decode(chunk) {
|
|
468
|
+
if (chunk == null) {
|
|
469
|
+
return [];
|
|
470
|
+
}
|
|
471
|
+
const binaryChunk = chunk instanceof ArrayBuffer ? new Uint8Array(chunk) : typeof chunk === "string" ? encodeUTF8(chunk) : chunk;
|
|
472
|
+
__classPrivateFieldSet(this, _LineDecoder_buffer, concatBytes([__classPrivateFieldGet(this, _LineDecoder_buffer, "f"), binaryChunk]), "f");
|
|
473
|
+
const lines = [];
|
|
474
|
+
let patternIndex;
|
|
475
|
+
while ((patternIndex = findNewlineIndex(__classPrivateFieldGet(this, _LineDecoder_buffer, "f"), __classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f"))) != null) {
|
|
476
|
+
if (patternIndex.carriage && __classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f") == null) {
|
|
477
|
+
__classPrivateFieldSet(this, _LineDecoder_carriageReturnIndex, patternIndex.index, "f");
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
if (__classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f") != null && (patternIndex.index !== __classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f") + 1 || patternIndex.carriage)) {
|
|
481
|
+
lines.push(decodeUTF8(__classPrivateFieldGet(this, _LineDecoder_buffer, "f").subarray(0, __classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f") - 1)));
|
|
482
|
+
__classPrivateFieldSet(this, _LineDecoder_buffer, __classPrivateFieldGet(this, _LineDecoder_buffer, "f").subarray(__classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f")), "f");
|
|
483
|
+
__classPrivateFieldSet(this, _LineDecoder_carriageReturnIndex, null, "f");
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
const endIndex = __classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f") !== null ? patternIndex.preceding - 1 : patternIndex.preceding;
|
|
487
|
+
const line = decodeUTF8(__classPrivateFieldGet(this, _LineDecoder_buffer, "f").subarray(0, endIndex));
|
|
488
|
+
lines.push(line);
|
|
489
|
+
__classPrivateFieldSet(this, _LineDecoder_buffer, __classPrivateFieldGet(this, _LineDecoder_buffer, "f").subarray(patternIndex.index), "f");
|
|
490
|
+
__classPrivateFieldSet(this, _LineDecoder_carriageReturnIndex, null, "f");
|
|
491
|
+
}
|
|
492
|
+
return lines;
|
|
493
|
+
}
|
|
494
|
+
flush() {
|
|
495
|
+
if (!__classPrivateFieldGet(this, _LineDecoder_buffer, "f").length) {
|
|
496
|
+
return [];
|
|
497
|
+
}
|
|
498
|
+
return this.decode(`
|
|
499
|
+
`);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
function findNewlineIndex(buffer, startIndex) {
|
|
503
|
+
const newline = 10;
|
|
504
|
+
const carriage = 13;
|
|
505
|
+
for (let i = startIndex ?? 0;i < buffer.length; i++) {
|
|
506
|
+
if (buffer[i] === newline) {
|
|
507
|
+
return { preceding: i, index: i + 1, carriage: false };
|
|
508
|
+
}
|
|
509
|
+
if (buffer[i] === carriage) {
|
|
510
|
+
return { preceding: i, index: i + 1, carriage: true };
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
return null;
|
|
514
|
+
}
|
|
515
|
+
function findDoubleNewlineIndex(buffer) {
|
|
516
|
+
const newline = 10;
|
|
517
|
+
const carriage = 13;
|
|
518
|
+
for (let i = 0;i < buffer.length - 1; i++) {
|
|
519
|
+
if (buffer[i] === newline && buffer[i + 1] === newline) {
|
|
520
|
+
return i + 2;
|
|
521
|
+
}
|
|
522
|
+
if (buffer[i] === carriage && buffer[i + 1] === carriage) {
|
|
523
|
+
return i + 2;
|
|
524
|
+
}
|
|
525
|
+
if (buffer[i] === carriage && buffer[i + 1] === newline && i + 3 < buffer.length && buffer[i + 2] === carriage && buffer[i + 3] === newline) {
|
|
526
|
+
return i + 4;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return -1;
|
|
530
|
+
}
|
|
531
|
+
var _LineDecoder_buffer, _LineDecoder_carriageReturnIndex;
|
|
532
|
+
var init_line = __esm(() => {
|
|
533
|
+
init_tslib();
|
|
534
|
+
init_bytes();
|
|
535
|
+
_LineDecoder_buffer = new WeakMap, _LineDecoder_carriageReturnIndex = new WeakMap;
|
|
536
|
+
LineDecoder.NEWLINE_CHARS = new Set([`
|
|
537
|
+
`, "\r"]);
|
|
538
|
+
LineDecoder.NEWLINE_REGEXP = /\r\n|[\n\r]/g;
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/utils/log.mjs
|
|
542
|
+
function noop() {}
|
|
543
|
+
function makeLogFn(fnLevel, logger, logLevel) {
|
|
544
|
+
if (!logger || levelNumbers[fnLevel] > levelNumbers[logLevel]) {
|
|
545
|
+
return noop;
|
|
546
|
+
} else {
|
|
547
|
+
return logger[fnLevel].bind(logger);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
function loggerFor(client) {
|
|
551
|
+
const logger = client.logger;
|
|
552
|
+
const logLevel = client.logLevel ?? "off";
|
|
553
|
+
if (!logger) {
|
|
554
|
+
return noopLogger;
|
|
555
|
+
}
|
|
556
|
+
const cachedLogger = cachedLoggers.get(logger);
|
|
557
|
+
if (cachedLogger && cachedLogger[0] === logLevel) {
|
|
558
|
+
return cachedLogger[1];
|
|
559
|
+
}
|
|
560
|
+
const levelLogger = {
|
|
561
|
+
error: makeLogFn("error", logger, logLevel),
|
|
562
|
+
warn: makeLogFn("warn", logger, logLevel),
|
|
563
|
+
info: makeLogFn("info", logger, logLevel),
|
|
564
|
+
debug: makeLogFn("debug", logger, logLevel)
|
|
565
|
+
};
|
|
566
|
+
cachedLoggers.set(logger, [logLevel, levelLogger]);
|
|
567
|
+
return levelLogger;
|
|
568
|
+
}
|
|
569
|
+
var levelNumbers, parseLogLevel = (maybeLevel, sourceName, client) => {
|
|
570
|
+
if (!maybeLevel) {
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
if (hasOwn(levelNumbers, maybeLevel)) {
|
|
574
|
+
return maybeLevel;
|
|
575
|
+
}
|
|
576
|
+
loggerFor(client).warn(`${sourceName} was set to ${JSON.stringify(maybeLevel)}, expected one of ${JSON.stringify(Object.keys(levelNumbers))}`);
|
|
577
|
+
return;
|
|
578
|
+
}, noopLogger, cachedLoggers, formatRequestDetails = (details) => {
|
|
579
|
+
if (details.options) {
|
|
580
|
+
details.options = { ...details.options };
|
|
581
|
+
delete details.options["headers"];
|
|
582
|
+
}
|
|
583
|
+
if (details.headers) {
|
|
584
|
+
details.headers = Object.fromEntries((details.headers instanceof Headers ? [...details.headers] : Object.entries(details.headers)).map(([name, value]) => [
|
|
585
|
+
name,
|
|
586
|
+
name.toLowerCase() === "x-api-key" || name.toLowerCase() === "authorization" || name.toLowerCase() === "cookie" || name.toLowerCase() === "set-cookie" ? "***" : value
|
|
587
|
+
]));
|
|
588
|
+
}
|
|
589
|
+
if ("retryOfRequestLogID" in details) {
|
|
590
|
+
if (details.retryOfRequestLogID) {
|
|
591
|
+
details.retryOf = details.retryOfRequestLogID;
|
|
592
|
+
}
|
|
593
|
+
delete details.retryOfRequestLogID;
|
|
594
|
+
}
|
|
595
|
+
return details;
|
|
596
|
+
};
|
|
597
|
+
var init_log = __esm(() => {
|
|
598
|
+
init_values();
|
|
599
|
+
levelNumbers = {
|
|
600
|
+
off: 0,
|
|
601
|
+
error: 200,
|
|
602
|
+
warn: 300,
|
|
603
|
+
info: 400,
|
|
604
|
+
debug: 500
|
|
605
|
+
};
|
|
606
|
+
noopLogger = {
|
|
607
|
+
error: noop,
|
|
608
|
+
warn: noop,
|
|
609
|
+
info: noop,
|
|
610
|
+
debug: noop
|
|
611
|
+
};
|
|
612
|
+
cachedLoggers = /* @__PURE__ */ new WeakMap;
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/core/streaming.mjs
|
|
616
|
+
async function* _iterSSEMessages(response, controller) {
|
|
617
|
+
if (!response.body) {
|
|
618
|
+
controller.abort();
|
|
619
|
+
if (typeof globalThis.navigator !== "undefined" && globalThis.navigator.product === "ReactNative") {
|
|
620
|
+
throw new AnthropicError(`The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api`);
|
|
621
|
+
}
|
|
622
|
+
throw new AnthropicError(`Attempted to iterate over a response with no body`);
|
|
623
|
+
}
|
|
624
|
+
const sseDecoder = new SSEDecoder;
|
|
625
|
+
const lineDecoder = new LineDecoder;
|
|
626
|
+
const iter = ReadableStreamToAsyncIterable(response.body);
|
|
627
|
+
for await (const sseChunk of iterSSEChunks(iter)) {
|
|
628
|
+
for (const line of lineDecoder.decode(sseChunk)) {
|
|
629
|
+
const sse = sseDecoder.decode(line);
|
|
630
|
+
if (sse)
|
|
631
|
+
yield sse;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
for (const line of lineDecoder.flush()) {
|
|
635
|
+
const sse = sseDecoder.decode(line);
|
|
636
|
+
if (sse)
|
|
637
|
+
yield sse;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
async function* iterSSEChunks(iterator) {
|
|
641
|
+
let data = new Uint8Array;
|
|
642
|
+
for await (const chunk of iterator) {
|
|
643
|
+
if (chunk == null) {
|
|
644
|
+
continue;
|
|
645
|
+
}
|
|
646
|
+
const binaryChunk = chunk instanceof ArrayBuffer ? new Uint8Array(chunk) : typeof chunk === "string" ? encodeUTF8(chunk) : chunk;
|
|
647
|
+
let newData = new Uint8Array(data.length + binaryChunk.length);
|
|
648
|
+
newData.set(data);
|
|
649
|
+
newData.set(binaryChunk, data.length);
|
|
650
|
+
data = newData;
|
|
651
|
+
let patternIndex;
|
|
652
|
+
while ((patternIndex = findDoubleNewlineIndex(data)) !== -1) {
|
|
653
|
+
yield data.slice(0, patternIndex);
|
|
654
|
+
data = data.slice(patternIndex);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
if (data.length > 0) {
|
|
658
|
+
yield data;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
class SSEDecoder {
|
|
663
|
+
constructor() {
|
|
664
|
+
this.event = null;
|
|
665
|
+
this.data = [];
|
|
666
|
+
this.chunks = [];
|
|
667
|
+
}
|
|
668
|
+
decode(line) {
|
|
669
|
+
if (line.endsWith("\r")) {
|
|
670
|
+
line = line.substring(0, line.length - 1);
|
|
671
|
+
}
|
|
672
|
+
if (!line) {
|
|
673
|
+
if (!this.event && !this.data.length)
|
|
674
|
+
return null;
|
|
675
|
+
const sse = {
|
|
676
|
+
event: this.event,
|
|
677
|
+
data: this.data.join(`
|
|
678
|
+
`),
|
|
679
|
+
raw: this.chunks
|
|
680
|
+
};
|
|
681
|
+
this.event = null;
|
|
682
|
+
this.data = [];
|
|
683
|
+
this.chunks = [];
|
|
684
|
+
return sse;
|
|
685
|
+
}
|
|
686
|
+
this.chunks.push(line);
|
|
687
|
+
if (line.startsWith(":")) {
|
|
688
|
+
return null;
|
|
689
|
+
}
|
|
690
|
+
let [fieldname, _, value] = partition(line, ":");
|
|
691
|
+
if (value.startsWith(" ")) {
|
|
692
|
+
value = value.substring(1);
|
|
693
|
+
}
|
|
694
|
+
if (fieldname === "event") {
|
|
695
|
+
this.event = value;
|
|
696
|
+
} else if (fieldname === "data") {
|
|
697
|
+
this.data.push(value);
|
|
698
|
+
}
|
|
699
|
+
return null;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
function partition(str, delimiter) {
|
|
703
|
+
const index = str.indexOf(delimiter);
|
|
704
|
+
if (index !== -1) {
|
|
705
|
+
return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];
|
|
706
|
+
}
|
|
707
|
+
return [str, "", ""];
|
|
708
|
+
}
|
|
709
|
+
var _Stream_client, Stream;
|
|
710
|
+
var init_streaming = __esm(() => {
|
|
711
|
+
init_tslib();
|
|
712
|
+
init_error();
|
|
713
|
+
init_shims();
|
|
714
|
+
init_line();
|
|
715
|
+
init_shims();
|
|
716
|
+
init_errors();
|
|
717
|
+
init_values();
|
|
718
|
+
init_bytes();
|
|
719
|
+
init_log();
|
|
720
|
+
init_error();
|
|
721
|
+
Stream = class Stream {
|
|
722
|
+
constructor(iterator, controller, client) {
|
|
723
|
+
this.iterator = iterator;
|
|
724
|
+
_Stream_client.set(this, undefined);
|
|
725
|
+
this.controller = controller;
|
|
726
|
+
__classPrivateFieldSet(this, _Stream_client, client, "f");
|
|
727
|
+
}
|
|
728
|
+
static fromSSEResponse(response, controller, client) {
|
|
729
|
+
let consumed = false;
|
|
730
|
+
const logger = client ? loggerFor(client) : console;
|
|
731
|
+
async function* iterator() {
|
|
732
|
+
if (consumed) {
|
|
733
|
+
throw new AnthropicError("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");
|
|
734
|
+
}
|
|
735
|
+
consumed = true;
|
|
736
|
+
let done = false;
|
|
737
|
+
try {
|
|
738
|
+
for await (const sse of _iterSSEMessages(response, controller)) {
|
|
739
|
+
if (sse.event === "completion") {
|
|
740
|
+
try {
|
|
741
|
+
yield JSON.parse(sse.data);
|
|
742
|
+
} catch (e) {
|
|
743
|
+
logger.error(`Could not parse message into JSON:`, sse.data);
|
|
744
|
+
logger.error(`From chunk:`, sse.raw);
|
|
745
|
+
throw e;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
if (sse.event === "message_start" || sse.event === "message_delta" || sse.event === "message_stop" || sse.event === "content_block_start" || sse.event === "content_block_delta" || sse.event === "content_block_stop") {
|
|
749
|
+
try {
|
|
750
|
+
yield JSON.parse(sse.data);
|
|
751
|
+
} catch (e) {
|
|
752
|
+
logger.error(`Could not parse message into JSON:`, sse.data);
|
|
753
|
+
logger.error(`From chunk:`, sse.raw);
|
|
754
|
+
throw e;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
if (sse.event === "ping") {
|
|
758
|
+
continue;
|
|
759
|
+
}
|
|
760
|
+
if (sse.event === "error") {
|
|
761
|
+
throw new APIError(undefined, safeJSON(sse.data) ?? sse.data, undefined, response.headers);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
done = true;
|
|
765
|
+
} catch (e) {
|
|
766
|
+
if (isAbortError(e))
|
|
767
|
+
return;
|
|
768
|
+
throw e;
|
|
769
|
+
} finally {
|
|
770
|
+
if (!done)
|
|
771
|
+
controller.abort();
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
return new Stream(iterator, controller, client);
|
|
775
|
+
}
|
|
776
|
+
static fromReadableStream(readableStream, controller, client) {
|
|
777
|
+
let consumed = false;
|
|
778
|
+
async function* iterLines() {
|
|
779
|
+
const lineDecoder = new LineDecoder;
|
|
780
|
+
const iter = ReadableStreamToAsyncIterable(readableStream);
|
|
781
|
+
for await (const chunk of iter) {
|
|
782
|
+
for (const line of lineDecoder.decode(chunk)) {
|
|
783
|
+
yield line;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
for (const line of lineDecoder.flush()) {
|
|
787
|
+
yield line;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
async function* iterator() {
|
|
791
|
+
if (consumed) {
|
|
792
|
+
throw new AnthropicError("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");
|
|
793
|
+
}
|
|
794
|
+
consumed = true;
|
|
795
|
+
let done = false;
|
|
796
|
+
try {
|
|
797
|
+
for await (const line of iterLines()) {
|
|
798
|
+
if (done)
|
|
799
|
+
continue;
|
|
800
|
+
if (line)
|
|
801
|
+
yield JSON.parse(line);
|
|
802
|
+
}
|
|
803
|
+
done = true;
|
|
804
|
+
} catch (e) {
|
|
805
|
+
if (isAbortError(e))
|
|
806
|
+
return;
|
|
807
|
+
throw e;
|
|
808
|
+
} finally {
|
|
809
|
+
if (!done)
|
|
810
|
+
controller.abort();
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
return new Stream(iterator, controller, client);
|
|
814
|
+
}
|
|
815
|
+
[(_Stream_client = new WeakMap, Symbol.asyncIterator)]() {
|
|
816
|
+
return this.iterator();
|
|
817
|
+
}
|
|
818
|
+
tee() {
|
|
819
|
+
const left = [];
|
|
820
|
+
const right = [];
|
|
821
|
+
const iterator = this.iterator();
|
|
822
|
+
const teeIterator = (queue) => {
|
|
823
|
+
return {
|
|
824
|
+
next: () => {
|
|
825
|
+
if (queue.length === 0) {
|
|
826
|
+
const result = iterator.next();
|
|
827
|
+
left.push(result);
|
|
828
|
+
right.push(result);
|
|
829
|
+
}
|
|
830
|
+
return queue.shift();
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
};
|
|
834
|
+
return [
|
|
835
|
+
new Stream(() => teeIterator(left), this.controller, __classPrivateFieldGet(this, _Stream_client, "f")),
|
|
836
|
+
new Stream(() => teeIterator(right), this.controller, __classPrivateFieldGet(this, _Stream_client, "f"))
|
|
837
|
+
];
|
|
838
|
+
}
|
|
839
|
+
toReadableStream() {
|
|
840
|
+
const self = this;
|
|
841
|
+
let iter;
|
|
842
|
+
return makeReadableStream({
|
|
843
|
+
async start() {
|
|
844
|
+
iter = self[Symbol.asyncIterator]();
|
|
845
|
+
},
|
|
846
|
+
async pull(ctrl) {
|
|
847
|
+
try {
|
|
848
|
+
const { value, done } = await iter.next();
|
|
849
|
+
if (done)
|
|
850
|
+
return ctrl.close();
|
|
851
|
+
const bytes = encodeUTF8(JSON.stringify(value) + `
|
|
852
|
+
`);
|
|
853
|
+
ctrl.enqueue(bytes);
|
|
854
|
+
} catch (err) {
|
|
855
|
+
ctrl.error(err);
|
|
856
|
+
}
|
|
857
|
+
},
|
|
858
|
+
async cancel() {
|
|
859
|
+
await iter.return?.();
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
});
|
|
865
|
+
|
|
866
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/parse.mjs
|
|
867
|
+
async function defaultParseResponse(client, props) {
|
|
868
|
+
const { response, requestLogID, retryOfRequestLogID, startTime } = props;
|
|
869
|
+
const body = await (async () => {
|
|
870
|
+
if (props.options.stream) {
|
|
871
|
+
loggerFor(client).debug("response", response.status, response.url, response.headers, response.body);
|
|
872
|
+
if (props.options.__streamClass) {
|
|
873
|
+
return props.options.__streamClass.fromSSEResponse(response, props.controller);
|
|
874
|
+
}
|
|
875
|
+
return Stream.fromSSEResponse(response, props.controller);
|
|
876
|
+
}
|
|
877
|
+
if (response.status === 204) {
|
|
878
|
+
return null;
|
|
879
|
+
}
|
|
880
|
+
if (props.options.__binaryResponse) {
|
|
881
|
+
return response;
|
|
882
|
+
}
|
|
883
|
+
const contentType = response.headers.get("content-type");
|
|
884
|
+
const mediaType = contentType?.split(";")[0]?.trim();
|
|
885
|
+
const isJSON = mediaType?.includes("application/json") || mediaType?.endsWith("+json");
|
|
886
|
+
if (isJSON) {
|
|
887
|
+
const contentLength = response.headers.get("content-length");
|
|
888
|
+
if (contentLength === "0") {
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
const json = await response.json();
|
|
892
|
+
return addRequestID(json, response);
|
|
893
|
+
}
|
|
894
|
+
const text = await response.text();
|
|
895
|
+
return text;
|
|
896
|
+
})();
|
|
897
|
+
loggerFor(client).debug(`[${requestLogID}] response parsed`, formatRequestDetails({
|
|
898
|
+
retryOfRequestLogID,
|
|
899
|
+
url: response.url,
|
|
900
|
+
status: response.status,
|
|
901
|
+
body,
|
|
902
|
+
durationMs: Date.now() - startTime
|
|
903
|
+
}));
|
|
904
|
+
return body;
|
|
905
|
+
}
|
|
906
|
+
function addRequestID(value, response) {
|
|
907
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
908
|
+
return value;
|
|
909
|
+
}
|
|
910
|
+
return Object.defineProperty(value, "_request_id", {
|
|
911
|
+
value: response.headers.get("request-id"),
|
|
912
|
+
enumerable: false
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
var init_parse = __esm(() => {
|
|
916
|
+
init_streaming();
|
|
917
|
+
init_log();
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/core/api-promise.mjs
|
|
921
|
+
var _APIPromise_client, APIPromise;
|
|
922
|
+
var init_api_promise = __esm(() => {
|
|
923
|
+
init_tslib();
|
|
924
|
+
init_parse();
|
|
925
|
+
APIPromise = class APIPromise extends Promise {
|
|
926
|
+
constructor(client, responsePromise, parseResponse = defaultParseResponse) {
|
|
927
|
+
super((resolve) => {
|
|
928
|
+
resolve(null);
|
|
929
|
+
});
|
|
930
|
+
this.responsePromise = responsePromise;
|
|
931
|
+
this.parseResponse = parseResponse;
|
|
932
|
+
_APIPromise_client.set(this, undefined);
|
|
933
|
+
__classPrivateFieldSet(this, _APIPromise_client, client, "f");
|
|
934
|
+
}
|
|
935
|
+
_thenUnwrap(transform) {
|
|
936
|
+
return new APIPromise(__classPrivateFieldGet(this, _APIPromise_client, "f"), this.responsePromise, async (client, props) => addRequestID(transform(await this.parseResponse(client, props), props), props.response));
|
|
937
|
+
}
|
|
938
|
+
asResponse() {
|
|
939
|
+
return this.responsePromise.then((p) => p.response);
|
|
940
|
+
}
|
|
941
|
+
async withResponse() {
|
|
942
|
+
const [data, response] = await Promise.all([this.parse(), this.asResponse()]);
|
|
943
|
+
return { data, response, request_id: response.headers.get("request-id") };
|
|
944
|
+
}
|
|
945
|
+
parse() {
|
|
946
|
+
if (!this.parsedPromise) {
|
|
947
|
+
this.parsedPromise = this.responsePromise.then((data) => this.parseResponse(__classPrivateFieldGet(this, _APIPromise_client, "f"), data));
|
|
948
|
+
}
|
|
949
|
+
return this.parsedPromise;
|
|
950
|
+
}
|
|
951
|
+
then(onfulfilled, onrejected) {
|
|
952
|
+
return this.parse().then(onfulfilled, onrejected);
|
|
953
|
+
}
|
|
954
|
+
catch(onrejected) {
|
|
955
|
+
return this.parse().catch(onrejected);
|
|
956
|
+
}
|
|
957
|
+
finally(onfinally) {
|
|
958
|
+
return this.parse().finally(onfinally);
|
|
959
|
+
}
|
|
960
|
+
};
|
|
961
|
+
_APIPromise_client = new WeakMap;
|
|
962
|
+
});
|
|
963
|
+
|
|
964
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/core/pagination.mjs
|
|
965
|
+
var _AbstractPage_client, AbstractPage, PagePromise, Page, PageCursor;
|
|
966
|
+
var init_pagination = __esm(() => {
|
|
967
|
+
init_tslib();
|
|
968
|
+
init_error();
|
|
969
|
+
init_parse();
|
|
970
|
+
init_api_promise();
|
|
971
|
+
init_values();
|
|
972
|
+
AbstractPage = class AbstractPage {
|
|
973
|
+
constructor(client, response, body, options) {
|
|
974
|
+
_AbstractPage_client.set(this, undefined);
|
|
975
|
+
__classPrivateFieldSet(this, _AbstractPage_client, client, "f");
|
|
976
|
+
this.options = options;
|
|
977
|
+
this.response = response;
|
|
978
|
+
this.body = body;
|
|
979
|
+
}
|
|
980
|
+
hasNextPage() {
|
|
981
|
+
const items = this.getPaginatedItems();
|
|
982
|
+
if (!items.length)
|
|
983
|
+
return false;
|
|
984
|
+
return this.nextPageRequestOptions() != null;
|
|
985
|
+
}
|
|
986
|
+
async getNextPage() {
|
|
987
|
+
const nextOptions = this.nextPageRequestOptions();
|
|
988
|
+
if (!nextOptions) {
|
|
989
|
+
throw new AnthropicError("No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.");
|
|
990
|
+
}
|
|
991
|
+
return await __classPrivateFieldGet(this, _AbstractPage_client, "f").requestAPIList(this.constructor, nextOptions);
|
|
992
|
+
}
|
|
993
|
+
async* iterPages() {
|
|
994
|
+
let page = this;
|
|
995
|
+
yield page;
|
|
996
|
+
while (page.hasNextPage()) {
|
|
997
|
+
page = await page.getNextPage();
|
|
998
|
+
yield page;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
async* [(_AbstractPage_client = new WeakMap, Symbol.asyncIterator)]() {
|
|
1002
|
+
for await (const page of this.iterPages()) {
|
|
1003
|
+
for (const item of page.getPaginatedItems()) {
|
|
1004
|
+
yield item;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
};
|
|
1009
|
+
PagePromise = class PagePromise extends APIPromise {
|
|
1010
|
+
constructor(client, request, Page) {
|
|
1011
|
+
super(client, request, async (client2, props) => new Page(client2, props.response, await defaultParseResponse(client2, props), props.options));
|
|
1012
|
+
}
|
|
1013
|
+
async* [Symbol.asyncIterator]() {
|
|
1014
|
+
const page = await this;
|
|
1015
|
+
for await (const item of page) {
|
|
1016
|
+
yield item;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
Page = class Page extends AbstractPage {
|
|
1021
|
+
constructor(client, response, body, options) {
|
|
1022
|
+
super(client, response, body, options);
|
|
1023
|
+
this.data = body.data || [];
|
|
1024
|
+
this.has_more = body.has_more || false;
|
|
1025
|
+
this.first_id = body.first_id || null;
|
|
1026
|
+
this.last_id = body.last_id || null;
|
|
1027
|
+
}
|
|
1028
|
+
getPaginatedItems() {
|
|
1029
|
+
return this.data ?? [];
|
|
1030
|
+
}
|
|
1031
|
+
hasNextPage() {
|
|
1032
|
+
if (this.has_more === false) {
|
|
1033
|
+
return false;
|
|
1034
|
+
}
|
|
1035
|
+
return super.hasNextPage();
|
|
1036
|
+
}
|
|
1037
|
+
nextPageRequestOptions() {
|
|
1038
|
+
if (this.options.query?.["before_id"]) {
|
|
1039
|
+
const first_id = this.first_id;
|
|
1040
|
+
if (!first_id) {
|
|
1041
|
+
return null;
|
|
1042
|
+
}
|
|
1043
|
+
return {
|
|
1044
|
+
...this.options,
|
|
1045
|
+
query: {
|
|
1046
|
+
...maybeObj(this.options.query),
|
|
1047
|
+
before_id: first_id
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
const cursor = this.last_id;
|
|
1052
|
+
if (!cursor) {
|
|
1053
|
+
return null;
|
|
1054
|
+
}
|
|
1055
|
+
return {
|
|
1056
|
+
...this.options,
|
|
1057
|
+
query: {
|
|
1058
|
+
...maybeObj(this.options.query),
|
|
1059
|
+
after_id: cursor
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
PageCursor = class PageCursor extends AbstractPage {
|
|
1065
|
+
constructor(client, response, body, options) {
|
|
1066
|
+
super(client, response, body, options);
|
|
1067
|
+
this.data = body.data || [];
|
|
1068
|
+
this.has_more = body.has_more || false;
|
|
1069
|
+
this.next_page = body.next_page || null;
|
|
1070
|
+
}
|
|
1071
|
+
getPaginatedItems() {
|
|
1072
|
+
return this.data ?? [];
|
|
1073
|
+
}
|
|
1074
|
+
hasNextPage() {
|
|
1075
|
+
if (this.has_more === false) {
|
|
1076
|
+
return false;
|
|
1077
|
+
}
|
|
1078
|
+
return super.hasNextPage();
|
|
1079
|
+
}
|
|
1080
|
+
nextPageRequestOptions() {
|
|
1081
|
+
const cursor = this.next_page;
|
|
1082
|
+
if (!cursor) {
|
|
1083
|
+
return null;
|
|
1084
|
+
}
|
|
1085
|
+
return {
|
|
1086
|
+
...this.options,
|
|
1087
|
+
query: {
|
|
1088
|
+
...maybeObj(this.options.query),
|
|
1089
|
+
page: cursor
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
1093
|
+
};
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/uploads.mjs
|
|
1097
|
+
function makeFile(fileBits, fileName, options) {
|
|
1098
|
+
checkFileSupport();
|
|
1099
|
+
return new File(fileBits, fileName ?? "unknown_file", options);
|
|
1100
|
+
}
|
|
1101
|
+
function getName(value, stripPath) {
|
|
1102
|
+
const val = typeof value === "object" && value !== null && (("name" in value) && value.name && String(value.name) || ("url" in value) && value.url && String(value.url) || ("filename" in value) && value.filename && String(value.filename) || ("path" in value) && value.path && String(value.path)) || "";
|
|
1103
|
+
return stripPath ? val.split(/[\\/]/).pop() || undefined : val;
|
|
1104
|
+
}
|
|
1105
|
+
function supportsFormData(fetchObject) {
|
|
1106
|
+
const fetch2 = typeof fetchObject === "function" ? fetchObject : fetchObject.fetch;
|
|
1107
|
+
const cached = supportsFormDataMap.get(fetch2);
|
|
1108
|
+
if (cached)
|
|
1109
|
+
return cached;
|
|
1110
|
+
const promise = (async () => {
|
|
1111
|
+
try {
|
|
1112
|
+
const FetchResponse = "Response" in fetch2 ? fetch2.Response : (await fetch2("data:,")).constructor;
|
|
1113
|
+
const data = new FormData;
|
|
1114
|
+
if (data.toString() === await new FetchResponse(data).text()) {
|
|
1115
|
+
return false;
|
|
1116
|
+
}
|
|
1117
|
+
return true;
|
|
1118
|
+
} catch {
|
|
1119
|
+
return true;
|
|
1120
|
+
}
|
|
1121
|
+
})();
|
|
1122
|
+
supportsFormDataMap.set(fetch2, promise);
|
|
1123
|
+
return promise;
|
|
1124
|
+
}
|
|
1125
|
+
var checkFileSupport = () => {
|
|
1126
|
+
if (typeof File === "undefined") {
|
|
1127
|
+
const { process } = globalThis;
|
|
1128
|
+
const isOldNode = typeof process?.versions?.node === "string" && parseInt(process.versions.node.split(".")) < 20;
|
|
1129
|
+
throw new Error("`File` is not defined as a global, which is required for file uploads." + (isOldNode ? " Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`." : ""));
|
|
1130
|
+
}
|
|
1131
|
+
}, isAsyncIterable = (value) => value != null && typeof value === "object" && typeof value[Symbol.asyncIterator] === "function", multipartFormRequestOptions = async (opts, fetch2, stripFilenames = true) => {
|
|
1132
|
+
return { ...opts, body: await createForm(opts.body, fetch2, stripFilenames) };
|
|
1133
|
+
}, supportsFormDataMap, createForm = async (body, fetch2, stripFilenames = true) => {
|
|
1134
|
+
if (!await supportsFormData(fetch2)) {
|
|
1135
|
+
throw new TypeError("The provided fetch function does not support file uploads with the current global FormData class.");
|
|
1136
|
+
}
|
|
1137
|
+
const form = new FormData;
|
|
1138
|
+
await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value, stripFilenames)));
|
|
1139
|
+
return form;
|
|
1140
|
+
}, isNamedBlob = (value) => value instanceof Blob && ("name" in value), addFormValue = async (form, key, value, stripFilenames) => {
|
|
1141
|
+
if (value === undefined)
|
|
1142
|
+
return;
|
|
1143
|
+
if (value == null) {
|
|
1144
|
+
throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`);
|
|
1145
|
+
}
|
|
1146
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
1147
|
+
form.append(key, String(value));
|
|
1148
|
+
} else if (value instanceof Response) {
|
|
1149
|
+
let options = {};
|
|
1150
|
+
const contentType = value.headers.get("Content-Type");
|
|
1151
|
+
if (contentType) {
|
|
1152
|
+
options = { type: contentType };
|
|
1153
|
+
}
|
|
1154
|
+
form.append(key, makeFile([await value.blob()], getName(value, stripFilenames), options));
|
|
1155
|
+
} else if (isAsyncIterable(value)) {
|
|
1156
|
+
form.append(key, makeFile([await new Response(ReadableStreamFrom(value)).blob()], getName(value, stripFilenames)));
|
|
1157
|
+
} else if (isNamedBlob(value)) {
|
|
1158
|
+
form.append(key, makeFile([value], getName(value, stripFilenames), { type: value.type }));
|
|
1159
|
+
} else if (Array.isArray(value)) {
|
|
1160
|
+
await Promise.all(value.map((entry) => addFormValue(form, key + "[]", entry, stripFilenames)));
|
|
1161
|
+
} else if (typeof value === "object") {
|
|
1162
|
+
await Promise.all(Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop, stripFilenames)));
|
|
1163
|
+
} else {
|
|
1164
|
+
throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
|
|
1165
|
+
}
|
|
1166
|
+
};
|
|
1167
|
+
var init_uploads = __esm(() => {
|
|
1168
|
+
init_shims();
|
|
1169
|
+
supportsFormDataMap = /* @__PURE__ */ new WeakMap;
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/to-file.mjs
|
|
1173
|
+
async function toFile(value, name, options) {
|
|
1174
|
+
checkFileSupport();
|
|
1175
|
+
value = await value;
|
|
1176
|
+
name || (name = getName(value, true));
|
|
1177
|
+
if (isFileLike(value)) {
|
|
1178
|
+
if (value instanceof File && name == null && options == null) {
|
|
1179
|
+
return value;
|
|
1180
|
+
}
|
|
1181
|
+
return makeFile([await value.arrayBuffer()], name ?? value.name, {
|
|
1182
|
+
type: value.type,
|
|
1183
|
+
lastModified: value.lastModified,
|
|
1184
|
+
...options
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
if (isResponseLike(value)) {
|
|
1188
|
+
const blob = await value.blob();
|
|
1189
|
+
name || (name = new URL(value.url).pathname.split(/[\\/]/).pop());
|
|
1190
|
+
return makeFile(await getBytes(blob), name, options);
|
|
1191
|
+
}
|
|
1192
|
+
const parts = await getBytes(value);
|
|
1193
|
+
if (!options?.type) {
|
|
1194
|
+
const type = parts.find((part) => typeof part === "object" && ("type" in part) && part.type);
|
|
1195
|
+
if (typeof type === "string") {
|
|
1196
|
+
options = { ...options, type };
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
return makeFile(parts, name, options);
|
|
1200
|
+
}
|
|
1201
|
+
async function getBytes(value) {
|
|
1202
|
+
let parts = [];
|
|
1203
|
+
if (typeof value === "string" || ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {
|
|
1204
|
+
parts.push(value);
|
|
1205
|
+
} else if (isBlobLike(value)) {
|
|
1206
|
+
parts.push(value instanceof Blob ? value : await value.arrayBuffer());
|
|
1207
|
+
} else if (isAsyncIterable(value)) {
|
|
1208
|
+
for await (const chunk of value) {
|
|
1209
|
+
parts.push(...await getBytes(chunk));
|
|
1210
|
+
}
|
|
1211
|
+
} else {
|
|
1212
|
+
const constructor = value?.constructor?.name;
|
|
1213
|
+
throw new Error(`Unexpected data type: ${typeof value}${constructor ? `; constructor: ${constructor}` : ""}${propsForError(value)}`);
|
|
1214
|
+
}
|
|
1215
|
+
return parts;
|
|
1216
|
+
}
|
|
1217
|
+
function propsForError(value) {
|
|
1218
|
+
if (typeof value !== "object" || value === null)
|
|
1219
|
+
return "";
|
|
1220
|
+
const props = Object.getOwnPropertyNames(value);
|
|
1221
|
+
return `; props: [${props.map((p) => `"${p}"`).join(", ")}]`;
|
|
1222
|
+
}
|
|
1223
|
+
var isBlobLike = (value) => value != null && typeof value === "object" && typeof value.size === "number" && typeof value.type === "string" && typeof value.text === "function" && typeof value.slice === "function" && typeof value.arrayBuffer === "function", isFileLike = (value) => value != null && typeof value === "object" && typeof value.name === "string" && typeof value.lastModified === "number" && isBlobLike(value), isResponseLike = (value) => value != null && typeof value === "object" && typeof value.url === "string" && typeof value.blob === "function";
|
|
1224
|
+
var init_to_file = __esm(() => {
|
|
1225
|
+
init_uploads();
|
|
1226
|
+
init_uploads();
|
|
1227
|
+
});
|
|
1228
|
+
|
|
1229
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/core/uploads.mjs
|
|
1230
|
+
var init_uploads2 = __esm(() => {
|
|
1231
|
+
init_to_file();
|
|
1232
|
+
});
|
|
1233
|
+
|
|
1234
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/resources/shared.mjs
|
|
1235
|
+
var init_shared = () => {};
|
|
1236
|
+
|
|
1237
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/core/resource.mjs
|
|
1238
|
+
class APIResource {
|
|
1239
|
+
constructor(client) {
|
|
1240
|
+
this._client = client;
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
var init_resource = () => {};
|
|
1244
|
+
|
|
1245
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/headers.mjs
|
|
1246
|
+
function* iterateHeaders(headers) {
|
|
1247
|
+
if (!headers)
|
|
1248
|
+
return;
|
|
1249
|
+
if (brand_privateNullableHeaders in headers) {
|
|
1250
|
+
const { values, nulls } = headers;
|
|
1251
|
+
yield* values.entries();
|
|
1252
|
+
for (const name of nulls) {
|
|
1253
|
+
yield [name, null];
|
|
1254
|
+
}
|
|
1255
|
+
return;
|
|
1256
|
+
}
|
|
1257
|
+
let shouldClear = false;
|
|
1258
|
+
let iter;
|
|
1259
|
+
if (headers instanceof Headers) {
|
|
1260
|
+
iter = headers.entries();
|
|
1261
|
+
} else if (isReadonlyArray(headers)) {
|
|
1262
|
+
iter = headers;
|
|
1263
|
+
} else {
|
|
1264
|
+
shouldClear = true;
|
|
1265
|
+
iter = Object.entries(headers ?? {});
|
|
1266
|
+
}
|
|
1267
|
+
for (let row of iter) {
|
|
1268
|
+
const name = row[0];
|
|
1269
|
+
if (typeof name !== "string")
|
|
1270
|
+
throw new TypeError("expected header name to be a string");
|
|
1271
|
+
const values = isReadonlyArray(row[1]) ? row[1] : [row[1]];
|
|
1272
|
+
let didClear = false;
|
|
1273
|
+
for (const value of values) {
|
|
1274
|
+
if (value === undefined)
|
|
1275
|
+
continue;
|
|
1276
|
+
if (shouldClear && !didClear) {
|
|
1277
|
+
didClear = true;
|
|
1278
|
+
yield [name, null];
|
|
1279
|
+
}
|
|
1280
|
+
yield [name, value];
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
var brand_privateNullableHeaders, buildHeaders = (newHeaders) => {
|
|
1285
|
+
const targetHeaders = new Headers;
|
|
1286
|
+
const nullHeaders = new Set;
|
|
1287
|
+
for (const headers of newHeaders) {
|
|
1288
|
+
const seenHeaders = new Set;
|
|
1289
|
+
for (const [name, value] of iterateHeaders(headers)) {
|
|
1290
|
+
const lowerName = name.toLowerCase();
|
|
1291
|
+
if (!seenHeaders.has(lowerName)) {
|
|
1292
|
+
targetHeaders.delete(name);
|
|
1293
|
+
seenHeaders.add(lowerName);
|
|
1294
|
+
}
|
|
1295
|
+
if (value === null) {
|
|
1296
|
+
targetHeaders.delete(name);
|
|
1297
|
+
nullHeaders.add(lowerName);
|
|
1298
|
+
} else {
|
|
1299
|
+
targetHeaders.append(name, value);
|
|
1300
|
+
nullHeaders.delete(lowerName);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
return { [brand_privateNullableHeaders]: true, values: targetHeaders, nulls: nullHeaders };
|
|
1305
|
+
};
|
|
1306
|
+
var init_headers = __esm(() => {
|
|
1307
|
+
init_values();
|
|
1308
|
+
brand_privateNullableHeaders = Symbol.for("brand.privateNullableHeaders");
|
|
1309
|
+
});
|
|
1310
|
+
|
|
1311
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/lib/stainless-helper-header.mjs
|
|
1312
|
+
function wasCreatedByStainlessHelper(value) {
|
|
1313
|
+
return typeof value === "object" && value !== null && SDK_HELPER_SYMBOL in value;
|
|
1314
|
+
}
|
|
1315
|
+
function collectStainlessHelpers(tools, messages) {
|
|
1316
|
+
const helpers = new Set;
|
|
1317
|
+
if (tools) {
|
|
1318
|
+
for (const tool of tools) {
|
|
1319
|
+
if (wasCreatedByStainlessHelper(tool)) {
|
|
1320
|
+
helpers.add(tool[SDK_HELPER_SYMBOL]);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
if (messages) {
|
|
1325
|
+
for (const message of messages) {
|
|
1326
|
+
if (wasCreatedByStainlessHelper(message)) {
|
|
1327
|
+
helpers.add(message[SDK_HELPER_SYMBOL]);
|
|
1328
|
+
}
|
|
1329
|
+
if (Array.isArray(message.content)) {
|
|
1330
|
+
for (const block of message.content) {
|
|
1331
|
+
if (wasCreatedByStainlessHelper(block)) {
|
|
1332
|
+
helpers.add(block[SDK_HELPER_SYMBOL]);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
return Array.from(helpers);
|
|
1339
|
+
}
|
|
1340
|
+
function stainlessHelperHeader(tools, messages) {
|
|
1341
|
+
const helpers = collectStainlessHelpers(tools, messages);
|
|
1342
|
+
if (helpers.length === 0)
|
|
1343
|
+
return {};
|
|
1344
|
+
return { "x-stainless-helper": helpers.join(", ") };
|
|
1345
|
+
}
|
|
1346
|
+
function stainlessHelperHeaderFromFile(file) {
|
|
1347
|
+
if (wasCreatedByStainlessHelper(file)) {
|
|
1348
|
+
return { "x-stainless-helper": file[SDK_HELPER_SYMBOL] };
|
|
1349
|
+
}
|
|
1350
|
+
return {};
|
|
1351
|
+
}
|
|
1352
|
+
var SDK_HELPER_SYMBOL;
|
|
1353
|
+
var init_stainless_helper_header = __esm(() => {
|
|
1354
|
+
SDK_HELPER_SYMBOL = Symbol("anthropic.sdk.stainlessHelper");
|
|
1355
|
+
});
|
|
1356
|
+
|
|
1357
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/utils/path.mjs
|
|
1358
|
+
function encodeURIPath(str) {
|
|
1359
|
+
return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
|
|
1360
|
+
}
|
|
1361
|
+
var EMPTY, createPathTagFunction = (pathEncoder = encodeURIPath) => function path(statics, ...params) {
|
|
1362
|
+
if (statics.length === 1)
|
|
1363
|
+
return statics[0];
|
|
1364
|
+
let postPath = false;
|
|
1365
|
+
const invalidSegments = [];
|
|
1366
|
+
const path2 = statics.reduce((previousValue, currentValue, index) => {
|
|
1367
|
+
if (/[?#]/.test(currentValue)) {
|
|
1368
|
+
postPath = true;
|
|
1369
|
+
}
|
|
1370
|
+
const value = params[index];
|
|
1371
|
+
let encoded = (postPath ? encodeURIComponent : pathEncoder)("" + value);
|
|
1372
|
+
if (index !== params.length && (value == null || typeof value === "object" && value.toString === Object.getPrototypeOf(Object.getPrototypeOf(value.hasOwnProperty ?? EMPTY) ?? EMPTY)?.toString)) {
|
|
1373
|
+
encoded = value + "";
|
|
1374
|
+
invalidSegments.push({
|
|
1375
|
+
start: previousValue.length + currentValue.length,
|
|
1376
|
+
length: encoded.length,
|
|
1377
|
+
error: `Value of type ${Object.prototype.toString.call(value).slice(8, -1)} is not a valid path parameter`
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
return previousValue + currentValue + (index === params.length ? "" : encoded);
|
|
1381
|
+
}, "");
|
|
1382
|
+
const pathOnly = path2.split(/[?#]/, 1)[0];
|
|
1383
|
+
const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
|
|
1384
|
+
let match;
|
|
1385
|
+
while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
|
|
1386
|
+
invalidSegments.push({
|
|
1387
|
+
start: match.index,
|
|
1388
|
+
length: match[0].length,
|
|
1389
|
+
error: `Value "${match[0]}" can't be safely passed as a path parameter`
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
invalidSegments.sort((a, b) => a.start - b.start);
|
|
1393
|
+
if (invalidSegments.length > 0) {
|
|
1394
|
+
let lastEnd = 0;
|
|
1395
|
+
const underline = invalidSegments.reduce((acc, segment) => {
|
|
1396
|
+
const spaces = " ".repeat(segment.start - lastEnd);
|
|
1397
|
+
const arrows = "^".repeat(segment.length);
|
|
1398
|
+
lastEnd = segment.start + segment.length;
|
|
1399
|
+
return acc + spaces + arrows;
|
|
1400
|
+
}, "");
|
|
1401
|
+
throw new AnthropicError(`Path parameters result in path with invalid segments:
|
|
1402
|
+
${invalidSegments.map((e) => e.error).join(`
|
|
1403
|
+
`)}
|
|
1404
|
+
${path2}
|
|
1405
|
+
${underline}`);
|
|
1406
|
+
}
|
|
1407
|
+
return path2;
|
|
1408
|
+
}, path;
|
|
1409
|
+
var init_path = __esm(() => {
|
|
1410
|
+
init_error();
|
|
1411
|
+
EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
1412
|
+
path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
|
|
1413
|
+
});
|
|
1414
|
+
|
|
1415
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/resources/beta/files.mjs
|
|
1416
|
+
var Files;
|
|
1417
|
+
var init_files = __esm(() => {
|
|
1418
|
+
init_resource();
|
|
1419
|
+
init_pagination();
|
|
1420
|
+
init_headers();
|
|
1421
|
+
init_stainless_helper_header();
|
|
1422
|
+
init_uploads();
|
|
1423
|
+
init_path();
|
|
1424
|
+
Files = class Files extends APIResource {
|
|
1425
|
+
list(params = {}, options) {
|
|
1426
|
+
const { betas, ...query } = params ?? {};
|
|
1427
|
+
return this._client.getAPIList("/v1/files", Page, {
|
|
1428
|
+
query,
|
|
1429
|
+
...options,
|
|
1430
|
+
headers: buildHeaders([
|
|
1431
|
+
{ "anthropic-beta": [...betas ?? [], "files-api-2025-04-14"].toString() },
|
|
1432
|
+
options?.headers
|
|
1433
|
+
])
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
delete(fileID, params = {}, options) {
|
|
1437
|
+
const { betas } = params ?? {};
|
|
1438
|
+
return this._client.delete(path`/v1/files/${fileID}`, {
|
|
1439
|
+
...options,
|
|
1440
|
+
headers: buildHeaders([
|
|
1441
|
+
{ "anthropic-beta": [...betas ?? [], "files-api-2025-04-14"].toString() },
|
|
1442
|
+
options?.headers
|
|
1443
|
+
])
|
|
1444
|
+
});
|
|
1445
|
+
}
|
|
1446
|
+
download(fileID, params = {}, options) {
|
|
1447
|
+
const { betas } = params ?? {};
|
|
1448
|
+
return this._client.get(path`/v1/files/${fileID}/content`, {
|
|
1449
|
+
...options,
|
|
1450
|
+
headers: buildHeaders([
|
|
1451
|
+
{
|
|
1452
|
+
"anthropic-beta": [...betas ?? [], "files-api-2025-04-14"].toString(),
|
|
1453
|
+
Accept: "application/binary"
|
|
1454
|
+
},
|
|
1455
|
+
options?.headers
|
|
1456
|
+
]),
|
|
1457
|
+
__binaryResponse: true
|
|
1458
|
+
});
|
|
1459
|
+
}
|
|
1460
|
+
retrieveMetadata(fileID, params = {}, options) {
|
|
1461
|
+
const { betas } = params ?? {};
|
|
1462
|
+
return this._client.get(path`/v1/files/${fileID}`, {
|
|
1463
|
+
...options,
|
|
1464
|
+
headers: buildHeaders([
|
|
1465
|
+
{ "anthropic-beta": [...betas ?? [], "files-api-2025-04-14"].toString() },
|
|
1466
|
+
options?.headers
|
|
1467
|
+
])
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
upload(params, options) {
|
|
1471
|
+
const { betas, ...body } = params;
|
|
1472
|
+
return this._client.post("/v1/files", multipartFormRequestOptions({
|
|
1473
|
+
body,
|
|
1474
|
+
...options,
|
|
1475
|
+
headers: buildHeaders([
|
|
1476
|
+
{ "anthropic-beta": [...betas ?? [], "files-api-2025-04-14"].toString() },
|
|
1477
|
+
stainlessHelperHeaderFromFile(body.file),
|
|
1478
|
+
options?.headers
|
|
1479
|
+
])
|
|
1480
|
+
}, this._client));
|
|
1481
|
+
}
|
|
1482
|
+
};
|
|
1483
|
+
});
|
|
1484
|
+
|
|
1485
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/resources/beta/models.mjs
|
|
1486
|
+
var Models;
|
|
1487
|
+
var init_models = __esm(() => {
|
|
1488
|
+
init_resource();
|
|
1489
|
+
init_pagination();
|
|
1490
|
+
init_headers();
|
|
1491
|
+
init_path();
|
|
1492
|
+
Models = class Models extends APIResource {
|
|
1493
|
+
retrieve(modelID, params = {}, options) {
|
|
1494
|
+
const { betas } = params ?? {};
|
|
1495
|
+
return this._client.get(path`/v1/models/${modelID}?beta=true`, {
|
|
1496
|
+
...options,
|
|
1497
|
+
headers: buildHeaders([
|
|
1498
|
+
{ ...betas?.toString() != null ? { "anthropic-beta": betas?.toString() } : undefined },
|
|
1499
|
+
options?.headers
|
|
1500
|
+
])
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
1503
|
+
list(params = {}, options) {
|
|
1504
|
+
const { betas, ...query } = params ?? {};
|
|
1505
|
+
return this._client.getAPIList("/v1/models?beta=true", Page, {
|
|
1506
|
+
query,
|
|
1507
|
+
...options,
|
|
1508
|
+
headers: buildHeaders([
|
|
1509
|
+
{ ...betas?.toString() != null ? { "anthropic-beta": betas?.toString() } : undefined },
|
|
1510
|
+
options?.headers
|
|
1511
|
+
])
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
});
|
|
1516
|
+
|
|
1517
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/error.mjs
|
|
1518
|
+
var init_error2 = __esm(() => {
|
|
1519
|
+
init_error();
|
|
1520
|
+
});
|
|
1521
|
+
|
|
1522
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/constants.mjs
|
|
1523
|
+
var MODEL_NONSTREAMING_TOKENS;
|
|
1524
|
+
var init_constants = __esm(() => {
|
|
1525
|
+
MODEL_NONSTREAMING_TOKENS = {
|
|
1526
|
+
"claude-opus-4-20250514": 8192,
|
|
1527
|
+
"claude-opus-4-0": 8192,
|
|
1528
|
+
"claude-4-opus-20250514": 8192,
|
|
1529
|
+
"anthropic.claude-opus-4-20250514-v1:0": 8192,
|
|
1530
|
+
"claude-opus-4@20250514": 8192,
|
|
1531
|
+
"claude-opus-4-1-20250805": 8192,
|
|
1532
|
+
"anthropic.claude-opus-4-1-20250805-v1:0": 8192,
|
|
1533
|
+
"claude-opus-4-1@20250805": 8192
|
|
1534
|
+
};
|
|
1535
|
+
});
|
|
1536
|
+
|
|
1537
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/lib/beta-parser.mjs
|
|
1538
|
+
function getOutputFormat(params) {
|
|
1539
|
+
return params?.output_format ?? params?.output_config?.format;
|
|
1540
|
+
}
|
|
1541
|
+
function maybeParseBetaMessage(message, params, opts) {
|
|
1542
|
+
const outputFormat = getOutputFormat(params);
|
|
1543
|
+
if (!params || !("parse" in (outputFormat ?? {}))) {
|
|
1544
|
+
return {
|
|
1545
|
+
...message,
|
|
1546
|
+
content: message.content.map((block) => {
|
|
1547
|
+
if (block.type === "text") {
|
|
1548
|
+
const parsedBlock = Object.defineProperty({ ...block }, "parsed_output", {
|
|
1549
|
+
value: null,
|
|
1550
|
+
enumerable: false
|
|
1551
|
+
});
|
|
1552
|
+
return Object.defineProperty(parsedBlock, "parsed", {
|
|
1553
|
+
get() {
|
|
1554
|
+
opts.logger.warn("The `parsed` property on `text` blocks is deprecated, please use `parsed_output` instead.");
|
|
1555
|
+
return null;
|
|
1556
|
+
},
|
|
1557
|
+
enumerable: false
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
return block;
|
|
1561
|
+
}),
|
|
1562
|
+
parsed_output: null
|
|
1563
|
+
};
|
|
1564
|
+
}
|
|
1565
|
+
return parseBetaMessage(message, params, opts);
|
|
1566
|
+
}
|
|
1567
|
+
function parseBetaMessage(message, params, opts) {
|
|
1568
|
+
let firstParsedOutput = null;
|
|
1569
|
+
const content = message.content.map((block) => {
|
|
1570
|
+
if (block.type === "text") {
|
|
1571
|
+
const parsedOutput = parseBetaOutputFormat(params, block.text);
|
|
1572
|
+
if (firstParsedOutput === null) {
|
|
1573
|
+
firstParsedOutput = parsedOutput;
|
|
1574
|
+
}
|
|
1575
|
+
const parsedBlock = Object.defineProperty({ ...block }, "parsed_output", {
|
|
1576
|
+
value: parsedOutput,
|
|
1577
|
+
enumerable: false
|
|
1578
|
+
});
|
|
1579
|
+
return Object.defineProperty(parsedBlock, "parsed", {
|
|
1580
|
+
get() {
|
|
1581
|
+
opts.logger.warn("The `parsed` property on `text` blocks is deprecated, please use `parsed_output` instead.");
|
|
1582
|
+
return parsedOutput;
|
|
1583
|
+
},
|
|
1584
|
+
enumerable: false
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
return block;
|
|
1588
|
+
});
|
|
1589
|
+
return {
|
|
1590
|
+
...message,
|
|
1591
|
+
content,
|
|
1592
|
+
parsed_output: firstParsedOutput
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1595
|
+
function parseBetaOutputFormat(params, content) {
|
|
1596
|
+
const outputFormat = getOutputFormat(params);
|
|
1597
|
+
if (outputFormat?.type !== "json_schema") {
|
|
1598
|
+
return null;
|
|
1599
|
+
}
|
|
1600
|
+
try {
|
|
1601
|
+
if ("parse" in outputFormat) {
|
|
1602
|
+
return outputFormat.parse(content);
|
|
1603
|
+
}
|
|
1604
|
+
return JSON.parse(content);
|
|
1605
|
+
} catch (error2) {
|
|
1606
|
+
throw new AnthropicError(`Failed to parse structured output: ${error2}`);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
var init_beta_parser = __esm(() => {
|
|
1610
|
+
init_error();
|
|
1611
|
+
});
|
|
1612
|
+
|
|
1613
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/_vendor/partial-json-parser/parser.mjs
|
|
1614
|
+
var tokenize = (input) => {
|
|
1615
|
+
let current = 0;
|
|
1616
|
+
let tokens = [];
|
|
1617
|
+
while (current < input.length) {
|
|
1618
|
+
let char = input[current];
|
|
1619
|
+
if (char === "\\") {
|
|
1620
|
+
current++;
|
|
1621
|
+
continue;
|
|
1622
|
+
}
|
|
1623
|
+
if (char === "{") {
|
|
1624
|
+
tokens.push({
|
|
1625
|
+
type: "brace",
|
|
1626
|
+
value: "{"
|
|
1627
|
+
});
|
|
1628
|
+
current++;
|
|
1629
|
+
continue;
|
|
1630
|
+
}
|
|
1631
|
+
if (char === "}") {
|
|
1632
|
+
tokens.push({
|
|
1633
|
+
type: "brace",
|
|
1634
|
+
value: "}"
|
|
1635
|
+
});
|
|
1636
|
+
current++;
|
|
1637
|
+
continue;
|
|
1638
|
+
}
|
|
1639
|
+
if (char === "[") {
|
|
1640
|
+
tokens.push({
|
|
1641
|
+
type: "paren",
|
|
1642
|
+
value: "["
|
|
1643
|
+
});
|
|
1644
|
+
current++;
|
|
1645
|
+
continue;
|
|
1646
|
+
}
|
|
1647
|
+
if (char === "]") {
|
|
1648
|
+
tokens.push({
|
|
1649
|
+
type: "paren",
|
|
1650
|
+
value: "]"
|
|
1651
|
+
});
|
|
1652
|
+
current++;
|
|
1653
|
+
continue;
|
|
1654
|
+
}
|
|
1655
|
+
if (char === ":") {
|
|
1656
|
+
tokens.push({
|
|
1657
|
+
type: "separator",
|
|
1658
|
+
value: ":"
|
|
1659
|
+
});
|
|
1660
|
+
current++;
|
|
1661
|
+
continue;
|
|
1662
|
+
}
|
|
1663
|
+
if (char === ",") {
|
|
1664
|
+
tokens.push({
|
|
1665
|
+
type: "delimiter",
|
|
1666
|
+
value: ","
|
|
1667
|
+
});
|
|
1668
|
+
current++;
|
|
1669
|
+
continue;
|
|
1670
|
+
}
|
|
1671
|
+
if (char === '"') {
|
|
1672
|
+
let value = "";
|
|
1673
|
+
let danglingQuote = false;
|
|
1674
|
+
char = input[++current];
|
|
1675
|
+
while (char !== '"') {
|
|
1676
|
+
if (current === input.length) {
|
|
1677
|
+
danglingQuote = true;
|
|
1678
|
+
break;
|
|
1679
|
+
}
|
|
1680
|
+
if (char === "\\") {
|
|
1681
|
+
current++;
|
|
1682
|
+
if (current === input.length) {
|
|
1683
|
+
danglingQuote = true;
|
|
1684
|
+
break;
|
|
1685
|
+
}
|
|
1686
|
+
value += char + input[current];
|
|
1687
|
+
char = input[++current];
|
|
1688
|
+
} else {
|
|
1689
|
+
value += char;
|
|
1690
|
+
char = input[++current];
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
char = input[++current];
|
|
1694
|
+
if (!danglingQuote) {
|
|
1695
|
+
tokens.push({
|
|
1696
|
+
type: "string",
|
|
1697
|
+
value
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
1700
|
+
continue;
|
|
1701
|
+
}
|
|
1702
|
+
let WHITESPACE = /\s/;
|
|
1703
|
+
if (char && WHITESPACE.test(char)) {
|
|
1704
|
+
current++;
|
|
1705
|
+
continue;
|
|
1706
|
+
}
|
|
1707
|
+
let NUMBERS = /[0-9]/;
|
|
1708
|
+
if (char && NUMBERS.test(char) || char === "-" || char === ".") {
|
|
1709
|
+
let value = "";
|
|
1710
|
+
if (char === "-") {
|
|
1711
|
+
value += char;
|
|
1712
|
+
char = input[++current];
|
|
1713
|
+
}
|
|
1714
|
+
while (char && NUMBERS.test(char) || char === ".") {
|
|
1715
|
+
value += char;
|
|
1716
|
+
char = input[++current];
|
|
1717
|
+
}
|
|
1718
|
+
tokens.push({
|
|
1719
|
+
type: "number",
|
|
1720
|
+
value
|
|
1721
|
+
});
|
|
1722
|
+
continue;
|
|
1723
|
+
}
|
|
1724
|
+
let LETTERS = /[a-z]/i;
|
|
1725
|
+
if (char && LETTERS.test(char)) {
|
|
1726
|
+
let value = "";
|
|
1727
|
+
while (char && LETTERS.test(char)) {
|
|
1728
|
+
if (current === input.length) {
|
|
1729
|
+
break;
|
|
1730
|
+
}
|
|
1731
|
+
value += char;
|
|
1732
|
+
char = input[++current];
|
|
1733
|
+
}
|
|
1734
|
+
if (value == "true" || value == "false" || value === "null") {
|
|
1735
|
+
tokens.push({
|
|
1736
|
+
type: "name",
|
|
1737
|
+
value
|
|
1738
|
+
});
|
|
1739
|
+
} else {
|
|
1740
|
+
current++;
|
|
1741
|
+
continue;
|
|
1742
|
+
}
|
|
1743
|
+
continue;
|
|
1744
|
+
}
|
|
1745
|
+
current++;
|
|
1746
|
+
}
|
|
1747
|
+
return tokens;
|
|
1748
|
+
}, strip = (tokens) => {
|
|
1749
|
+
if (tokens.length === 0) {
|
|
1750
|
+
return tokens;
|
|
1751
|
+
}
|
|
1752
|
+
let lastToken = tokens[tokens.length - 1];
|
|
1753
|
+
switch (lastToken.type) {
|
|
1754
|
+
case "separator":
|
|
1755
|
+
tokens = tokens.slice(0, tokens.length - 1);
|
|
1756
|
+
return strip(tokens);
|
|
1757
|
+
break;
|
|
1758
|
+
case "number":
|
|
1759
|
+
let lastCharacterOfLastToken = lastToken.value[lastToken.value.length - 1];
|
|
1760
|
+
if (lastCharacterOfLastToken === "." || lastCharacterOfLastToken === "-") {
|
|
1761
|
+
tokens = tokens.slice(0, tokens.length - 1);
|
|
1762
|
+
return strip(tokens);
|
|
1763
|
+
}
|
|
1764
|
+
case "string":
|
|
1765
|
+
let tokenBeforeTheLastToken = tokens[tokens.length - 2];
|
|
1766
|
+
if (tokenBeforeTheLastToken?.type === "delimiter") {
|
|
1767
|
+
tokens = tokens.slice(0, tokens.length - 1);
|
|
1768
|
+
return strip(tokens);
|
|
1769
|
+
} else if (tokenBeforeTheLastToken?.type === "brace" && tokenBeforeTheLastToken.value === "{") {
|
|
1770
|
+
tokens = tokens.slice(0, tokens.length - 1);
|
|
1771
|
+
return strip(tokens);
|
|
1772
|
+
}
|
|
1773
|
+
break;
|
|
1774
|
+
case "delimiter":
|
|
1775
|
+
tokens = tokens.slice(0, tokens.length - 1);
|
|
1776
|
+
return strip(tokens);
|
|
1777
|
+
break;
|
|
1778
|
+
}
|
|
1779
|
+
return tokens;
|
|
1780
|
+
}, unstrip = (tokens) => {
|
|
1781
|
+
let tail = [];
|
|
1782
|
+
tokens.map((token) => {
|
|
1783
|
+
if (token.type === "brace") {
|
|
1784
|
+
if (token.value === "{") {
|
|
1785
|
+
tail.push("}");
|
|
1786
|
+
} else {
|
|
1787
|
+
tail.splice(tail.lastIndexOf("}"), 1);
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
if (token.type === "paren") {
|
|
1791
|
+
if (token.value === "[") {
|
|
1792
|
+
tail.push("]");
|
|
1793
|
+
} else {
|
|
1794
|
+
tail.splice(tail.lastIndexOf("]"), 1);
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
});
|
|
1798
|
+
if (tail.length > 0) {
|
|
1799
|
+
tail.reverse().map((item) => {
|
|
1800
|
+
if (item === "}") {
|
|
1801
|
+
tokens.push({
|
|
1802
|
+
type: "brace",
|
|
1803
|
+
value: "}"
|
|
1804
|
+
});
|
|
1805
|
+
} else if (item === "]") {
|
|
1806
|
+
tokens.push({
|
|
1807
|
+
type: "paren",
|
|
1808
|
+
value: "]"
|
|
1809
|
+
});
|
|
1810
|
+
}
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
return tokens;
|
|
1814
|
+
}, generate = (tokens) => {
|
|
1815
|
+
let output = "";
|
|
1816
|
+
tokens.map((token) => {
|
|
1817
|
+
switch (token.type) {
|
|
1818
|
+
case "string":
|
|
1819
|
+
output += '"' + token.value + '"';
|
|
1820
|
+
break;
|
|
1821
|
+
default:
|
|
1822
|
+
output += token.value;
|
|
1823
|
+
break;
|
|
1824
|
+
}
|
|
1825
|
+
});
|
|
1826
|
+
return output;
|
|
1827
|
+
}, partialParse = (input) => JSON.parse(generate(unstrip(strip(tokenize(input)))));
|
|
1828
|
+
var init_parser = () => {};
|
|
1829
|
+
|
|
1830
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/streaming.mjs
|
|
1831
|
+
var init_streaming2 = __esm(() => {
|
|
1832
|
+
init_streaming();
|
|
1833
|
+
});
|
|
1834
|
+
|
|
1835
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/lib/BetaMessageStream.mjs
|
|
1836
|
+
function tracksToolInput(content) {
|
|
1837
|
+
return content.type === "tool_use" || content.type === "server_tool_use" || content.type === "mcp_tool_use";
|
|
1838
|
+
}
|
|
1839
|
+
function checkNever(x) {}
|
|
1840
|
+
var _BetaMessageStream_instances, _BetaMessageStream_currentMessageSnapshot, _BetaMessageStream_params, _BetaMessageStream_connectedPromise, _BetaMessageStream_resolveConnectedPromise, _BetaMessageStream_rejectConnectedPromise, _BetaMessageStream_endPromise, _BetaMessageStream_resolveEndPromise, _BetaMessageStream_rejectEndPromise, _BetaMessageStream_listeners, _BetaMessageStream_ended, _BetaMessageStream_errored, _BetaMessageStream_aborted, _BetaMessageStream_catchingPromiseCreated, _BetaMessageStream_response, _BetaMessageStream_request_id, _BetaMessageStream_logger, _BetaMessageStream_getFinalMessage, _BetaMessageStream_getFinalText, _BetaMessageStream_handleError, _BetaMessageStream_beginRequest, _BetaMessageStream_addStreamEvent, _BetaMessageStream_endRequest, _BetaMessageStream_accumulateMessage, JSON_BUF_PROPERTY = "__json_buf", BetaMessageStream;
|
|
1841
|
+
var init_BetaMessageStream = __esm(() => {
|
|
1842
|
+
init_tslib();
|
|
1843
|
+
init_parser();
|
|
1844
|
+
init_error2();
|
|
1845
|
+
init_errors();
|
|
1846
|
+
init_streaming2();
|
|
1847
|
+
init_beta_parser();
|
|
1848
|
+
BetaMessageStream = class BetaMessageStream {
|
|
1849
|
+
constructor(params, opts) {
|
|
1850
|
+
_BetaMessageStream_instances.add(this);
|
|
1851
|
+
this.messages = [];
|
|
1852
|
+
this.receivedMessages = [];
|
|
1853
|
+
_BetaMessageStream_currentMessageSnapshot.set(this, undefined);
|
|
1854
|
+
_BetaMessageStream_params.set(this, null);
|
|
1855
|
+
this.controller = new AbortController;
|
|
1856
|
+
_BetaMessageStream_connectedPromise.set(this, undefined);
|
|
1857
|
+
_BetaMessageStream_resolveConnectedPromise.set(this, () => {});
|
|
1858
|
+
_BetaMessageStream_rejectConnectedPromise.set(this, () => {});
|
|
1859
|
+
_BetaMessageStream_endPromise.set(this, undefined);
|
|
1860
|
+
_BetaMessageStream_resolveEndPromise.set(this, () => {});
|
|
1861
|
+
_BetaMessageStream_rejectEndPromise.set(this, () => {});
|
|
1862
|
+
_BetaMessageStream_listeners.set(this, {});
|
|
1863
|
+
_BetaMessageStream_ended.set(this, false);
|
|
1864
|
+
_BetaMessageStream_errored.set(this, false);
|
|
1865
|
+
_BetaMessageStream_aborted.set(this, false);
|
|
1866
|
+
_BetaMessageStream_catchingPromiseCreated.set(this, false);
|
|
1867
|
+
_BetaMessageStream_response.set(this, undefined);
|
|
1868
|
+
_BetaMessageStream_request_id.set(this, undefined);
|
|
1869
|
+
_BetaMessageStream_logger.set(this, undefined);
|
|
1870
|
+
_BetaMessageStream_handleError.set(this, (error2) => {
|
|
1871
|
+
__classPrivateFieldSet(this, _BetaMessageStream_errored, true, "f");
|
|
1872
|
+
if (isAbortError(error2)) {
|
|
1873
|
+
error2 = new APIUserAbortError;
|
|
1874
|
+
}
|
|
1875
|
+
if (error2 instanceof APIUserAbortError) {
|
|
1876
|
+
__classPrivateFieldSet(this, _BetaMessageStream_aborted, true, "f");
|
|
1877
|
+
return this._emit("abort", error2);
|
|
1878
|
+
}
|
|
1879
|
+
if (error2 instanceof AnthropicError) {
|
|
1880
|
+
return this._emit("error", error2);
|
|
1881
|
+
}
|
|
1882
|
+
if (error2 instanceof Error) {
|
|
1883
|
+
const anthropicError = new AnthropicError(error2.message);
|
|
1884
|
+
anthropicError.cause = error2;
|
|
1885
|
+
return this._emit("error", anthropicError);
|
|
1886
|
+
}
|
|
1887
|
+
return this._emit("error", new AnthropicError(String(error2)));
|
|
1888
|
+
});
|
|
1889
|
+
__classPrivateFieldSet(this, _BetaMessageStream_connectedPromise, new Promise((resolve, reject) => {
|
|
1890
|
+
__classPrivateFieldSet(this, _BetaMessageStream_resolveConnectedPromise, resolve, "f");
|
|
1891
|
+
__classPrivateFieldSet(this, _BetaMessageStream_rejectConnectedPromise, reject, "f");
|
|
1892
|
+
}), "f");
|
|
1893
|
+
__classPrivateFieldSet(this, _BetaMessageStream_endPromise, new Promise((resolve, reject) => {
|
|
1894
|
+
__classPrivateFieldSet(this, _BetaMessageStream_resolveEndPromise, resolve, "f");
|
|
1895
|
+
__classPrivateFieldSet(this, _BetaMessageStream_rejectEndPromise, reject, "f");
|
|
1896
|
+
}), "f");
|
|
1897
|
+
__classPrivateFieldGet(this, _BetaMessageStream_connectedPromise, "f").catch(() => {});
|
|
1898
|
+
__classPrivateFieldGet(this, _BetaMessageStream_endPromise, "f").catch(() => {});
|
|
1899
|
+
__classPrivateFieldSet(this, _BetaMessageStream_params, params, "f");
|
|
1900
|
+
__classPrivateFieldSet(this, _BetaMessageStream_logger, opts?.logger ?? console, "f");
|
|
1901
|
+
}
|
|
1902
|
+
get response() {
|
|
1903
|
+
return __classPrivateFieldGet(this, _BetaMessageStream_response, "f");
|
|
1904
|
+
}
|
|
1905
|
+
get request_id() {
|
|
1906
|
+
return __classPrivateFieldGet(this, _BetaMessageStream_request_id, "f");
|
|
1907
|
+
}
|
|
1908
|
+
async withResponse() {
|
|
1909
|
+
__classPrivateFieldSet(this, _BetaMessageStream_catchingPromiseCreated, true, "f");
|
|
1910
|
+
const response = await __classPrivateFieldGet(this, _BetaMessageStream_connectedPromise, "f");
|
|
1911
|
+
if (!response) {
|
|
1912
|
+
throw new Error("Could not resolve a `Response` object");
|
|
1913
|
+
}
|
|
1914
|
+
return {
|
|
1915
|
+
data: this,
|
|
1916
|
+
response,
|
|
1917
|
+
request_id: response.headers.get("request-id")
|
|
1918
|
+
};
|
|
1919
|
+
}
|
|
1920
|
+
static fromReadableStream(stream) {
|
|
1921
|
+
const runner = new BetaMessageStream(null);
|
|
1922
|
+
runner._run(() => runner._fromReadableStream(stream));
|
|
1923
|
+
return runner;
|
|
1924
|
+
}
|
|
1925
|
+
static createMessage(messages, params, options, { logger } = {}) {
|
|
1926
|
+
const runner = new BetaMessageStream(params, { logger });
|
|
1927
|
+
for (const message of params.messages) {
|
|
1928
|
+
runner._addMessageParam(message);
|
|
1929
|
+
}
|
|
1930
|
+
__classPrivateFieldSet(runner, _BetaMessageStream_params, { ...params, stream: true }, "f");
|
|
1931
|
+
runner._run(() => runner._createMessage(messages, { ...params, stream: true }, { ...options, headers: { ...options?.headers, "X-Stainless-Helper-Method": "stream" } }));
|
|
1932
|
+
return runner;
|
|
1933
|
+
}
|
|
1934
|
+
_run(executor) {
|
|
1935
|
+
executor().then(() => {
|
|
1936
|
+
this._emitFinal();
|
|
1937
|
+
this._emit("end");
|
|
1938
|
+
}, __classPrivateFieldGet(this, _BetaMessageStream_handleError, "f"));
|
|
1939
|
+
}
|
|
1940
|
+
_addMessageParam(message) {
|
|
1941
|
+
this.messages.push(message);
|
|
1942
|
+
}
|
|
1943
|
+
_addMessage(message, emit = true) {
|
|
1944
|
+
this.receivedMessages.push(message);
|
|
1945
|
+
if (emit) {
|
|
1946
|
+
this._emit("message", message);
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
async _createMessage(messages, params, options) {
|
|
1950
|
+
const signal = options?.signal;
|
|
1951
|
+
let abortHandler;
|
|
1952
|
+
if (signal) {
|
|
1953
|
+
if (signal.aborted)
|
|
1954
|
+
this.controller.abort();
|
|
1955
|
+
abortHandler = this.controller.abort.bind(this.controller);
|
|
1956
|
+
signal.addEventListener("abort", abortHandler);
|
|
1957
|
+
}
|
|
1958
|
+
try {
|
|
1959
|
+
__classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_beginRequest).call(this);
|
|
1960
|
+
const { response, data: stream } = await messages.create({ ...params, stream: true }, { ...options, signal: this.controller.signal }).withResponse();
|
|
1961
|
+
this._connected(response);
|
|
1962
|
+
for await (const event of stream) {
|
|
1963
|
+
__classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_addStreamEvent).call(this, event);
|
|
1964
|
+
}
|
|
1965
|
+
if (stream.controller.signal?.aborted) {
|
|
1966
|
+
throw new APIUserAbortError;
|
|
1967
|
+
}
|
|
1968
|
+
__classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_endRequest).call(this);
|
|
1969
|
+
} finally {
|
|
1970
|
+
if (signal && abortHandler) {
|
|
1971
|
+
signal.removeEventListener("abort", abortHandler);
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
_connected(response) {
|
|
1976
|
+
if (this.ended)
|
|
1977
|
+
return;
|
|
1978
|
+
__classPrivateFieldSet(this, _BetaMessageStream_response, response, "f");
|
|
1979
|
+
__classPrivateFieldSet(this, _BetaMessageStream_request_id, response?.headers.get("request-id"), "f");
|
|
1980
|
+
__classPrivateFieldGet(this, _BetaMessageStream_resolveConnectedPromise, "f").call(this, response);
|
|
1981
|
+
this._emit("connect");
|
|
1982
|
+
}
|
|
1983
|
+
get ended() {
|
|
1984
|
+
return __classPrivateFieldGet(this, _BetaMessageStream_ended, "f");
|
|
1985
|
+
}
|
|
1986
|
+
get errored() {
|
|
1987
|
+
return __classPrivateFieldGet(this, _BetaMessageStream_errored, "f");
|
|
1988
|
+
}
|
|
1989
|
+
get aborted() {
|
|
1990
|
+
return __classPrivateFieldGet(this, _BetaMessageStream_aborted, "f");
|
|
1991
|
+
}
|
|
1992
|
+
abort() {
|
|
1993
|
+
this.controller.abort();
|
|
1994
|
+
}
|
|
1995
|
+
on(event, listener) {
|
|
1996
|
+
const listeners = __classPrivateFieldGet(this, _BetaMessageStream_listeners, "f")[event] || (__classPrivateFieldGet(this, _BetaMessageStream_listeners, "f")[event] = []);
|
|
1997
|
+
listeners.push({ listener });
|
|
1998
|
+
return this;
|
|
1999
|
+
}
|
|
2000
|
+
off(event, listener) {
|
|
2001
|
+
const listeners = __classPrivateFieldGet(this, _BetaMessageStream_listeners, "f")[event];
|
|
2002
|
+
if (!listeners)
|
|
2003
|
+
return this;
|
|
2004
|
+
const index = listeners.findIndex((l) => l.listener === listener);
|
|
2005
|
+
if (index >= 0)
|
|
2006
|
+
listeners.splice(index, 1);
|
|
2007
|
+
return this;
|
|
2008
|
+
}
|
|
2009
|
+
once(event, listener) {
|
|
2010
|
+
const listeners = __classPrivateFieldGet(this, _BetaMessageStream_listeners, "f")[event] || (__classPrivateFieldGet(this, _BetaMessageStream_listeners, "f")[event] = []);
|
|
2011
|
+
listeners.push({ listener, once: true });
|
|
2012
|
+
return this;
|
|
2013
|
+
}
|
|
2014
|
+
emitted(event) {
|
|
2015
|
+
return new Promise((resolve, reject) => {
|
|
2016
|
+
__classPrivateFieldSet(this, _BetaMessageStream_catchingPromiseCreated, true, "f");
|
|
2017
|
+
if (event !== "error")
|
|
2018
|
+
this.once("error", reject);
|
|
2019
|
+
this.once(event, resolve);
|
|
2020
|
+
});
|
|
2021
|
+
}
|
|
2022
|
+
async done() {
|
|
2023
|
+
__classPrivateFieldSet(this, _BetaMessageStream_catchingPromiseCreated, true, "f");
|
|
2024
|
+
await __classPrivateFieldGet(this, _BetaMessageStream_endPromise, "f");
|
|
2025
|
+
}
|
|
2026
|
+
get currentMessage() {
|
|
2027
|
+
return __classPrivateFieldGet(this, _BetaMessageStream_currentMessageSnapshot, "f");
|
|
2028
|
+
}
|
|
2029
|
+
async finalMessage() {
|
|
2030
|
+
await this.done();
|
|
2031
|
+
return __classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_getFinalMessage).call(this);
|
|
2032
|
+
}
|
|
2033
|
+
async finalText() {
|
|
2034
|
+
await this.done();
|
|
2035
|
+
return __classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_getFinalText).call(this);
|
|
2036
|
+
}
|
|
2037
|
+
_emit(event, ...args) {
|
|
2038
|
+
if (__classPrivateFieldGet(this, _BetaMessageStream_ended, "f"))
|
|
2039
|
+
return;
|
|
2040
|
+
if (event === "end") {
|
|
2041
|
+
__classPrivateFieldSet(this, _BetaMessageStream_ended, true, "f");
|
|
2042
|
+
__classPrivateFieldGet(this, _BetaMessageStream_resolveEndPromise, "f").call(this);
|
|
2043
|
+
}
|
|
2044
|
+
const listeners = __classPrivateFieldGet(this, _BetaMessageStream_listeners, "f")[event];
|
|
2045
|
+
if (listeners) {
|
|
2046
|
+
__classPrivateFieldGet(this, _BetaMessageStream_listeners, "f")[event] = listeners.filter((l) => !l.once);
|
|
2047
|
+
listeners.forEach(({ listener }) => listener(...args));
|
|
2048
|
+
}
|
|
2049
|
+
if (event === "abort") {
|
|
2050
|
+
const error2 = args[0];
|
|
2051
|
+
if (!__classPrivateFieldGet(this, _BetaMessageStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
|
2052
|
+
Promise.reject(error2);
|
|
2053
|
+
}
|
|
2054
|
+
__classPrivateFieldGet(this, _BetaMessageStream_rejectConnectedPromise, "f").call(this, error2);
|
|
2055
|
+
__classPrivateFieldGet(this, _BetaMessageStream_rejectEndPromise, "f").call(this, error2);
|
|
2056
|
+
this._emit("end");
|
|
2057
|
+
return;
|
|
2058
|
+
}
|
|
2059
|
+
if (event === "error") {
|
|
2060
|
+
const error2 = args[0];
|
|
2061
|
+
if (!__classPrivateFieldGet(this, _BetaMessageStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
|
2062
|
+
Promise.reject(error2);
|
|
2063
|
+
}
|
|
2064
|
+
__classPrivateFieldGet(this, _BetaMessageStream_rejectConnectedPromise, "f").call(this, error2);
|
|
2065
|
+
__classPrivateFieldGet(this, _BetaMessageStream_rejectEndPromise, "f").call(this, error2);
|
|
2066
|
+
this._emit("end");
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
_emitFinal() {
|
|
2070
|
+
const finalMessage = this.receivedMessages.at(-1);
|
|
2071
|
+
if (finalMessage) {
|
|
2072
|
+
this._emit("finalMessage", __classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_getFinalMessage).call(this));
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
async _fromReadableStream(readableStream, options) {
|
|
2076
|
+
const signal = options?.signal;
|
|
2077
|
+
let abortHandler;
|
|
2078
|
+
if (signal) {
|
|
2079
|
+
if (signal.aborted)
|
|
2080
|
+
this.controller.abort();
|
|
2081
|
+
abortHandler = this.controller.abort.bind(this.controller);
|
|
2082
|
+
signal.addEventListener("abort", abortHandler);
|
|
2083
|
+
}
|
|
2084
|
+
try {
|
|
2085
|
+
__classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_beginRequest).call(this);
|
|
2086
|
+
this._connected(null);
|
|
2087
|
+
const stream = Stream.fromReadableStream(readableStream, this.controller);
|
|
2088
|
+
for await (const event of stream) {
|
|
2089
|
+
__classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_addStreamEvent).call(this, event);
|
|
2090
|
+
}
|
|
2091
|
+
if (stream.controller.signal?.aborted) {
|
|
2092
|
+
throw new APIUserAbortError;
|
|
2093
|
+
}
|
|
2094
|
+
__classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_endRequest).call(this);
|
|
2095
|
+
} finally {
|
|
2096
|
+
if (signal && abortHandler) {
|
|
2097
|
+
signal.removeEventListener("abort", abortHandler);
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
[(_BetaMessageStream_currentMessageSnapshot = new WeakMap, _BetaMessageStream_params = new WeakMap, _BetaMessageStream_connectedPromise = new WeakMap, _BetaMessageStream_resolveConnectedPromise = new WeakMap, _BetaMessageStream_rejectConnectedPromise = new WeakMap, _BetaMessageStream_endPromise = new WeakMap, _BetaMessageStream_resolveEndPromise = new WeakMap, _BetaMessageStream_rejectEndPromise = new WeakMap, _BetaMessageStream_listeners = new WeakMap, _BetaMessageStream_ended = new WeakMap, _BetaMessageStream_errored = new WeakMap, _BetaMessageStream_aborted = new WeakMap, _BetaMessageStream_catchingPromiseCreated = new WeakMap, _BetaMessageStream_response = new WeakMap, _BetaMessageStream_request_id = new WeakMap, _BetaMessageStream_logger = new WeakMap, _BetaMessageStream_handleError = new WeakMap, _BetaMessageStream_instances = new WeakSet, _BetaMessageStream_getFinalMessage = function _BetaMessageStream_getFinalMessage2() {
|
|
2102
|
+
if (this.receivedMessages.length === 0) {
|
|
2103
|
+
throw new AnthropicError("stream ended without producing a Message with role=assistant");
|
|
2104
|
+
}
|
|
2105
|
+
return this.receivedMessages.at(-1);
|
|
2106
|
+
}, _BetaMessageStream_getFinalText = function _BetaMessageStream_getFinalText2() {
|
|
2107
|
+
if (this.receivedMessages.length === 0) {
|
|
2108
|
+
throw new AnthropicError("stream ended without producing a Message with role=assistant");
|
|
2109
|
+
}
|
|
2110
|
+
const textBlocks = this.receivedMessages.at(-1).content.filter((block) => block.type === "text").map((block) => block.text);
|
|
2111
|
+
if (textBlocks.length === 0) {
|
|
2112
|
+
throw new AnthropicError("stream ended without producing a content block with type=text");
|
|
2113
|
+
}
|
|
2114
|
+
return textBlocks.join(" ");
|
|
2115
|
+
}, _BetaMessageStream_beginRequest = function _BetaMessageStream_beginRequest2() {
|
|
2116
|
+
if (this.ended)
|
|
2117
|
+
return;
|
|
2118
|
+
__classPrivateFieldSet(this, _BetaMessageStream_currentMessageSnapshot, undefined, "f");
|
|
2119
|
+
}, _BetaMessageStream_addStreamEvent = function _BetaMessageStream_addStreamEvent2(event) {
|
|
2120
|
+
if (this.ended)
|
|
2121
|
+
return;
|
|
2122
|
+
const messageSnapshot = __classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_accumulateMessage).call(this, event);
|
|
2123
|
+
this._emit("streamEvent", event, messageSnapshot);
|
|
2124
|
+
switch (event.type) {
|
|
2125
|
+
case "content_block_delta": {
|
|
2126
|
+
const content = messageSnapshot.content.at(-1);
|
|
2127
|
+
switch (event.delta.type) {
|
|
2128
|
+
case "text_delta": {
|
|
2129
|
+
if (content.type === "text") {
|
|
2130
|
+
this._emit("text", event.delta.text, content.text || "");
|
|
2131
|
+
}
|
|
2132
|
+
break;
|
|
2133
|
+
}
|
|
2134
|
+
case "citations_delta": {
|
|
2135
|
+
if (content.type === "text") {
|
|
2136
|
+
this._emit("citation", event.delta.citation, content.citations ?? []);
|
|
2137
|
+
}
|
|
2138
|
+
break;
|
|
2139
|
+
}
|
|
2140
|
+
case "input_json_delta": {
|
|
2141
|
+
if (tracksToolInput(content) && content.input) {
|
|
2142
|
+
this._emit("inputJson", event.delta.partial_json, content.input);
|
|
2143
|
+
}
|
|
2144
|
+
break;
|
|
2145
|
+
}
|
|
2146
|
+
case "thinking_delta": {
|
|
2147
|
+
if (content.type === "thinking") {
|
|
2148
|
+
this._emit("thinking", event.delta.thinking, content.thinking);
|
|
2149
|
+
}
|
|
2150
|
+
break;
|
|
2151
|
+
}
|
|
2152
|
+
case "signature_delta": {
|
|
2153
|
+
if (content.type === "thinking") {
|
|
2154
|
+
this._emit("signature", content.signature);
|
|
2155
|
+
}
|
|
2156
|
+
break;
|
|
2157
|
+
}
|
|
2158
|
+
case "compaction_delta": {
|
|
2159
|
+
if (content.type === "compaction" && content.content) {
|
|
2160
|
+
this._emit("compaction", content.content);
|
|
2161
|
+
}
|
|
2162
|
+
break;
|
|
2163
|
+
}
|
|
2164
|
+
default:
|
|
2165
|
+
checkNever(event.delta);
|
|
2166
|
+
}
|
|
2167
|
+
break;
|
|
2168
|
+
}
|
|
2169
|
+
case "message_stop": {
|
|
2170
|
+
this._addMessageParam(messageSnapshot);
|
|
2171
|
+
this._addMessage(maybeParseBetaMessage(messageSnapshot, __classPrivateFieldGet(this, _BetaMessageStream_params, "f"), { logger: __classPrivateFieldGet(this, _BetaMessageStream_logger, "f") }), true);
|
|
2172
|
+
break;
|
|
2173
|
+
}
|
|
2174
|
+
case "content_block_stop": {
|
|
2175
|
+
this._emit("contentBlock", messageSnapshot.content.at(-1));
|
|
2176
|
+
break;
|
|
2177
|
+
}
|
|
2178
|
+
case "message_start": {
|
|
2179
|
+
__classPrivateFieldSet(this, _BetaMessageStream_currentMessageSnapshot, messageSnapshot, "f");
|
|
2180
|
+
break;
|
|
2181
|
+
}
|
|
2182
|
+
case "content_block_start":
|
|
2183
|
+
case "message_delta":
|
|
2184
|
+
break;
|
|
2185
|
+
}
|
|
2186
|
+
}, _BetaMessageStream_endRequest = function _BetaMessageStream_endRequest2() {
|
|
2187
|
+
if (this.ended) {
|
|
2188
|
+
throw new AnthropicError(`stream has ended, this shouldn't happen`);
|
|
2189
|
+
}
|
|
2190
|
+
const snapshot = __classPrivateFieldGet(this, _BetaMessageStream_currentMessageSnapshot, "f");
|
|
2191
|
+
if (!snapshot) {
|
|
2192
|
+
throw new AnthropicError(`request ended without sending any chunks`);
|
|
2193
|
+
}
|
|
2194
|
+
__classPrivateFieldSet(this, _BetaMessageStream_currentMessageSnapshot, undefined, "f");
|
|
2195
|
+
return maybeParseBetaMessage(snapshot, __classPrivateFieldGet(this, _BetaMessageStream_params, "f"), { logger: __classPrivateFieldGet(this, _BetaMessageStream_logger, "f") });
|
|
2196
|
+
}, _BetaMessageStream_accumulateMessage = function _BetaMessageStream_accumulateMessage2(event) {
|
|
2197
|
+
let snapshot = __classPrivateFieldGet(this, _BetaMessageStream_currentMessageSnapshot, "f");
|
|
2198
|
+
if (event.type === "message_start") {
|
|
2199
|
+
if (snapshot) {
|
|
2200
|
+
throw new AnthropicError(`Unexpected event order, got ${event.type} before receiving "message_stop"`);
|
|
2201
|
+
}
|
|
2202
|
+
return event.message;
|
|
2203
|
+
}
|
|
2204
|
+
if (!snapshot) {
|
|
2205
|
+
throw new AnthropicError(`Unexpected event order, got ${event.type} before "message_start"`);
|
|
2206
|
+
}
|
|
2207
|
+
switch (event.type) {
|
|
2208
|
+
case "message_stop":
|
|
2209
|
+
return snapshot;
|
|
2210
|
+
case "message_delta":
|
|
2211
|
+
snapshot.container = event.delta.container;
|
|
2212
|
+
snapshot.stop_reason = event.delta.stop_reason;
|
|
2213
|
+
snapshot.stop_sequence = event.delta.stop_sequence;
|
|
2214
|
+
snapshot.usage.output_tokens = event.usage.output_tokens;
|
|
2215
|
+
snapshot.context_management = event.context_management;
|
|
2216
|
+
if (event.usage.input_tokens != null) {
|
|
2217
|
+
snapshot.usage.input_tokens = event.usage.input_tokens;
|
|
2218
|
+
}
|
|
2219
|
+
if (event.usage.cache_creation_input_tokens != null) {
|
|
2220
|
+
snapshot.usage.cache_creation_input_tokens = event.usage.cache_creation_input_tokens;
|
|
2221
|
+
}
|
|
2222
|
+
if (event.usage.cache_read_input_tokens != null) {
|
|
2223
|
+
snapshot.usage.cache_read_input_tokens = event.usage.cache_read_input_tokens;
|
|
2224
|
+
}
|
|
2225
|
+
if (event.usage.server_tool_use != null) {
|
|
2226
|
+
snapshot.usage.server_tool_use = event.usage.server_tool_use;
|
|
2227
|
+
}
|
|
2228
|
+
if (event.usage.iterations != null) {
|
|
2229
|
+
snapshot.usage.iterations = event.usage.iterations;
|
|
2230
|
+
}
|
|
2231
|
+
return snapshot;
|
|
2232
|
+
case "content_block_start":
|
|
2233
|
+
snapshot.content.push(event.content_block);
|
|
2234
|
+
return snapshot;
|
|
2235
|
+
case "content_block_delta": {
|
|
2236
|
+
const snapshotContent = snapshot.content.at(event.index);
|
|
2237
|
+
switch (event.delta.type) {
|
|
2238
|
+
case "text_delta": {
|
|
2239
|
+
if (snapshotContent?.type === "text") {
|
|
2240
|
+
snapshot.content[event.index] = {
|
|
2241
|
+
...snapshotContent,
|
|
2242
|
+
text: (snapshotContent.text || "") + event.delta.text
|
|
2243
|
+
};
|
|
2244
|
+
}
|
|
2245
|
+
break;
|
|
2246
|
+
}
|
|
2247
|
+
case "citations_delta": {
|
|
2248
|
+
if (snapshotContent?.type === "text") {
|
|
2249
|
+
snapshot.content[event.index] = {
|
|
2250
|
+
...snapshotContent,
|
|
2251
|
+
citations: [...snapshotContent.citations ?? [], event.delta.citation]
|
|
2252
|
+
};
|
|
2253
|
+
}
|
|
2254
|
+
break;
|
|
2255
|
+
}
|
|
2256
|
+
case "input_json_delta": {
|
|
2257
|
+
if (snapshotContent && tracksToolInput(snapshotContent)) {
|
|
2258
|
+
let jsonBuf = snapshotContent[JSON_BUF_PROPERTY] || "";
|
|
2259
|
+
jsonBuf += event.delta.partial_json;
|
|
2260
|
+
const newContent = { ...snapshotContent };
|
|
2261
|
+
Object.defineProperty(newContent, JSON_BUF_PROPERTY, {
|
|
2262
|
+
value: jsonBuf,
|
|
2263
|
+
enumerable: false,
|
|
2264
|
+
writable: true
|
|
2265
|
+
});
|
|
2266
|
+
if (jsonBuf) {
|
|
2267
|
+
try {
|
|
2268
|
+
newContent.input = partialParse(jsonBuf);
|
|
2269
|
+
} catch (err) {
|
|
2270
|
+
const error2 = new AnthropicError(`Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt. Error: ${err}. JSON: ${jsonBuf}`);
|
|
2271
|
+
__classPrivateFieldGet(this, _BetaMessageStream_handleError, "f").call(this, error2);
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
snapshot.content[event.index] = newContent;
|
|
2275
|
+
}
|
|
2276
|
+
break;
|
|
2277
|
+
}
|
|
2278
|
+
case "thinking_delta": {
|
|
2279
|
+
if (snapshotContent?.type === "thinking") {
|
|
2280
|
+
snapshot.content[event.index] = {
|
|
2281
|
+
...snapshotContent,
|
|
2282
|
+
thinking: snapshotContent.thinking + event.delta.thinking
|
|
2283
|
+
};
|
|
2284
|
+
}
|
|
2285
|
+
break;
|
|
2286
|
+
}
|
|
2287
|
+
case "signature_delta": {
|
|
2288
|
+
if (snapshotContent?.type === "thinking") {
|
|
2289
|
+
snapshot.content[event.index] = {
|
|
2290
|
+
...snapshotContent,
|
|
2291
|
+
signature: event.delta.signature
|
|
2292
|
+
};
|
|
2293
|
+
}
|
|
2294
|
+
break;
|
|
2295
|
+
}
|
|
2296
|
+
case "compaction_delta": {
|
|
2297
|
+
if (snapshotContent?.type === "compaction") {
|
|
2298
|
+
snapshot.content[event.index] = {
|
|
2299
|
+
...snapshotContent,
|
|
2300
|
+
content: (snapshotContent.content || "") + event.delta.content
|
|
2301
|
+
};
|
|
2302
|
+
}
|
|
2303
|
+
break;
|
|
2304
|
+
}
|
|
2305
|
+
default:
|
|
2306
|
+
checkNever(event.delta);
|
|
2307
|
+
}
|
|
2308
|
+
return snapshot;
|
|
2309
|
+
}
|
|
2310
|
+
case "content_block_stop":
|
|
2311
|
+
return snapshot;
|
|
2312
|
+
}
|
|
2313
|
+
}, Symbol.asyncIterator)]() {
|
|
2314
|
+
const pushQueue = [];
|
|
2315
|
+
const readQueue = [];
|
|
2316
|
+
let done = false;
|
|
2317
|
+
this.on("streamEvent", (event) => {
|
|
2318
|
+
const reader = readQueue.shift();
|
|
2319
|
+
if (reader) {
|
|
2320
|
+
reader.resolve(event);
|
|
2321
|
+
} else {
|
|
2322
|
+
pushQueue.push(event);
|
|
2323
|
+
}
|
|
2324
|
+
});
|
|
2325
|
+
this.on("end", () => {
|
|
2326
|
+
done = true;
|
|
2327
|
+
for (const reader of readQueue) {
|
|
2328
|
+
reader.resolve(undefined);
|
|
2329
|
+
}
|
|
2330
|
+
readQueue.length = 0;
|
|
2331
|
+
});
|
|
2332
|
+
this.on("abort", (err) => {
|
|
2333
|
+
done = true;
|
|
2334
|
+
for (const reader of readQueue) {
|
|
2335
|
+
reader.reject(err);
|
|
2336
|
+
}
|
|
2337
|
+
readQueue.length = 0;
|
|
2338
|
+
});
|
|
2339
|
+
this.on("error", (err) => {
|
|
2340
|
+
done = true;
|
|
2341
|
+
for (const reader of readQueue) {
|
|
2342
|
+
reader.reject(err);
|
|
2343
|
+
}
|
|
2344
|
+
readQueue.length = 0;
|
|
2345
|
+
});
|
|
2346
|
+
return {
|
|
2347
|
+
next: async () => {
|
|
2348
|
+
if (!pushQueue.length) {
|
|
2349
|
+
if (done) {
|
|
2350
|
+
return { value: undefined, done: true };
|
|
2351
|
+
}
|
|
2352
|
+
return new Promise((resolve, reject) => readQueue.push({ resolve, reject })).then((chunk2) => chunk2 ? { value: chunk2, done: false } : { value: undefined, done: true });
|
|
2353
|
+
}
|
|
2354
|
+
const chunk = pushQueue.shift();
|
|
2355
|
+
return { value: chunk, done: false };
|
|
2356
|
+
},
|
|
2357
|
+
return: async () => {
|
|
2358
|
+
this.abort();
|
|
2359
|
+
return { value: undefined, done: true };
|
|
2360
|
+
}
|
|
2361
|
+
};
|
|
2362
|
+
}
|
|
2363
|
+
toReadableStream() {
|
|
2364
|
+
const stream = new Stream(this[Symbol.asyncIterator].bind(this), this.controller);
|
|
2365
|
+
return stream.toReadableStream();
|
|
2366
|
+
}
|
|
2367
|
+
};
|
|
2368
|
+
});
|
|
2369
|
+
|
|
2370
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/lib/tools/ToolError.mjs
|
|
2371
|
+
var ToolError;
|
|
2372
|
+
var init_ToolError = __esm(() => {
|
|
2373
|
+
ToolError = class ToolError extends Error {
|
|
2374
|
+
constructor(content) {
|
|
2375
|
+
const message = typeof content === "string" ? content : content.map((block) => {
|
|
2376
|
+
if (block.type === "text")
|
|
2377
|
+
return block.text;
|
|
2378
|
+
return `[${block.type}]`;
|
|
2379
|
+
}).join(" ");
|
|
2380
|
+
super(message);
|
|
2381
|
+
this.name = "ToolError";
|
|
2382
|
+
this.content = content;
|
|
2383
|
+
}
|
|
2384
|
+
};
|
|
2385
|
+
});
|
|
2386
|
+
|
|
2387
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/lib/tools/CompactionControl.mjs
|
|
2388
|
+
var DEFAULT_TOKEN_THRESHOLD = 1e5, DEFAULT_SUMMARY_PROMPT = `You have been working on the task described above but have not yet completed it. Write a continuation summary that will allow you (or another instance of yourself) to resume work efficiently in a future context window where the conversation history will be replaced with this summary. Your summary should be structured, concise, and actionable. Include:
|
|
2389
|
+
1. Task Overview
|
|
2390
|
+
The user's core request and success criteria
|
|
2391
|
+
Any clarifications or constraints they specified
|
|
2392
|
+
2. Current State
|
|
2393
|
+
What has been completed so far
|
|
2394
|
+
Files created, modified, or analyzed (with paths if relevant)
|
|
2395
|
+
Key outputs or artifacts produced
|
|
2396
|
+
3. Important Discoveries
|
|
2397
|
+
Technical constraints or requirements uncovered
|
|
2398
|
+
Decisions made and their rationale
|
|
2399
|
+
Errors encountered and how they were resolved
|
|
2400
|
+
What approaches were tried that didn't work (and why)
|
|
2401
|
+
4. Next Steps
|
|
2402
|
+
Specific actions needed to complete the task
|
|
2403
|
+
Any blockers or open questions to resolve
|
|
2404
|
+
Priority order if multiple steps remain
|
|
2405
|
+
5. Context to Preserve
|
|
2406
|
+
User preferences or style requirements
|
|
2407
|
+
Domain-specific details that aren't obvious
|
|
2408
|
+
Any promises made to the user
|
|
2409
|
+
Be concise but complete\u2014err on the side of including information that would prevent duplicate work or repeated mistakes. Write in a way that enables immediate resumption of the task.
|
|
2410
|
+
Wrap your summary in <summary></summary> tags.`;
|
|
2411
|
+
var init_CompactionControl = () => {};
|
|
2412
|
+
|
|
2413
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/lib/tools/BetaToolRunner.mjs
|
|
2414
|
+
function promiseWithResolvers() {
|
|
2415
|
+
let resolve;
|
|
2416
|
+
let reject;
|
|
2417
|
+
const promise = new Promise((res, rej) => {
|
|
2418
|
+
resolve = res;
|
|
2419
|
+
reject = rej;
|
|
2420
|
+
});
|
|
2421
|
+
return { promise, resolve, reject };
|
|
2422
|
+
}
|
|
2423
|
+
async function generateToolResponse(params, lastMessage = params.messages.at(-1)) {
|
|
2424
|
+
if (!lastMessage || lastMessage.role !== "assistant" || !lastMessage.content || typeof lastMessage.content === "string") {
|
|
2425
|
+
return null;
|
|
2426
|
+
}
|
|
2427
|
+
const toolUseBlocks = lastMessage.content.filter((content) => content.type === "tool_use");
|
|
2428
|
+
if (toolUseBlocks.length === 0) {
|
|
2429
|
+
return null;
|
|
2430
|
+
}
|
|
2431
|
+
const toolResults = await Promise.all(toolUseBlocks.map(async (toolUse) => {
|
|
2432
|
+
const tool = params.tools.find((t) => ("name" in t ? t.name : t.mcp_server_name) === toolUse.name);
|
|
2433
|
+
if (!tool || !("run" in tool)) {
|
|
2434
|
+
return {
|
|
2435
|
+
type: "tool_result",
|
|
2436
|
+
tool_use_id: toolUse.id,
|
|
2437
|
+
content: `Error: Tool '${toolUse.name}' not found`,
|
|
2438
|
+
is_error: true
|
|
2439
|
+
};
|
|
2440
|
+
}
|
|
2441
|
+
try {
|
|
2442
|
+
let input = toolUse.input;
|
|
2443
|
+
if ("parse" in tool && tool.parse) {
|
|
2444
|
+
input = tool.parse(input);
|
|
2445
|
+
}
|
|
2446
|
+
const result = await tool.run(input);
|
|
2447
|
+
return {
|
|
2448
|
+
type: "tool_result",
|
|
2449
|
+
tool_use_id: toolUse.id,
|
|
2450
|
+
content: result
|
|
2451
|
+
};
|
|
2452
|
+
} catch (error2) {
|
|
2453
|
+
return {
|
|
2454
|
+
type: "tool_result",
|
|
2455
|
+
tool_use_id: toolUse.id,
|
|
2456
|
+
content: error2 instanceof ToolError ? error2.content : `Error: ${error2 instanceof Error ? error2.message : String(error2)}`,
|
|
2457
|
+
is_error: true
|
|
2458
|
+
};
|
|
2459
|
+
}
|
|
2460
|
+
}));
|
|
2461
|
+
return {
|
|
2462
|
+
role: "user",
|
|
2463
|
+
content: toolResults
|
|
2464
|
+
};
|
|
2465
|
+
}
|
|
2466
|
+
var _BetaToolRunner_instances, _BetaToolRunner_consumed, _BetaToolRunner_mutated, _BetaToolRunner_state, _BetaToolRunner_options, _BetaToolRunner_message, _BetaToolRunner_toolResponse, _BetaToolRunner_completion, _BetaToolRunner_iterationCount, _BetaToolRunner_checkAndCompact, _BetaToolRunner_generateToolResponse, BetaToolRunner;
|
|
2467
|
+
var init_BetaToolRunner = __esm(() => {
|
|
2468
|
+
init_tslib();
|
|
2469
|
+
init_ToolError();
|
|
2470
|
+
init_error();
|
|
2471
|
+
init_headers();
|
|
2472
|
+
init_CompactionControl();
|
|
2473
|
+
init_stainless_helper_header();
|
|
2474
|
+
BetaToolRunner = class BetaToolRunner {
|
|
2475
|
+
constructor(client, params, options) {
|
|
2476
|
+
_BetaToolRunner_instances.add(this);
|
|
2477
|
+
this.client = client;
|
|
2478
|
+
_BetaToolRunner_consumed.set(this, false);
|
|
2479
|
+
_BetaToolRunner_mutated.set(this, false);
|
|
2480
|
+
_BetaToolRunner_state.set(this, undefined);
|
|
2481
|
+
_BetaToolRunner_options.set(this, undefined);
|
|
2482
|
+
_BetaToolRunner_message.set(this, undefined);
|
|
2483
|
+
_BetaToolRunner_toolResponse.set(this, undefined);
|
|
2484
|
+
_BetaToolRunner_completion.set(this, undefined);
|
|
2485
|
+
_BetaToolRunner_iterationCount.set(this, 0);
|
|
2486
|
+
__classPrivateFieldSet(this, _BetaToolRunner_state, {
|
|
2487
|
+
params: {
|
|
2488
|
+
...params,
|
|
2489
|
+
messages: structuredClone(params.messages)
|
|
2490
|
+
}
|
|
2491
|
+
}, "f");
|
|
2492
|
+
const helpers = collectStainlessHelpers(params.tools, params.messages);
|
|
2493
|
+
const helperValue = ["BetaToolRunner", ...helpers].join(", ");
|
|
2494
|
+
__classPrivateFieldSet(this, _BetaToolRunner_options, {
|
|
2495
|
+
...options,
|
|
2496
|
+
headers: buildHeaders([{ "x-stainless-helper": helperValue }, options?.headers])
|
|
2497
|
+
}, "f");
|
|
2498
|
+
__classPrivateFieldSet(this, _BetaToolRunner_completion, promiseWithResolvers(), "f");
|
|
2499
|
+
}
|
|
2500
|
+
async* [(_BetaToolRunner_consumed = new WeakMap, _BetaToolRunner_mutated = new WeakMap, _BetaToolRunner_state = new WeakMap, _BetaToolRunner_options = new WeakMap, _BetaToolRunner_message = new WeakMap, _BetaToolRunner_toolResponse = new WeakMap, _BetaToolRunner_completion = new WeakMap, _BetaToolRunner_iterationCount = new WeakMap, _BetaToolRunner_instances = new WeakSet, _BetaToolRunner_checkAndCompact = async function _BetaToolRunner_checkAndCompact2() {
|
|
2501
|
+
const compactionControl = __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.compactionControl;
|
|
2502
|
+
if (!compactionControl || !compactionControl.enabled) {
|
|
2503
|
+
return false;
|
|
2504
|
+
}
|
|
2505
|
+
let tokensUsed = 0;
|
|
2506
|
+
if (__classPrivateFieldGet(this, _BetaToolRunner_message, "f") !== undefined) {
|
|
2507
|
+
try {
|
|
2508
|
+
const message = await __classPrivateFieldGet(this, _BetaToolRunner_message, "f");
|
|
2509
|
+
const totalInputTokens = message.usage.input_tokens + (message.usage.cache_creation_input_tokens ?? 0) + (message.usage.cache_read_input_tokens ?? 0);
|
|
2510
|
+
tokensUsed = totalInputTokens + message.usage.output_tokens;
|
|
2511
|
+
} catch {
|
|
2512
|
+
return false;
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
const threshold = compactionControl.contextTokenThreshold ?? DEFAULT_TOKEN_THRESHOLD;
|
|
2516
|
+
if (tokensUsed < threshold) {
|
|
2517
|
+
return false;
|
|
2518
|
+
}
|
|
2519
|
+
const model = compactionControl.model ?? __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.model;
|
|
2520
|
+
const summaryPrompt = compactionControl.summaryPrompt ?? DEFAULT_SUMMARY_PROMPT;
|
|
2521
|
+
const messages = __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages;
|
|
2522
|
+
if (messages[messages.length - 1].role === "assistant") {
|
|
2523
|
+
const lastMessage = messages[messages.length - 1];
|
|
2524
|
+
if (Array.isArray(lastMessage.content)) {
|
|
2525
|
+
const nonToolBlocks = lastMessage.content.filter((block) => block.type !== "tool_use");
|
|
2526
|
+
if (nonToolBlocks.length === 0) {
|
|
2527
|
+
messages.pop();
|
|
2528
|
+
} else {
|
|
2529
|
+
lastMessage.content = nonToolBlocks;
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
const response = await this.client.beta.messages.create({
|
|
2534
|
+
model,
|
|
2535
|
+
messages: [
|
|
2536
|
+
...messages,
|
|
2537
|
+
{
|
|
2538
|
+
role: "user",
|
|
2539
|
+
content: [
|
|
2540
|
+
{
|
|
2541
|
+
type: "text",
|
|
2542
|
+
text: summaryPrompt
|
|
2543
|
+
}
|
|
2544
|
+
]
|
|
2545
|
+
}
|
|
2546
|
+
],
|
|
2547
|
+
max_tokens: __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.max_tokens
|
|
2548
|
+
}, {
|
|
2549
|
+
headers: { "x-stainless-helper": "compaction" }
|
|
2550
|
+
});
|
|
2551
|
+
if (response.content[0]?.type !== "text") {
|
|
2552
|
+
throw new AnthropicError("Expected text response for compaction");
|
|
2553
|
+
}
|
|
2554
|
+
__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages = [
|
|
2555
|
+
{
|
|
2556
|
+
role: "user",
|
|
2557
|
+
content: response.content
|
|
2558
|
+
}
|
|
2559
|
+
];
|
|
2560
|
+
return true;
|
|
2561
|
+
}, Symbol.asyncIterator)]() {
|
|
2562
|
+
var _a;
|
|
2563
|
+
if (__classPrivateFieldGet(this, _BetaToolRunner_consumed, "f")) {
|
|
2564
|
+
throw new AnthropicError("Cannot iterate over a consumed stream");
|
|
2565
|
+
}
|
|
2566
|
+
__classPrivateFieldSet(this, _BetaToolRunner_consumed, true, "f");
|
|
2567
|
+
__classPrivateFieldSet(this, _BetaToolRunner_mutated, true, "f");
|
|
2568
|
+
__classPrivateFieldSet(this, _BetaToolRunner_toolResponse, undefined, "f");
|
|
2569
|
+
try {
|
|
2570
|
+
while (true) {
|
|
2571
|
+
let stream;
|
|
2572
|
+
try {
|
|
2573
|
+
if (__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.max_iterations && __classPrivateFieldGet(this, _BetaToolRunner_iterationCount, "f") >= __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.max_iterations) {
|
|
2574
|
+
break;
|
|
2575
|
+
}
|
|
2576
|
+
__classPrivateFieldSet(this, _BetaToolRunner_mutated, false, "f");
|
|
2577
|
+
__classPrivateFieldSet(this, _BetaToolRunner_toolResponse, undefined, "f");
|
|
2578
|
+
__classPrivateFieldSet(this, _BetaToolRunner_iterationCount, (_a = __classPrivateFieldGet(this, _BetaToolRunner_iterationCount, "f"), _a++, _a), "f");
|
|
2579
|
+
__classPrivateFieldSet(this, _BetaToolRunner_message, undefined, "f");
|
|
2580
|
+
const { max_iterations, compactionControl, ...params } = __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params;
|
|
2581
|
+
if (params.stream) {
|
|
2582
|
+
stream = this.client.beta.messages.stream({ ...params }, __classPrivateFieldGet(this, _BetaToolRunner_options, "f"));
|
|
2583
|
+
__classPrivateFieldSet(this, _BetaToolRunner_message, stream.finalMessage(), "f");
|
|
2584
|
+
__classPrivateFieldGet(this, _BetaToolRunner_message, "f").catch(() => {});
|
|
2585
|
+
yield stream;
|
|
2586
|
+
} else {
|
|
2587
|
+
__classPrivateFieldSet(this, _BetaToolRunner_message, this.client.beta.messages.create({ ...params, stream: false }, __classPrivateFieldGet(this, _BetaToolRunner_options, "f")), "f");
|
|
2588
|
+
yield __classPrivateFieldGet(this, _BetaToolRunner_message, "f");
|
|
2589
|
+
}
|
|
2590
|
+
const isCompacted = await __classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_checkAndCompact).call(this);
|
|
2591
|
+
if (!isCompacted) {
|
|
2592
|
+
if (!__classPrivateFieldGet(this, _BetaToolRunner_mutated, "f")) {
|
|
2593
|
+
const { role, content } = await __classPrivateFieldGet(this, _BetaToolRunner_message, "f");
|
|
2594
|
+
__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages.push({ role, content });
|
|
2595
|
+
}
|
|
2596
|
+
const toolMessage = await __classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_generateToolResponse).call(this, __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages.at(-1));
|
|
2597
|
+
if (toolMessage) {
|
|
2598
|
+
__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages.push(toolMessage);
|
|
2599
|
+
} else if (!__classPrivateFieldGet(this, _BetaToolRunner_mutated, "f")) {
|
|
2600
|
+
break;
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
} finally {
|
|
2604
|
+
if (stream) {
|
|
2605
|
+
stream.abort();
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2609
|
+
if (!__classPrivateFieldGet(this, _BetaToolRunner_message, "f")) {
|
|
2610
|
+
throw new AnthropicError("ToolRunner concluded without a message from the server");
|
|
2611
|
+
}
|
|
2612
|
+
__classPrivateFieldGet(this, _BetaToolRunner_completion, "f").resolve(await __classPrivateFieldGet(this, _BetaToolRunner_message, "f"));
|
|
2613
|
+
} catch (error2) {
|
|
2614
|
+
__classPrivateFieldSet(this, _BetaToolRunner_consumed, false, "f");
|
|
2615
|
+
__classPrivateFieldGet(this, _BetaToolRunner_completion, "f").promise.catch(() => {});
|
|
2616
|
+
__classPrivateFieldGet(this, _BetaToolRunner_completion, "f").reject(error2);
|
|
2617
|
+
__classPrivateFieldSet(this, _BetaToolRunner_completion, promiseWithResolvers(), "f");
|
|
2618
|
+
throw error2;
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
setMessagesParams(paramsOrMutator) {
|
|
2622
|
+
if (typeof paramsOrMutator === "function") {
|
|
2623
|
+
__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params = paramsOrMutator(__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params);
|
|
2624
|
+
} else {
|
|
2625
|
+
__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params = paramsOrMutator;
|
|
2626
|
+
}
|
|
2627
|
+
__classPrivateFieldSet(this, _BetaToolRunner_mutated, true, "f");
|
|
2628
|
+
__classPrivateFieldSet(this, _BetaToolRunner_toolResponse, undefined, "f");
|
|
2629
|
+
}
|
|
2630
|
+
async generateToolResponse() {
|
|
2631
|
+
const message = await __classPrivateFieldGet(this, _BetaToolRunner_message, "f") ?? this.params.messages.at(-1);
|
|
2632
|
+
if (!message) {
|
|
2633
|
+
return null;
|
|
2634
|
+
}
|
|
2635
|
+
return __classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_generateToolResponse).call(this, message);
|
|
2636
|
+
}
|
|
2637
|
+
done() {
|
|
2638
|
+
return __classPrivateFieldGet(this, _BetaToolRunner_completion, "f").promise;
|
|
2639
|
+
}
|
|
2640
|
+
async runUntilDone() {
|
|
2641
|
+
if (!__classPrivateFieldGet(this, _BetaToolRunner_consumed, "f")) {
|
|
2642
|
+
for await (const _ of this) {}
|
|
2643
|
+
}
|
|
2644
|
+
return this.done();
|
|
2645
|
+
}
|
|
2646
|
+
get params() {
|
|
2647
|
+
return __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params;
|
|
2648
|
+
}
|
|
2649
|
+
pushMessages(...messages) {
|
|
2650
|
+
this.setMessagesParams((params) => ({
|
|
2651
|
+
...params,
|
|
2652
|
+
messages: [...params.messages, ...messages]
|
|
2653
|
+
}));
|
|
2654
|
+
}
|
|
2655
|
+
then(onfulfilled, onrejected) {
|
|
2656
|
+
return this.runUntilDone().then(onfulfilled, onrejected);
|
|
2657
|
+
}
|
|
2658
|
+
};
|
|
2659
|
+
_BetaToolRunner_generateToolResponse = async function _BetaToolRunner_generateToolResponse2(lastMessage) {
|
|
2660
|
+
if (__classPrivateFieldGet(this, _BetaToolRunner_toolResponse, "f") !== undefined) {
|
|
2661
|
+
return __classPrivateFieldGet(this, _BetaToolRunner_toolResponse, "f");
|
|
2662
|
+
}
|
|
2663
|
+
__classPrivateFieldSet(this, _BetaToolRunner_toolResponse, generateToolResponse(__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params, lastMessage), "f");
|
|
2664
|
+
return __classPrivateFieldGet(this, _BetaToolRunner_toolResponse, "f");
|
|
2665
|
+
};
|
|
2666
|
+
});
|
|
2667
|
+
|
|
2668
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/decoders/jsonl.mjs
|
|
2669
|
+
var JSONLDecoder;
|
|
2670
|
+
var init_jsonl = __esm(() => {
|
|
2671
|
+
init_error();
|
|
2672
|
+
init_shims();
|
|
2673
|
+
init_line();
|
|
2674
|
+
JSONLDecoder = class JSONLDecoder {
|
|
2675
|
+
constructor(iterator, controller) {
|
|
2676
|
+
this.iterator = iterator;
|
|
2677
|
+
this.controller = controller;
|
|
2678
|
+
}
|
|
2679
|
+
async* decoder() {
|
|
2680
|
+
const lineDecoder = new LineDecoder;
|
|
2681
|
+
for await (const chunk of this.iterator) {
|
|
2682
|
+
for (const line of lineDecoder.decode(chunk)) {
|
|
2683
|
+
yield JSON.parse(line);
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
for (const line of lineDecoder.flush()) {
|
|
2687
|
+
yield JSON.parse(line);
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
[Symbol.asyncIterator]() {
|
|
2691
|
+
return this.decoder();
|
|
2692
|
+
}
|
|
2693
|
+
static fromResponse(response, controller) {
|
|
2694
|
+
if (!response.body) {
|
|
2695
|
+
controller.abort();
|
|
2696
|
+
if (typeof globalThis.navigator !== "undefined" && globalThis.navigator.product === "ReactNative") {
|
|
2697
|
+
throw new AnthropicError(`The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api`);
|
|
2698
|
+
}
|
|
2699
|
+
throw new AnthropicError(`Attempted to iterate over a response with no body`);
|
|
2700
|
+
}
|
|
2701
|
+
return new JSONLDecoder(ReadableStreamToAsyncIterable(response.body), controller);
|
|
2702
|
+
}
|
|
2703
|
+
};
|
|
2704
|
+
});
|
|
2705
|
+
|
|
2706
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/resources/beta/messages/batches.mjs
|
|
2707
|
+
var Batches;
|
|
2708
|
+
var init_batches = __esm(() => {
|
|
2709
|
+
init_resource();
|
|
2710
|
+
init_pagination();
|
|
2711
|
+
init_headers();
|
|
2712
|
+
init_jsonl();
|
|
2713
|
+
init_error2();
|
|
2714
|
+
init_path();
|
|
2715
|
+
Batches = class Batches extends APIResource {
|
|
2716
|
+
create(params, options) {
|
|
2717
|
+
const { betas, ...body } = params;
|
|
2718
|
+
return this._client.post("/v1/messages/batches?beta=true", {
|
|
2719
|
+
body,
|
|
2720
|
+
...options,
|
|
2721
|
+
headers: buildHeaders([
|
|
2722
|
+
{ "anthropic-beta": [...betas ?? [], "message-batches-2024-09-24"].toString() },
|
|
2723
|
+
options?.headers
|
|
2724
|
+
])
|
|
2725
|
+
});
|
|
2726
|
+
}
|
|
2727
|
+
retrieve(messageBatchID, params = {}, options) {
|
|
2728
|
+
const { betas } = params ?? {};
|
|
2729
|
+
return this._client.get(path`/v1/messages/batches/${messageBatchID}?beta=true`, {
|
|
2730
|
+
...options,
|
|
2731
|
+
headers: buildHeaders([
|
|
2732
|
+
{ "anthropic-beta": [...betas ?? [], "message-batches-2024-09-24"].toString() },
|
|
2733
|
+
options?.headers
|
|
2734
|
+
])
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2737
|
+
list(params = {}, options) {
|
|
2738
|
+
const { betas, ...query } = params ?? {};
|
|
2739
|
+
return this._client.getAPIList("/v1/messages/batches?beta=true", Page, {
|
|
2740
|
+
query,
|
|
2741
|
+
...options,
|
|
2742
|
+
headers: buildHeaders([
|
|
2743
|
+
{ "anthropic-beta": [...betas ?? [], "message-batches-2024-09-24"].toString() },
|
|
2744
|
+
options?.headers
|
|
2745
|
+
])
|
|
2746
|
+
});
|
|
2747
|
+
}
|
|
2748
|
+
delete(messageBatchID, params = {}, options) {
|
|
2749
|
+
const { betas } = params ?? {};
|
|
2750
|
+
return this._client.delete(path`/v1/messages/batches/${messageBatchID}?beta=true`, {
|
|
2751
|
+
...options,
|
|
2752
|
+
headers: buildHeaders([
|
|
2753
|
+
{ "anthropic-beta": [...betas ?? [], "message-batches-2024-09-24"].toString() },
|
|
2754
|
+
options?.headers
|
|
2755
|
+
])
|
|
2756
|
+
});
|
|
2757
|
+
}
|
|
2758
|
+
cancel(messageBatchID, params = {}, options) {
|
|
2759
|
+
const { betas } = params ?? {};
|
|
2760
|
+
return this._client.post(path`/v1/messages/batches/${messageBatchID}/cancel?beta=true`, {
|
|
2761
|
+
...options,
|
|
2762
|
+
headers: buildHeaders([
|
|
2763
|
+
{ "anthropic-beta": [...betas ?? [], "message-batches-2024-09-24"].toString() },
|
|
2764
|
+
options?.headers
|
|
2765
|
+
])
|
|
2766
|
+
});
|
|
2767
|
+
}
|
|
2768
|
+
async results(messageBatchID, params = {}, options) {
|
|
2769
|
+
const batch = await this.retrieve(messageBatchID);
|
|
2770
|
+
if (!batch.results_url) {
|
|
2771
|
+
throw new AnthropicError(`No batch \`results_url\`; Has it finished processing? ${batch.processing_status} - ${batch.id}`);
|
|
2772
|
+
}
|
|
2773
|
+
const { betas } = params ?? {};
|
|
2774
|
+
return this._client.get(batch.results_url, {
|
|
2775
|
+
...options,
|
|
2776
|
+
headers: buildHeaders([
|
|
2777
|
+
{
|
|
2778
|
+
"anthropic-beta": [...betas ?? [], "message-batches-2024-09-24"].toString(),
|
|
2779
|
+
Accept: "application/binary"
|
|
2780
|
+
},
|
|
2781
|
+
options?.headers
|
|
2782
|
+
]),
|
|
2783
|
+
stream: true,
|
|
2784
|
+
__binaryResponse: true
|
|
2785
|
+
})._thenUnwrap((_, props) => JSONLDecoder.fromResponse(props.response, props.controller));
|
|
2786
|
+
}
|
|
2787
|
+
};
|
|
2788
|
+
});
|
|
2789
|
+
|
|
2790
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/resources/beta/messages/messages.mjs
|
|
2791
|
+
function transformOutputFormat(params) {
|
|
2792
|
+
if (!params.output_format) {
|
|
2793
|
+
return params;
|
|
2794
|
+
}
|
|
2795
|
+
if (params.output_config?.format) {
|
|
2796
|
+
throw new AnthropicError("Both output_format and output_config.format were provided. " + "Please use only output_config.format (output_format is deprecated).");
|
|
2797
|
+
}
|
|
2798
|
+
const { output_format, ...rest } = params;
|
|
2799
|
+
return {
|
|
2800
|
+
...rest,
|
|
2801
|
+
output_config: {
|
|
2802
|
+
...params.output_config,
|
|
2803
|
+
format: output_format
|
|
2804
|
+
}
|
|
2805
|
+
};
|
|
2806
|
+
}
|
|
2807
|
+
var DEPRECATED_MODELS, MODELS_TO_WARN_WITH_THINKING_ENABLED, Messages;
|
|
2808
|
+
var init_messages = __esm(() => {
|
|
2809
|
+
init_error2();
|
|
2810
|
+
init_resource();
|
|
2811
|
+
init_constants();
|
|
2812
|
+
init_headers();
|
|
2813
|
+
init_stainless_helper_header();
|
|
2814
|
+
init_beta_parser();
|
|
2815
|
+
init_BetaMessageStream();
|
|
2816
|
+
init_BetaToolRunner();
|
|
2817
|
+
init_ToolError();
|
|
2818
|
+
init_batches();
|
|
2819
|
+
init_batches();
|
|
2820
|
+
init_BetaToolRunner();
|
|
2821
|
+
init_ToolError();
|
|
2822
|
+
DEPRECATED_MODELS = {
|
|
2823
|
+
"claude-1.3": "November 6th, 2024",
|
|
2824
|
+
"claude-1.3-100k": "November 6th, 2024",
|
|
2825
|
+
"claude-instant-1.1": "November 6th, 2024",
|
|
2826
|
+
"claude-instant-1.1-100k": "November 6th, 2024",
|
|
2827
|
+
"claude-instant-1.2": "November 6th, 2024",
|
|
2828
|
+
"claude-3-sonnet-20240229": "July 21st, 2025",
|
|
2829
|
+
"claude-3-opus-20240229": "January 5th, 2026",
|
|
2830
|
+
"claude-2.1": "July 21st, 2025",
|
|
2831
|
+
"claude-2.0": "July 21st, 2025",
|
|
2832
|
+
"claude-3-7-sonnet-latest": "February 19th, 2026",
|
|
2833
|
+
"claude-3-7-sonnet-20250219": "February 19th, 2026"
|
|
2834
|
+
};
|
|
2835
|
+
MODELS_TO_WARN_WITH_THINKING_ENABLED = ["claude-opus-4-6"];
|
|
2836
|
+
Messages = class Messages extends APIResource {
|
|
2837
|
+
constructor() {
|
|
2838
|
+
super(...arguments);
|
|
2839
|
+
this.batches = new Batches(this._client);
|
|
2840
|
+
}
|
|
2841
|
+
create(params, options) {
|
|
2842
|
+
const modifiedParams = transformOutputFormat(params);
|
|
2843
|
+
const { betas, ...body } = modifiedParams;
|
|
2844
|
+
if (body.model in DEPRECATED_MODELS) {
|
|
2845
|
+
console.warn(`The model '${body.model}' is deprecated and will reach end-of-life on ${DEPRECATED_MODELS[body.model]}
|
|
2846
|
+
Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`);
|
|
2847
|
+
}
|
|
2848
|
+
if (body.model in MODELS_TO_WARN_WITH_THINKING_ENABLED && body.thinking && body.thinking.type === "enabled") {
|
|
2849
|
+
console.warn(`Using Claude with ${body.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);
|
|
2850
|
+
}
|
|
2851
|
+
let timeout = this._client._options.timeout;
|
|
2852
|
+
if (!body.stream && timeout == null) {
|
|
2853
|
+
const maxNonstreamingTokens = MODEL_NONSTREAMING_TOKENS[body.model] ?? undefined;
|
|
2854
|
+
timeout = this._client.calculateNonstreamingTimeout(body.max_tokens, maxNonstreamingTokens);
|
|
2855
|
+
}
|
|
2856
|
+
const helperHeader = stainlessHelperHeader(body.tools, body.messages);
|
|
2857
|
+
return this._client.post("/v1/messages?beta=true", {
|
|
2858
|
+
body,
|
|
2859
|
+
timeout: timeout ?? 600000,
|
|
2860
|
+
...options,
|
|
2861
|
+
headers: buildHeaders([
|
|
2862
|
+
{ ...betas?.toString() != null ? { "anthropic-beta": betas?.toString() } : undefined },
|
|
2863
|
+
helperHeader,
|
|
2864
|
+
options?.headers
|
|
2865
|
+
]),
|
|
2866
|
+
stream: modifiedParams.stream ?? false
|
|
2867
|
+
});
|
|
2868
|
+
}
|
|
2869
|
+
parse(params, options) {
|
|
2870
|
+
options = {
|
|
2871
|
+
...options,
|
|
2872
|
+
headers: buildHeaders([
|
|
2873
|
+
{ "anthropic-beta": [...params.betas ?? [], "structured-outputs-2025-12-15"].toString() },
|
|
2874
|
+
options?.headers
|
|
2875
|
+
])
|
|
2876
|
+
};
|
|
2877
|
+
return this.create(params, options).then((message) => parseBetaMessage(message, params, { logger: this._client.logger ?? console }));
|
|
2878
|
+
}
|
|
2879
|
+
stream(body, options) {
|
|
2880
|
+
return BetaMessageStream.createMessage(this, body, options);
|
|
2881
|
+
}
|
|
2882
|
+
countTokens(params, options) {
|
|
2883
|
+
const modifiedParams = transformOutputFormat(params);
|
|
2884
|
+
const { betas, ...body } = modifiedParams;
|
|
2885
|
+
return this._client.post("/v1/messages/count_tokens?beta=true", {
|
|
2886
|
+
body,
|
|
2887
|
+
...options,
|
|
2888
|
+
headers: buildHeaders([
|
|
2889
|
+
{ "anthropic-beta": [...betas ?? [], "token-counting-2024-11-01"].toString() },
|
|
2890
|
+
options?.headers
|
|
2891
|
+
])
|
|
2892
|
+
});
|
|
2893
|
+
}
|
|
2894
|
+
toolRunner(body, options) {
|
|
2895
|
+
return new BetaToolRunner(this._client, body, options);
|
|
2896
|
+
}
|
|
2897
|
+
};
|
|
2898
|
+
Messages.Batches = Batches;
|
|
2899
|
+
Messages.BetaToolRunner = BetaToolRunner;
|
|
2900
|
+
Messages.ToolError = ToolError;
|
|
2901
|
+
});
|
|
2902
|
+
|
|
2903
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/resources/beta/skills/versions.mjs
|
|
2904
|
+
var Versions;
|
|
2905
|
+
var init_versions = __esm(() => {
|
|
2906
|
+
init_resource();
|
|
2907
|
+
init_pagination();
|
|
2908
|
+
init_headers();
|
|
2909
|
+
init_uploads();
|
|
2910
|
+
init_path();
|
|
2911
|
+
Versions = class Versions extends APIResource {
|
|
2912
|
+
create(skillID, params = {}, options) {
|
|
2913
|
+
const { betas, ...body } = params ?? {};
|
|
2914
|
+
return this._client.post(path`/v1/skills/${skillID}/versions?beta=true`, multipartFormRequestOptions({
|
|
2915
|
+
body,
|
|
2916
|
+
...options,
|
|
2917
|
+
headers: buildHeaders([
|
|
2918
|
+
{ "anthropic-beta": [...betas ?? [], "skills-2025-10-02"].toString() },
|
|
2919
|
+
options?.headers
|
|
2920
|
+
])
|
|
2921
|
+
}, this._client));
|
|
2922
|
+
}
|
|
2923
|
+
retrieve(version, params, options) {
|
|
2924
|
+
const { skill_id, betas } = params;
|
|
2925
|
+
return this._client.get(path`/v1/skills/${skill_id}/versions/${version}?beta=true`, {
|
|
2926
|
+
...options,
|
|
2927
|
+
headers: buildHeaders([
|
|
2928
|
+
{ "anthropic-beta": [...betas ?? [], "skills-2025-10-02"].toString() },
|
|
2929
|
+
options?.headers
|
|
2930
|
+
])
|
|
2931
|
+
});
|
|
2932
|
+
}
|
|
2933
|
+
list(skillID, params = {}, options) {
|
|
2934
|
+
const { betas, ...query } = params ?? {};
|
|
2935
|
+
return this._client.getAPIList(path`/v1/skills/${skillID}/versions?beta=true`, PageCursor, {
|
|
2936
|
+
query,
|
|
2937
|
+
...options,
|
|
2938
|
+
headers: buildHeaders([
|
|
2939
|
+
{ "anthropic-beta": [...betas ?? [], "skills-2025-10-02"].toString() },
|
|
2940
|
+
options?.headers
|
|
2941
|
+
])
|
|
2942
|
+
});
|
|
2943
|
+
}
|
|
2944
|
+
delete(version, params, options) {
|
|
2945
|
+
const { skill_id, betas } = params;
|
|
2946
|
+
return this._client.delete(path`/v1/skills/${skill_id}/versions/${version}?beta=true`, {
|
|
2947
|
+
...options,
|
|
2948
|
+
headers: buildHeaders([
|
|
2949
|
+
{ "anthropic-beta": [...betas ?? [], "skills-2025-10-02"].toString() },
|
|
2950
|
+
options?.headers
|
|
2951
|
+
])
|
|
2952
|
+
});
|
|
2953
|
+
}
|
|
2954
|
+
};
|
|
2955
|
+
});
|
|
2956
|
+
|
|
2957
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/resources/beta/skills/skills.mjs
|
|
2958
|
+
var Skills;
|
|
2959
|
+
var init_skills = __esm(() => {
|
|
2960
|
+
init_resource();
|
|
2961
|
+
init_versions();
|
|
2962
|
+
init_versions();
|
|
2963
|
+
init_pagination();
|
|
2964
|
+
init_headers();
|
|
2965
|
+
init_uploads();
|
|
2966
|
+
init_path();
|
|
2967
|
+
Skills = class Skills extends APIResource {
|
|
2968
|
+
constructor() {
|
|
2969
|
+
super(...arguments);
|
|
2970
|
+
this.versions = new Versions(this._client);
|
|
2971
|
+
}
|
|
2972
|
+
create(params = {}, options) {
|
|
2973
|
+
const { betas, ...body } = params ?? {};
|
|
2974
|
+
return this._client.post("/v1/skills?beta=true", multipartFormRequestOptions({
|
|
2975
|
+
body,
|
|
2976
|
+
...options,
|
|
2977
|
+
headers: buildHeaders([
|
|
2978
|
+
{ "anthropic-beta": [...betas ?? [], "skills-2025-10-02"].toString() },
|
|
2979
|
+
options?.headers
|
|
2980
|
+
])
|
|
2981
|
+
}, this._client, false));
|
|
2982
|
+
}
|
|
2983
|
+
retrieve(skillID, params = {}, options) {
|
|
2984
|
+
const { betas } = params ?? {};
|
|
2985
|
+
return this._client.get(path`/v1/skills/${skillID}?beta=true`, {
|
|
2986
|
+
...options,
|
|
2987
|
+
headers: buildHeaders([
|
|
2988
|
+
{ "anthropic-beta": [...betas ?? [], "skills-2025-10-02"].toString() },
|
|
2989
|
+
options?.headers
|
|
2990
|
+
])
|
|
2991
|
+
});
|
|
2992
|
+
}
|
|
2993
|
+
list(params = {}, options) {
|
|
2994
|
+
const { betas, ...query } = params ?? {};
|
|
2995
|
+
return this._client.getAPIList("/v1/skills?beta=true", PageCursor, {
|
|
2996
|
+
query,
|
|
2997
|
+
...options,
|
|
2998
|
+
headers: buildHeaders([
|
|
2999
|
+
{ "anthropic-beta": [...betas ?? [], "skills-2025-10-02"].toString() },
|
|
3000
|
+
options?.headers
|
|
3001
|
+
])
|
|
3002
|
+
});
|
|
3003
|
+
}
|
|
3004
|
+
delete(skillID, params = {}, options) {
|
|
3005
|
+
const { betas } = params ?? {};
|
|
3006
|
+
return this._client.delete(path`/v1/skills/${skillID}?beta=true`, {
|
|
3007
|
+
...options,
|
|
3008
|
+
headers: buildHeaders([
|
|
3009
|
+
{ "anthropic-beta": [...betas ?? [], "skills-2025-10-02"].toString() },
|
|
3010
|
+
options?.headers
|
|
3011
|
+
])
|
|
3012
|
+
});
|
|
3013
|
+
}
|
|
3014
|
+
};
|
|
3015
|
+
Skills.Versions = Versions;
|
|
3016
|
+
});
|
|
3017
|
+
|
|
3018
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/resources/beta/beta.mjs
|
|
3019
|
+
var Beta;
|
|
3020
|
+
var init_beta = __esm(() => {
|
|
3021
|
+
init_resource();
|
|
3022
|
+
init_files();
|
|
3023
|
+
init_files();
|
|
3024
|
+
init_models();
|
|
3025
|
+
init_models();
|
|
3026
|
+
init_messages();
|
|
3027
|
+
init_messages();
|
|
3028
|
+
init_skills();
|
|
3029
|
+
init_skills();
|
|
3030
|
+
Beta = class Beta extends APIResource {
|
|
3031
|
+
constructor() {
|
|
3032
|
+
super(...arguments);
|
|
3033
|
+
this.models = new Models(this._client);
|
|
3034
|
+
this.messages = new Messages(this._client);
|
|
3035
|
+
this.files = new Files(this._client);
|
|
3036
|
+
this.skills = new Skills(this._client);
|
|
3037
|
+
}
|
|
3038
|
+
};
|
|
3039
|
+
Beta.Models = Models;
|
|
3040
|
+
Beta.Messages = Messages;
|
|
3041
|
+
Beta.Files = Files;
|
|
3042
|
+
Beta.Skills = Skills;
|
|
3043
|
+
});
|
|
3044
|
+
|
|
3045
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/resources/completions.mjs
|
|
3046
|
+
var Completions;
|
|
3047
|
+
var init_completions = __esm(() => {
|
|
3048
|
+
init_resource();
|
|
3049
|
+
init_headers();
|
|
3050
|
+
Completions = class Completions extends APIResource {
|
|
3051
|
+
create(params, options) {
|
|
3052
|
+
const { betas, ...body } = params;
|
|
3053
|
+
return this._client.post("/v1/complete", {
|
|
3054
|
+
body,
|
|
3055
|
+
timeout: this._client._options.timeout ?? 600000,
|
|
3056
|
+
...options,
|
|
3057
|
+
headers: buildHeaders([
|
|
3058
|
+
{ ...betas?.toString() != null ? { "anthropic-beta": betas?.toString() } : undefined },
|
|
3059
|
+
options?.headers
|
|
3060
|
+
]),
|
|
3061
|
+
stream: params.stream ?? false
|
|
3062
|
+
});
|
|
3063
|
+
}
|
|
3064
|
+
};
|
|
3065
|
+
});
|
|
3066
|
+
|
|
3067
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/lib/parser.mjs
|
|
3068
|
+
function getOutputFormat2(params) {
|
|
3069
|
+
return params?.output_config?.format;
|
|
3070
|
+
}
|
|
3071
|
+
function maybeParseMessage(message, params, opts) {
|
|
3072
|
+
const outputFormat = getOutputFormat2(params);
|
|
3073
|
+
if (!params || !("parse" in (outputFormat ?? {}))) {
|
|
3074
|
+
return {
|
|
3075
|
+
...message,
|
|
3076
|
+
content: message.content.map((block) => {
|
|
3077
|
+
if (block.type === "text") {
|
|
3078
|
+
const parsedBlock = Object.defineProperty({ ...block }, "parsed_output", {
|
|
3079
|
+
value: null,
|
|
3080
|
+
enumerable: false
|
|
3081
|
+
});
|
|
3082
|
+
return parsedBlock;
|
|
3083
|
+
}
|
|
3084
|
+
return block;
|
|
3085
|
+
}),
|
|
3086
|
+
parsed_output: null
|
|
3087
|
+
};
|
|
3088
|
+
}
|
|
3089
|
+
return parseMessage(message, params, opts);
|
|
3090
|
+
}
|
|
3091
|
+
function parseMessage(message, params, opts) {
|
|
3092
|
+
let firstParsedOutput = null;
|
|
3093
|
+
const content = message.content.map((block) => {
|
|
3094
|
+
if (block.type === "text") {
|
|
3095
|
+
const parsedOutput = parseOutputFormat(params, block.text);
|
|
3096
|
+
if (firstParsedOutput === null) {
|
|
3097
|
+
firstParsedOutput = parsedOutput;
|
|
3098
|
+
}
|
|
3099
|
+
const parsedBlock = Object.defineProperty({ ...block }, "parsed_output", {
|
|
3100
|
+
value: parsedOutput,
|
|
3101
|
+
enumerable: false
|
|
3102
|
+
});
|
|
3103
|
+
return parsedBlock;
|
|
3104
|
+
}
|
|
3105
|
+
return block;
|
|
3106
|
+
});
|
|
3107
|
+
return {
|
|
3108
|
+
...message,
|
|
3109
|
+
content,
|
|
3110
|
+
parsed_output: firstParsedOutput
|
|
3111
|
+
};
|
|
3112
|
+
}
|
|
3113
|
+
function parseOutputFormat(params, content) {
|
|
3114
|
+
const outputFormat = getOutputFormat2(params);
|
|
3115
|
+
if (outputFormat?.type !== "json_schema") {
|
|
3116
|
+
return null;
|
|
3117
|
+
}
|
|
3118
|
+
try {
|
|
3119
|
+
if ("parse" in outputFormat) {
|
|
3120
|
+
return outputFormat.parse(content);
|
|
3121
|
+
}
|
|
3122
|
+
return JSON.parse(content);
|
|
3123
|
+
} catch (error2) {
|
|
3124
|
+
throw new AnthropicError(`Failed to parse structured output: ${error2}`);
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
var init_parser2 = __esm(() => {
|
|
3128
|
+
init_error();
|
|
3129
|
+
});
|
|
3130
|
+
|
|
3131
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/lib/MessageStream.mjs
|
|
3132
|
+
function tracksToolInput2(content) {
|
|
3133
|
+
return content.type === "tool_use" || content.type === "server_tool_use";
|
|
3134
|
+
}
|
|
3135
|
+
function checkNever2(x) {}
|
|
3136
|
+
var _MessageStream_instances, _MessageStream_currentMessageSnapshot, _MessageStream_params, _MessageStream_connectedPromise, _MessageStream_resolveConnectedPromise, _MessageStream_rejectConnectedPromise, _MessageStream_endPromise, _MessageStream_resolveEndPromise, _MessageStream_rejectEndPromise, _MessageStream_listeners, _MessageStream_ended, _MessageStream_errored, _MessageStream_aborted, _MessageStream_catchingPromiseCreated, _MessageStream_response, _MessageStream_request_id, _MessageStream_logger, _MessageStream_getFinalMessage, _MessageStream_getFinalText, _MessageStream_handleError, _MessageStream_beginRequest, _MessageStream_addStreamEvent, _MessageStream_endRequest, _MessageStream_accumulateMessage, JSON_BUF_PROPERTY2 = "__json_buf", MessageStream;
|
|
3137
|
+
var init_MessageStream = __esm(() => {
|
|
3138
|
+
init_tslib();
|
|
3139
|
+
init_errors();
|
|
3140
|
+
init_error2();
|
|
3141
|
+
init_streaming2();
|
|
3142
|
+
init_parser();
|
|
3143
|
+
init_parser2();
|
|
3144
|
+
MessageStream = class MessageStream {
|
|
3145
|
+
constructor(params, opts) {
|
|
3146
|
+
_MessageStream_instances.add(this);
|
|
3147
|
+
this.messages = [];
|
|
3148
|
+
this.receivedMessages = [];
|
|
3149
|
+
_MessageStream_currentMessageSnapshot.set(this, undefined);
|
|
3150
|
+
_MessageStream_params.set(this, null);
|
|
3151
|
+
this.controller = new AbortController;
|
|
3152
|
+
_MessageStream_connectedPromise.set(this, undefined);
|
|
3153
|
+
_MessageStream_resolveConnectedPromise.set(this, () => {});
|
|
3154
|
+
_MessageStream_rejectConnectedPromise.set(this, () => {});
|
|
3155
|
+
_MessageStream_endPromise.set(this, undefined);
|
|
3156
|
+
_MessageStream_resolveEndPromise.set(this, () => {});
|
|
3157
|
+
_MessageStream_rejectEndPromise.set(this, () => {});
|
|
3158
|
+
_MessageStream_listeners.set(this, {});
|
|
3159
|
+
_MessageStream_ended.set(this, false);
|
|
3160
|
+
_MessageStream_errored.set(this, false);
|
|
3161
|
+
_MessageStream_aborted.set(this, false);
|
|
3162
|
+
_MessageStream_catchingPromiseCreated.set(this, false);
|
|
3163
|
+
_MessageStream_response.set(this, undefined);
|
|
3164
|
+
_MessageStream_request_id.set(this, undefined);
|
|
3165
|
+
_MessageStream_logger.set(this, undefined);
|
|
3166
|
+
_MessageStream_handleError.set(this, (error2) => {
|
|
3167
|
+
__classPrivateFieldSet(this, _MessageStream_errored, true, "f");
|
|
3168
|
+
if (isAbortError(error2)) {
|
|
3169
|
+
error2 = new APIUserAbortError;
|
|
3170
|
+
}
|
|
3171
|
+
if (error2 instanceof APIUserAbortError) {
|
|
3172
|
+
__classPrivateFieldSet(this, _MessageStream_aborted, true, "f");
|
|
3173
|
+
return this._emit("abort", error2);
|
|
3174
|
+
}
|
|
3175
|
+
if (error2 instanceof AnthropicError) {
|
|
3176
|
+
return this._emit("error", error2);
|
|
3177
|
+
}
|
|
3178
|
+
if (error2 instanceof Error) {
|
|
3179
|
+
const anthropicError = new AnthropicError(error2.message);
|
|
3180
|
+
anthropicError.cause = error2;
|
|
3181
|
+
return this._emit("error", anthropicError);
|
|
3182
|
+
}
|
|
3183
|
+
return this._emit("error", new AnthropicError(String(error2)));
|
|
3184
|
+
});
|
|
3185
|
+
__classPrivateFieldSet(this, _MessageStream_connectedPromise, new Promise((resolve, reject) => {
|
|
3186
|
+
__classPrivateFieldSet(this, _MessageStream_resolveConnectedPromise, resolve, "f");
|
|
3187
|
+
__classPrivateFieldSet(this, _MessageStream_rejectConnectedPromise, reject, "f");
|
|
3188
|
+
}), "f");
|
|
3189
|
+
__classPrivateFieldSet(this, _MessageStream_endPromise, new Promise((resolve, reject) => {
|
|
3190
|
+
__classPrivateFieldSet(this, _MessageStream_resolveEndPromise, resolve, "f");
|
|
3191
|
+
__classPrivateFieldSet(this, _MessageStream_rejectEndPromise, reject, "f");
|
|
3192
|
+
}), "f");
|
|
3193
|
+
__classPrivateFieldGet(this, _MessageStream_connectedPromise, "f").catch(() => {});
|
|
3194
|
+
__classPrivateFieldGet(this, _MessageStream_endPromise, "f").catch(() => {});
|
|
3195
|
+
__classPrivateFieldSet(this, _MessageStream_params, params, "f");
|
|
3196
|
+
__classPrivateFieldSet(this, _MessageStream_logger, opts?.logger ?? console, "f");
|
|
3197
|
+
}
|
|
3198
|
+
get response() {
|
|
3199
|
+
return __classPrivateFieldGet(this, _MessageStream_response, "f");
|
|
3200
|
+
}
|
|
3201
|
+
get request_id() {
|
|
3202
|
+
return __classPrivateFieldGet(this, _MessageStream_request_id, "f");
|
|
3203
|
+
}
|
|
3204
|
+
async withResponse() {
|
|
3205
|
+
__classPrivateFieldSet(this, _MessageStream_catchingPromiseCreated, true, "f");
|
|
3206
|
+
const response = await __classPrivateFieldGet(this, _MessageStream_connectedPromise, "f");
|
|
3207
|
+
if (!response) {
|
|
3208
|
+
throw new Error("Could not resolve a `Response` object");
|
|
3209
|
+
}
|
|
3210
|
+
return {
|
|
3211
|
+
data: this,
|
|
3212
|
+
response,
|
|
3213
|
+
request_id: response.headers.get("request-id")
|
|
3214
|
+
};
|
|
3215
|
+
}
|
|
3216
|
+
static fromReadableStream(stream) {
|
|
3217
|
+
const runner = new MessageStream(null);
|
|
3218
|
+
runner._run(() => runner._fromReadableStream(stream));
|
|
3219
|
+
return runner;
|
|
3220
|
+
}
|
|
3221
|
+
static createMessage(messages, params, options, { logger } = {}) {
|
|
3222
|
+
const runner = new MessageStream(params, { logger });
|
|
3223
|
+
for (const message of params.messages) {
|
|
3224
|
+
runner._addMessageParam(message);
|
|
3225
|
+
}
|
|
3226
|
+
__classPrivateFieldSet(runner, _MessageStream_params, { ...params, stream: true }, "f");
|
|
3227
|
+
runner._run(() => runner._createMessage(messages, { ...params, stream: true }, { ...options, headers: { ...options?.headers, "X-Stainless-Helper-Method": "stream" } }));
|
|
3228
|
+
return runner;
|
|
3229
|
+
}
|
|
3230
|
+
_run(executor) {
|
|
3231
|
+
executor().then(() => {
|
|
3232
|
+
this._emitFinal();
|
|
3233
|
+
this._emit("end");
|
|
3234
|
+
}, __classPrivateFieldGet(this, _MessageStream_handleError, "f"));
|
|
3235
|
+
}
|
|
3236
|
+
_addMessageParam(message) {
|
|
3237
|
+
this.messages.push(message);
|
|
3238
|
+
}
|
|
3239
|
+
_addMessage(message, emit = true) {
|
|
3240
|
+
this.receivedMessages.push(message);
|
|
3241
|
+
if (emit) {
|
|
3242
|
+
this._emit("message", message);
|
|
3243
|
+
}
|
|
3244
|
+
}
|
|
3245
|
+
async _createMessage(messages, params, options) {
|
|
3246
|
+
const signal = options?.signal;
|
|
3247
|
+
let abortHandler;
|
|
3248
|
+
if (signal) {
|
|
3249
|
+
if (signal.aborted)
|
|
3250
|
+
this.controller.abort();
|
|
3251
|
+
abortHandler = this.controller.abort.bind(this.controller);
|
|
3252
|
+
signal.addEventListener("abort", abortHandler);
|
|
3253
|
+
}
|
|
3254
|
+
try {
|
|
3255
|
+
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_beginRequest).call(this);
|
|
3256
|
+
const { response, data: stream } = await messages.create({ ...params, stream: true }, { ...options, signal: this.controller.signal }).withResponse();
|
|
3257
|
+
this._connected(response);
|
|
3258
|
+
for await (const event of stream) {
|
|
3259
|
+
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_addStreamEvent).call(this, event);
|
|
3260
|
+
}
|
|
3261
|
+
if (stream.controller.signal?.aborted) {
|
|
3262
|
+
throw new APIUserAbortError;
|
|
3263
|
+
}
|
|
3264
|
+
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_endRequest).call(this);
|
|
3265
|
+
} finally {
|
|
3266
|
+
if (signal && abortHandler) {
|
|
3267
|
+
signal.removeEventListener("abort", abortHandler);
|
|
3268
|
+
}
|
|
3269
|
+
}
|
|
3270
|
+
}
|
|
3271
|
+
_connected(response) {
|
|
3272
|
+
if (this.ended)
|
|
3273
|
+
return;
|
|
3274
|
+
__classPrivateFieldSet(this, _MessageStream_response, response, "f");
|
|
3275
|
+
__classPrivateFieldSet(this, _MessageStream_request_id, response?.headers.get("request-id"), "f");
|
|
3276
|
+
__classPrivateFieldGet(this, _MessageStream_resolveConnectedPromise, "f").call(this, response);
|
|
3277
|
+
this._emit("connect");
|
|
3278
|
+
}
|
|
3279
|
+
get ended() {
|
|
3280
|
+
return __classPrivateFieldGet(this, _MessageStream_ended, "f");
|
|
3281
|
+
}
|
|
3282
|
+
get errored() {
|
|
3283
|
+
return __classPrivateFieldGet(this, _MessageStream_errored, "f");
|
|
3284
|
+
}
|
|
3285
|
+
get aborted() {
|
|
3286
|
+
return __classPrivateFieldGet(this, _MessageStream_aborted, "f");
|
|
3287
|
+
}
|
|
3288
|
+
abort() {
|
|
3289
|
+
this.controller.abort();
|
|
3290
|
+
}
|
|
3291
|
+
on(event, listener) {
|
|
3292
|
+
const listeners = __classPrivateFieldGet(this, _MessageStream_listeners, "f")[event] || (__classPrivateFieldGet(this, _MessageStream_listeners, "f")[event] = []);
|
|
3293
|
+
listeners.push({ listener });
|
|
3294
|
+
return this;
|
|
3295
|
+
}
|
|
3296
|
+
off(event, listener) {
|
|
3297
|
+
const listeners = __classPrivateFieldGet(this, _MessageStream_listeners, "f")[event];
|
|
3298
|
+
if (!listeners)
|
|
3299
|
+
return this;
|
|
3300
|
+
const index = listeners.findIndex((l) => l.listener === listener);
|
|
3301
|
+
if (index >= 0)
|
|
3302
|
+
listeners.splice(index, 1);
|
|
3303
|
+
return this;
|
|
3304
|
+
}
|
|
3305
|
+
once(event, listener) {
|
|
3306
|
+
const listeners = __classPrivateFieldGet(this, _MessageStream_listeners, "f")[event] || (__classPrivateFieldGet(this, _MessageStream_listeners, "f")[event] = []);
|
|
3307
|
+
listeners.push({ listener, once: true });
|
|
3308
|
+
return this;
|
|
3309
|
+
}
|
|
3310
|
+
emitted(event) {
|
|
3311
|
+
return new Promise((resolve, reject) => {
|
|
3312
|
+
__classPrivateFieldSet(this, _MessageStream_catchingPromiseCreated, true, "f");
|
|
3313
|
+
if (event !== "error")
|
|
3314
|
+
this.once("error", reject);
|
|
3315
|
+
this.once(event, resolve);
|
|
3316
|
+
});
|
|
3317
|
+
}
|
|
3318
|
+
async done() {
|
|
3319
|
+
__classPrivateFieldSet(this, _MessageStream_catchingPromiseCreated, true, "f");
|
|
3320
|
+
await __classPrivateFieldGet(this, _MessageStream_endPromise, "f");
|
|
3321
|
+
}
|
|
3322
|
+
get currentMessage() {
|
|
3323
|
+
return __classPrivateFieldGet(this, _MessageStream_currentMessageSnapshot, "f");
|
|
3324
|
+
}
|
|
3325
|
+
async finalMessage() {
|
|
3326
|
+
await this.done();
|
|
3327
|
+
return __classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_getFinalMessage).call(this);
|
|
3328
|
+
}
|
|
3329
|
+
async finalText() {
|
|
3330
|
+
await this.done();
|
|
3331
|
+
return __classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_getFinalText).call(this);
|
|
3332
|
+
}
|
|
3333
|
+
_emit(event, ...args) {
|
|
3334
|
+
if (__classPrivateFieldGet(this, _MessageStream_ended, "f"))
|
|
3335
|
+
return;
|
|
3336
|
+
if (event === "end") {
|
|
3337
|
+
__classPrivateFieldSet(this, _MessageStream_ended, true, "f");
|
|
3338
|
+
__classPrivateFieldGet(this, _MessageStream_resolveEndPromise, "f").call(this);
|
|
3339
|
+
}
|
|
3340
|
+
const listeners = __classPrivateFieldGet(this, _MessageStream_listeners, "f")[event];
|
|
3341
|
+
if (listeners) {
|
|
3342
|
+
__classPrivateFieldGet(this, _MessageStream_listeners, "f")[event] = listeners.filter((l) => !l.once);
|
|
3343
|
+
listeners.forEach(({ listener }) => listener(...args));
|
|
3344
|
+
}
|
|
3345
|
+
if (event === "abort") {
|
|
3346
|
+
const error2 = args[0];
|
|
3347
|
+
if (!__classPrivateFieldGet(this, _MessageStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
|
3348
|
+
Promise.reject(error2);
|
|
3349
|
+
}
|
|
3350
|
+
__classPrivateFieldGet(this, _MessageStream_rejectConnectedPromise, "f").call(this, error2);
|
|
3351
|
+
__classPrivateFieldGet(this, _MessageStream_rejectEndPromise, "f").call(this, error2);
|
|
3352
|
+
this._emit("end");
|
|
3353
|
+
return;
|
|
3354
|
+
}
|
|
3355
|
+
if (event === "error") {
|
|
3356
|
+
const error2 = args[0];
|
|
3357
|
+
if (!__classPrivateFieldGet(this, _MessageStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
|
3358
|
+
Promise.reject(error2);
|
|
3359
|
+
}
|
|
3360
|
+
__classPrivateFieldGet(this, _MessageStream_rejectConnectedPromise, "f").call(this, error2);
|
|
3361
|
+
__classPrivateFieldGet(this, _MessageStream_rejectEndPromise, "f").call(this, error2);
|
|
3362
|
+
this._emit("end");
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
_emitFinal() {
|
|
3366
|
+
const finalMessage = this.receivedMessages.at(-1);
|
|
3367
|
+
if (finalMessage) {
|
|
3368
|
+
this._emit("finalMessage", __classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_getFinalMessage).call(this));
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
async _fromReadableStream(readableStream, options) {
|
|
3372
|
+
const signal = options?.signal;
|
|
3373
|
+
let abortHandler;
|
|
3374
|
+
if (signal) {
|
|
3375
|
+
if (signal.aborted)
|
|
3376
|
+
this.controller.abort();
|
|
3377
|
+
abortHandler = this.controller.abort.bind(this.controller);
|
|
3378
|
+
signal.addEventListener("abort", abortHandler);
|
|
3379
|
+
}
|
|
3380
|
+
try {
|
|
3381
|
+
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_beginRequest).call(this);
|
|
3382
|
+
this._connected(null);
|
|
3383
|
+
const stream = Stream.fromReadableStream(readableStream, this.controller);
|
|
3384
|
+
for await (const event of stream) {
|
|
3385
|
+
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_addStreamEvent).call(this, event);
|
|
3386
|
+
}
|
|
3387
|
+
if (stream.controller.signal?.aborted) {
|
|
3388
|
+
throw new APIUserAbortError;
|
|
3389
|
+
}
|
|
3390
|
+
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_endRequest).call(this);
|
|
3391
|
+
} finally {
|
|
3392
|
+
if (signal && abortHandler) {
|
|
3393
|
+
signal.removeEventListener("abort", abortHandler);
|
|
3394
|
+
}
|
|
3395
|
+
}
|
|
3396
|
+
}
|
|
3397
|
+
[(_MessageStream_currentMessageSnapshot = new WeakMap, _MessageStream_params = new WeakMap, _MessageStream_connectedPromise = new WeakMap, _MessageStream_resolveConnectedPromise = new WeakMap, _MessageStream_rejectConnectedPromise = new WeakMap, _MessageStream_endPromise = new WeakMap, _MessageStream_resolveEndPromise = new WeakMap, _MessageStream_rejectEndPromise = new WeakMap, _MessageStream_listeners = new WeakMap, _MessageStream_ended = new WeakMap, _MessageStream_errored = new WeakMap, _MessageStream_aborted = new WeakMap, _MessageStream_catchingPromiseCreated = new WeakMap, _MessageStream_response = new WeakMap, _MessageStream_request_id = new WeakMap, _MessageStream_logger = new WeakMap, _MessageStream_handleError = new WeakMap, _MessageStream_instances = new WeakSet, _MessageStream_getFinalMessage = function _MessageStream_getFinalMessage2() {
|
|
3398
|
+
if (this.receivedMessages.length === 0) {
|
|
3399
|
+
throw new AnthropicError("stream ended without producing a Message with role=assistant");
|
|
3400
|
+
}
|
|
3401
|
+
return this.receivedMessages.at(-1);
|
|
3402
|
+
}, _MessageStream_getFinalText = function _MessageStream_getFinalText2() {
|
|
3403
|
+
if (this.receivedMessages.length === 0) {
|
|
3404
|
+
throw new AnthropicError("stream ended without producing a Message with role=assistant");
|
|
3405
|
+
}
|
|
3406
|
+
const textBlocks = this.receivedMessages.at(-1).content.filter((block) => block.type === "text").map((block) => block.text);
|
|
3407
|
+
if (textBlocks.length === 0) {
|
|
3408
|
+
throw new AnthropicError("stream ended without producing a content block with type=text");
|
|
3409
|
+
}
|
|
3410
|
+
return textBlocks.join(" ");
|
|
3411
|
+
}, _MessageStream_beginRequest = function _MessageStream_beginRequest2() {
|
|
3412
|
+
if (this.ended)
|
|
3413
|
+
return;
|
|
3414
|
+
__classPrivateFieldSet(this, _MessageStream_currentMessageSnapshot, undefined, "f");
|
|
3415
|
+
}, _MessageStream_addStreamEvent = function _MessageStream_addStreamEvent2(event) {
|
|
3416
|
+
if (this.ended)
|
|
3417
|
+
return;
|
|
3418
|
+
const messageSnapshot = __classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_accumulateMessage).call(this, event);
|
|
3419
|
+
this._emit("streamEvent", event, messageSnapshot);
|
|
3420
|
+
switch (event.type) {
|
|
3421
|
+
case "content_block_delta": {
|
|
3422
|
+
const content = messageSnapshot.content.at(-1);
|
|
3423
|
+
switch (event.delta.type) {
|
|
3424
|
+
case "text_delta": {
|
|
3425
|
+
if (content.type === "text") {
|
|
3426
|
+
this._emit("text", event.delta.text, content.text || "");
|
|
3427
|
+
}
|
|
3428
|
+
break;
|
|
3429
|
+
}
|
|
3430
|
+
case "citations_delta": {
|
|
3431
|
+
if (content.type === "text") {
|
|
3432
|
+
this._emit("citation", event.delta.citation, content.citations ?? []);
|
|
3433
|
+
}
|
|
3434
|
+
break;
|
|
3435
|
+
}
|
|
3436
|
+
case "input_json_delta": {
|
|
3437
|
+
if (tracksToolInput2(content) && content.input) {
|
|
3438
|
+
this._emit("inputJson", event.delta.partial_json, content.input);
|
|
3439
|
+
}
|
|
3440
|
+
break;
|
|
3441
|
+
}
|
|
3442
|
+
case "thinking_delta": {
|
|
3443
|
+
if (content.type === "thinking") {
|
|
3444
|
+
this._emit("thinking", event.delta.thinking, content.thinking);
|
|
3445
|
+
}
|
|
3446
|
+
break;
|
|
3447
|
+
}
|
|
3448
|
+
case "signature_delta": {
|
|
3449
|
+
if (content.type === "thinking") {
|
|
3450
|
+
this._emit("signature", content.signature);
|
|
3451
|
+
}
|
|
3452
|
+
break;
|
|
3453
|
+
}
|
|
3454
|
+
default:
|
|
3455
|
+
checkNever2(event.delta);
|
|
3456
|
+
}
|
|
3457
|
+
break;
|
|
3458
|
+
}
|
|
3459
|
+
case "message_stop": {
|
|
3460
|
+
this._addMessageParam(messageSnapshot);
|
|
3461
|
+
this._addMessage(maybeParseMessage(messageSnapshot, __classPrivateFieldGet(this, _MessageStream_params, "f"), { logger: __classPrivateFieldGet(this, _MessageStream_logger, "f") }), true);
|
|
3462
|
+
break;
|
|
3463
|
+
}
|
|
3464
|
+
case "content_block_stop": {
|
|
3465
|
+
this._emit("contentBlock", messageSnapshot.content.at(-1));
|
|
3466
|
+
break;
|
|
3467
|
+
}
|
|
3468
|
+
case "message_start": {
|
|
3469
|
+
__classPrivateFieldSet(this, _MessageStream_currentMessageSnapshot, messageSnapshot, "f");
|
|
3470
|
+
break;
|
|
3471
|
+
}
|
|
3472
|
+
case "content_block_start":
|
|
3473
|
+
case "message_delta":
|
|
3474
|
+
break;
|
|
3475
|
+
}
|
|
3476
|
+
}, _MessageStream_endRequest = function _MessageStream_endRequest2() {
|
|
3477
|
+
if (this.ended) {
|
|
3478
|
+
throw new AnthropicError(`stream has ended, this shouldn't happen`);
|
|
3479
|
+
}
|
|
3480
|
+
const snapshot = __classPrivateFieldGet(this, _MessageStream_currentMessageSnapshot, "f");
|
|
3481
|
+
if (!snapshot) {
|
|
3482
|
+
throw new AnthropicError(`request ended without sending any chunks`);
|
|
3483
|
+
}
|
|
3484
|
+
__classPrivateFieldSet(this, _MessageStream_currentMessageSnapshot, undefined, "f");
|
|
3485
|
+
return maybeParseMessage(snapshot, __classPrivateFieldGet(this, _MessageStream_params, "f"), { logger: __classPrivateFieldGet(this, _MessageStream_logger, "f") });
|
|
3486
|
+
}, _MessageStream_accumulateMessage = function _MessageStream_accumulateMessage2(event) {
|
|
3487
|
+
let snapshot = __classPrivateFieldGet(this, _MessageStream_currentMessageSnapshot, "f");
|
|
3488
|
+
if (event.type === "message_start") {
|
|
3489
|
+
if (snapshot) {
|
|
3490
|
+
throw new AnthropicError(`Unexpected event order, got ${event.type} before receiving "message_stop"`);
|
|
3491
|
+
}
|
|
3492
|
+
return event.message;
|
|
3493
|
+
}
|
|
3494
|
+
if (!snapshot) {
|
|
3495
|
+
throw new AnthropicError(`Unexpected event order, got ${event.type} before "message_start"`);
|
|
3496
|
+
}
|
|
3497
|
+
switch (event.type) {
|
|
3498
|
+
case "message_stop":
|
|
3499
|
+
return snapshot;
|
|
3500
|
+
case "message_delta":
|
|
3501
|
+
snapshot.stop_reason = event.delta.stop_reason;
|
|
3502
|
+
snapshot.stop_sequence = event.delta.stop_sequence;
|
|
3503
|
+
snapshot.usage.output_tokens = event.usage.output_tokens;
|
|
3504
|
+
if (event.usage.input_tokens != null) {
|
|
3505
|
+
snapshot.usage.input_tokens = event.usage.input_tokens;
|
|
3506
|
+
}
|
|
3507
|
+
if (event.usage.cache_creation_input_tokens != null) {
|
|
3508
|
+
snapshot.usage.cache_creation_input_tokens = event.usage.cache_creation_input_tokens;
|
|
3509
|
+
}
|
|
3510
|
+
if (event.usage.cache_read_input_tokens != null) {
|
|
3511
|
+
snapshot.usage.cache_read_input_tokens = event.usage.cache_read_input_tokens;
|
|
3512
|
+
}
|
|
3513
|
+
if (event.usage.server_tool_use != null) {
|
|
3514
|
+
snapshot.usage.server_tool_use = event.usage.server_tool_use;
|
|
3515
|
+
}
|
|
3516
|
+
return snapshot;
|
|
3517
|
+
case "content_block_start":
|
|
3518
|
+
snapshot.content.push({ ...event.content_block });
|
|
3519
|
+
return snapshot;
|
|
3520
|
+
case "content_block_delta": {
|
|
3521
|
+
const snapshotContent = snapshot.content.at(event.index);
|
|
3522
|
+
switch (event.delta.type) {
|
|
3523
|
+
case "text_delta": {
|
|
3524
|
+
if (snapshotContent?.type === "text") {
|
|
3525
|
+
snapshot.content[event.index] = {
|
|
3526
|
+
...snapshotContent,
|
|
3527
|
+
text: (snapshotContent.text || "") + event.delta.text
|
|
3528
|
+
};
|
|
3529
|
+
}
|
|
3530
|
+
break;
|
|
3531
|
+
}
|
|
3532
|
+
case "citations_delta": {
|
|
3533
|
+
if (snapshotContent?.type === "text") {
|
|
3534
|
+
snapshot.content[event.index] = {
|
|
3535
|
+
...snapshotContent,
|
|
3536
|
+
citations: [...snapshotContent.citations ?? [], event.delta.citation]
|
|
3537
|
+
};
|
|
3538
|
+
}
|
|
3539
|
+
break;
|
|
3540
|
+
}
|
|
3541
|
+
case "input_json_delta": {
|
|
3542
|
+
if (snapshotContent && tracksToolInput2(snapshotContent)) {
|
|
3543
|
+
let jsonBuf = snapshotContent[JSON_BUF_PROPERTY2] || "";
|
|
3544
|
+
jsonBuf += event.delta.partial_json;
|
|
3545
|
+
const newContent = { ...snapshotContent };
|
|
3546
|
+
Object.defineProperty(newContent, JSON_BUF_PROPERTY2, {
|
|
3547
|
+
value: jsonBuf,
|
|
3548
|
+
enumerable: false,
|
|
3549
|
+
writable: true
|
|
3550
|
+
});
|
|
3551
|
+
if (jsonBuf) {
|
|
3552
|
+
newContent.input = partialParse(jsonBuf);
|
|
3553
|
+
}
|
|
3554
|
+
snapshot.content[event.index] = newContent;
|
|
3555
|
+
}
|
|
3556
|
+
break;
|
|
3557
|
+
}
|
|
3558
|
+
case "thinking_delta": {
|
|
3559
|
+
if (snapshotContent?.type === "thinking") {
|
|
3560
|
+
snapshot.content[event.index] = {
|
|
3561
|
+
...snapshotContent,
|
|
3562
|
+
thinking: snapshotContent.thinking + event.delta.thinking
|
|
3563
|
+
};
|
|
3564
|
+
}
|
|
3565
|
+
break;
|
|
3566
|
+
}
|
|
3567
|
+
case "signature_delta": {
|
|
3568
|
+
if (snapshotContent?.type === "thinking") {
|
|
3569
|
+
snapshot.content[event.index] = {
|
|
3570
|
+
...snapshotContent,
|
|
3571
|
+
signature: event.delta.signature
|
|
3572
|
+
};
|
|
3573
|
+
}
|
|
3574
|
+
break;
|
|
3575
|
+
}
|
|
3576
|
+
default:
|
|
3577
|
+
checkNever2(event.delta);
|
|
3578
|
+
}
|
|
3579
|
+
return snapshot;
|
|
3580
|
+
}
|
|
3581
|
+
case "content_block_stop":
|
|
3582
|
+
return snapshot;
|
|
3583
|
+
}
|
|
3584
|
+
}, Symbol.asyncIterator)]() {
|
|
3585
|
+
const pushQueue = [];
|
|
3586
|
+
const readQueue = [];
|
|
3587
|
+
let done = false;
|
|
3588
|
+
this.on("streamEvent", (event) => {
|
|
3589
|
+
const reader = readQueue.shift();
|
|
3590
|
+
if (reader) {
|
|
3591
|
+
reader.resolve(event);
|
|
3592
|
+
} else {
|
|
3593
|
+
pushQueue.push(event);
|
|
3594
|
+
}
|
|
3595
|
+
});
|
|
3596
|
+
this.on("end", () => {
|
|
3597
|
+
done = true;
|
|
3598
|
+
for (const reader of readQueue) {
|
|
3599
|
+
reader.resolve(undefined);
|
|
3600
|
+
}
|
|
3601
|
+
readQueue.length = 0;
|
|
3602
|
+
});
|
|
3603
|
+
this.on("abort", (err) => {
|
|
3604
|
+
done = true;
|
|
3605
|
+
for (const reader of readQueue) {
|
|
3606
|
+
reader.reject(err);
|
|
3607
|
+
}
|
|
3608
|
+
readQueue.length = 0;
|
|
3609
|
+
});
|
|
3610
|
+
this.on("error", (err) => {
|
|
3611
|
+
done = true;
|
|
3612
|
+
for (const reader of readQueue) {
|
|
3613
|
+
reader.reject(err);
|
|
3614
|
+
}
|
|
3615
|
+
readQueue.length = 0;
|
|
3616
|
+
});
|
|
3617
|
+
return {
|
|
3618
|
+
next: async () => {
|
|
3619
|
+
if (!pushQueue.length) {
|
|
3620
|
+
if (done) {
|
|
3621
|
+
return { value: undefined, done: true };
|
|
3622
|
+
}
|
|
3623
|
+
return new Promise((resolve, reject) => readQueue.push({ resolve, reject })).then((chunk2) => chunk2 ? { value: chunk2, done: false } : { value: undefined, done: true });
|
|
3624
|
+
}
|
|
3625
|
+
const chunk = pushQueue.shift();
|
|
3626
|
+
return { value: chunk, done: false };
|
|
3627
|
+
},
|
|
3628
|
+
return: async () => {
|
|
3629
|
+
this.abort();
|
|
3630
|
+
return { value: undefined, done: true };
|
|
3631
|
+
}
|
|
3632
|
+
};
|
|
3633
|
+
}
|
|
3634
|
+
toReadableStream() {
|
|
3635
|
+
const stream = new Stream(this[Symbol.asyncIterator].bind(this), this.controller);
|
|
3636
|
+
return stream.toReadableStream();
|
|
3637
|
+
}
|
|
3638
|
+
};
|
|
3639
|
+
});
|
|
3640
|
+
|
|
3641
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/resources/messages/batches.mjs
|
|
3642
|
+
var Batches2;
|
|
3643
|
+
var init_batches2 = __esm(() => {
|
|
3644
|
+
init_resource();
|
|
3645
|
+
init_pagination();
|
|
3646
|
+
init_headers();
|
|
3647
|
+
init_jsonl();
|
|
3648
|
+
init_error2();
|
|
3649
|
+
init_path();
|
|
3650
|
+
Batches2 = class Batches2 extends APIResource {
|
|
3651
|
+
create(body, options) {
|
|
3652
|
+
return this._client.post("/v1/messages/batches", { body, ...options });
|
|
3653
|
+
}
|
|
3654
|
+
retrieve(messageBatchID, options) {
|
|
3655
|
+
return this._client.get(path`/v1/messages/batches/${messageBatchID}`, options);
|
|
3656
|
+
}
|
|
3657
|
+
list(query = {}, options) {
|
|
3658
|
+
return this._client.getAPIList("/v1/messages/batches", Page, { query, ...options });
|
|
3659
|
+
}
|
|
3660
|
+
delete(messageBatchID, options) {
|
|
3661
|
+
return this._client.delete(path`/v1/messages/batches/${messageBatchID}`, options);
|
|
3662
|
+
}
|
|
3663
|
+
cancel(messageBatchID, options) {
|
|
3664
|
+
return this._client.post(path`/v1/messages/batches/${messageBatchID}/cancel`, options);
|
|
3665
|
+
}
|
|
3666
|
+
async results(messageBatchID, options) {
|
|
3667
|
+
const batch = await this.retrieve(messageBatchID);
|
|
3668
|
+
if (!batch.results_url) {
|
|
3669
|
+
throw new AnthropicError(`No batch \`results_url\`; Has it finished processing? ${batch.processing_status} - ${batch.id}`);
|
|
3670
|
+
}
|
|
3671
|
+
return this._client.get(batch.results_url, {
|
|
3672
|
+
...options,
|
|
3673
|
+
headers: buildHeaders([{ Accept: "application/binary" }, options?.headers]),
|
|
3674
|
+
stream: true,
|
|
3675
|
+
__binaryResponse: true
|
|
3676
|
+
})._thenUnwrap((_, props) => JSONLDecoder.fromResponse(props.response, props.controller));
|
|
3677
|
+
}
|
|
3678
|
+
};
|
|
3679
|
+
});
|
|
3680
|
+
|
|
3681
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/resources/messages/messages.mjs
|
|
3682
|
+
var Messages2, DEPRECATED_MODELS2, MODELS_TO_WARN_WITH_THINKING_ENABLED2;
|
|
3683
|
+
var init_messages2 = __esm(() => {
|
|
3684
|
+
init_resource();
|
|
3685
|
+
init_headers();
|
|
3686
|
+
init_stainless_helper_header();
|
|
3687
|
+
init_MessageStream();
|
|
3688
|
+
init_parser2();
|
|
3689
|
+
init_batches2();
|
|
3690
|
+
init_batches2();
|
|
3691
|
+
init_constants();
|
|
3692
|
+
Messages2 = class Messages2 extends APIResource {
|
|
3693
|
+
constructor() {
|
|
3694
|
+
super(...arguments);
|
|
3695
|
+
this.batches = new Batches2(this._client);
|
|
3696
|
+
}
|
|
3697
|
+
create(body, options) {
|
|
3698
|
+
if (body.model in DEPRECATED_MODELS2) {
|
|
3699
|
+
console.warn(`The model '${body.model}' is deprecated and will reach end-of-life on ${DEPRECATED_MODELS2[body.model]}
|
|
3700
|
+
Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`);
|
|
3701
|
+
}
|
|
3702
|
+
if (body.model in MODELS_TO_WARN_WITH_THINKING_ENABLED2 && body.thinking && body.thinking.type === "enabled") {
|
|
3703
|
+
console.warn(`Using Claude with ${body.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);
|
|
3704
|
+
}
|
|
3705
|
+
let timeout = this._client._options.timeout;
|
|
3706
|
+
if (!body.stream && timeout == null) {
|
|
3707
|
+
const maxNonstreamingTokens = MODEL_NONSTREAMING_TOKENS[body.model] ?? undefined;
|
|
3708
|
+
timeout = this._client.calculateNonstreamingTimeout(body.max_tokens, maxNonstreamingTokens);
|
|
3709
|
+
}
|
|
3710
|
+
const helperHeader = stainlessHelperHeader(body.tools, body.messages);
|
|
3711
|
+
return this._client.post("/v1/messages", {
|
|
3712
|
+
body,
|
|
3713
|
+
timeout: timeout ?? 600000,
|
|
3714
|
+
...options,
|
|
3715
|
+
headers: buildHeaders([helperHeader, options?.headers]),
|
|
3716
|
+
stream: body.stream ?? false
|
|
3717
|
+
});
|
|
3718
|
+
}
|
|
3719
|
+
parse(params, options) {
|
|
3720
|
+
return this.create(params, options).then((message) => parseMessage(message, params, { logger: this._client.logger ?? console }));
|
|
3721
|
+
}
|
|
3722
|
+
stream(body, options) {
|
|
3723
|
+
return MessageStream.createMessage(this, body, options, { logger: this._client.logger ?? console });
|
|
3724
|
+
}
|
|
3725
|
+
countTokens(body, options) {
|
|
3726
|
+
return this._client.post("/v1/messages/count_tokens", { body, ...options });
|
|
3727
|
+
}
|
|
3728
|
+
};
|
|
3729
|
+
DEPRECATED_MODELS2 = {
|
|
3730
|
+
"claude-1.3": "November 6th, 2024",
|
|
3731
|
+
"claude-1.3-100k": "November 6th, 2024",
|
|
3732
|
+
"claude-instant-1.1": "November 6th, 2024",
|
|
3733
|
+
"claude-instant-1.1-100k": "November 6th, 2024",
|
|
3734
|
+
"claude-instant-1.2": "November 6th, 2024",
|
|
3735
|
+
"claude-3-sonnet-20240229": "July 21st, 2025",
|
|
3736
|
+
"claude-3-opus-20240229": "January 5th, 2026",
|
|
3737
|
+
"claude-2.1": "July 21st, 2025",
|
|
3738
|
+
"claude-2.0": "July 21st, 2025",
|
|
3739
|
+
"claude-3-7-sonnet-latest": "February 19th, 2026",
|
|
3740
|
+
"claude-3-7-sonnet-20250219": "February 19th, 2026",
|
|
3741
|
+
"claude-3-5-haiku-latest": "February 19th, 2026",
|
|
3742
|
+
"claude-3-5-haiku-20241022": "February 19th, 2026"
|
|
3743
|
+
};
|
|
3744
|
+
MODELS_TO_WARN_WITH_THINKING_ENABLED2 = ["claude-opus-4-6"];
|
|
3745
|
+
Messages2.Batches = Batches2;
|
|
3746
|
+
});
|
|
3747
|
+
|
|
3748
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/resources/models.mjs
|
|
3749
|
+
var Models2;
|
|
3750
|
+
var init_models2 = __esm(() => {
|
|
3751
|
+
init_resource();
|
|
3752
|
+
init_pagination();
|
|
3753
|
+
init_headers();
|
|
3754
|
+
init_path();
|
|
3755
|
+
Models2 = class Models2 extends APIResource {
|
|
3756
|
+
retrieve(modelID, params = {}, options) {
|
|
3757
|
+
const { betas } = params ?? {};
|
|
3758
|
+
return this._client.get(path`/v1/models/${modelID}`, {
|
|
3759
|
+
...options,
|
|
3760
|
+
headers: buildHeaders([
|
|
3761
|
+
{ ...betas?.toString() != null ? { "anthropic-beta": betas?.toString() } : undefined },
|
|
3762
|
+
options?.headers
|
|
3763
|
+
])
|
|
3764
|
+
});
|
|
3765
|
+
}
|
|
3766
|
+
list(params = {}, options) {
|
|
3767
|
+
const { betas, ...query } = params ?? {};
|
|
3768
|
+
return this._client.getAPIList("/v1/models", Page, {
|
|
3769
|
+
query,
|
|
3770
|
+
...options,
|
|
3771
|
+
headers: buildHeaders([
|
|
3772
|
+
{ ...betas?.toString() != null ? { "anthropic-beta": betas?.toString() } : undefined },
|
|
3773
|
+
options?.headers
|
|
3774
|
+
])
|
|
3775
|
+
});
|
|
3776
|
+
}
|
|
3777
|
+
};
|
|
3778
|
+
});
|
|
3779
|
+
|
|
3780
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/resources/index.mjs
|
|
3781
|
+
var init_resources = __esm(() => {
|
|
3782
|
+
init_beta();
|
|
3783
|
+
init_completions();
|
|
3784
|
+
init_messages2();
|
|
3785
|
+
init_models2();
|
|
3786
|
+
init_shared();
|
|
3787
|
+
});
|
|
3788
|
+
|
|
3789
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/internal/utils/env.mjs
|
|
3790
|
+
var readEnv = (env) => {
|
|
3791
|
+
if (typeof globalThis.process !== "undefined") {
|
|
3792
|
+
return globalThis.process.env?.[env]?.trim() ?? undefined;
|
|
3793
|
+
}
|
|
3794
|
+
if (typeof globalThis.Deno !== "undefined") {
|
|
3795
|
+
return globalThis.Deno.env?.get?.(env)?.trim();
|
|
3796
|
+
}
|
|
3797
|
+
return;
|
|
3798
|
+
};
|
|
3799
|
+
var init_env = () => {};
|
|
3800
|
+
|
|
3801
|
+
// node_modules/.bun/@anthropic-ai+sdk@0.80.0+3c5d820c62823f0b/node_modules/@anthropic-ai/sdk/client.mjs
|
|
3802
|
+
class BaseAnthropic {
|
|
3803
|
+
constructor({ baseURL = readEnv("ANTHROPIC_BASE_URL"), apiKey = readEnv("ANTHROPIC_API_KEY") ?? null, authToken = readEnv("ANTHROPIC_AUTH_TOKEN") ?? null, ...opts } = {}) {
|
|
3804
|
+
_BaseAnthropic_instances.add(this);
|
|
3805
|
+
_BaseAnthropic_encoder.set(this, undefined);
|
|
3806
|
+
const options = {
|
|
3807
|
+
apiKey,
|
|
3808
|
+
authToken,
|
|
3809
|
+
...opts,
|
|
3810
|
+
baseURL: baseURL || `https://api.anthropic.com`
|
|
3811
|
+
};
|
|
3812
|
+
if (!options.dangerouslyAllowBrowser && isRunningInBrowser()) {
|
|
3813
|
+
throw new AnthropicError(`It looks like you're running in a browser-like environment.
|
|
3814
|
+
|
|
3815
|
+
This is disabled by default, as it risks exposing your secret API credentials to attackers.
|
|
3816
|
+
If you understand the risks and have appropriate mitigations in place,
|
|
3817
|
+
you can set the \`dangerouslyAllowBrowser\` option to \`true\`, e.g.,
|
|
3818
|
+
|
|
3819
|
+
new Anthropic({ apiKey, dangerouslyAllowBrowser: true });
|
|
3820
|
+
`);
|
|
3821
|
+
}
|
|
3822
|
+
this.baseURL = options.baseURL;
|
|
3823
|
+
this.timeout = options.timeout ?? _a.DEFAULT_TIMEOUT;
|
|
3824
|
+
this.logger = options.logger ?? console;
|
|
3825
|
+
const defaultLogLevel = "warn";
|
|
3826
|
+
this.logLevel = defaultLogLevel;
|
|
3827
|
+
this.logLevel = parseLogLevel(options.logLevel, "ClientOptions.logLevel", this) ?? parseLogLevel(readEnv("ANTHROPIC_LOG"), "process.env['ANTHROPIC_LOG']", this) ?? defaultLogLevel;
|
|
3828
|
+
this.fetchOptions = options.fetchOptions;
|
|
3829
|
+
this.maxRetries = options.maxRetries ?? 2;
|
|
3830
|
+
this.fetch = options.fetch ?? getDefaultFetch();
|
|
3831
|
+
__classPrivateFieldSet(this, _BaseAnthropic_encoder, FallbackEncoder, "f");
|
|
3832
|
+
this._options = options;
|
|
3833
|
+
this.apiKey = typeof apiKey === "string" ? apiKey : null;
|
|
3834
|
+
this.authToken = authToken;
|
|
3835
|
+
}
|
|
3836
|
+
withOptions(options) {
|
|
3837
|
+
const client = new this.constructor({
|
|
3838
|
+
...this._options,
|
|
3839
|
+
baseURL: this.baseURL,
|
|
3840
|
+
maxRetries: this.maxRetries,
|
|
3841
|
+
timeout: this.timeout,
|
|
3842
|
+
logger: this.logger,
|
|
3843
|
+
logLevel: this.logLevel,
|
|
3844
|
+
fetch: this.fetch,
|
|
3845
|
+
fetchOptions: this.fetchOptions,
|
|
3846
|
+
apiKey: this.apiKey,
|
|
3847
|
+
authToken: this.authToken,
|
|
3848
|
+
...options
|
|
3849
|
+
});
|
|
3850
|
+
return client;
|
|
3851
|
+
}
|
|
3852
|
+
defaultQuery() {
|
|
3853
|
+
return this._options.defaultQuery;
|
|
3854
|
+
}
|
|
3855
|
+
validateHeaders({ values, nulls }) {
|
|
3856
|
+
if (values.get("x-api-key") || values.get("authorization")) {
|
|
3857
|
+
return;
|
|
3858
|
+
}
|
|
3859
|
+
if (this.apiKey && values.get("x-api-key")) {
|
|
3860
|
+
return;
|
|
3861
|
+
}
|
|
3862
|
+
if (nulls.has("x-api-key")) {
|
|
3863
|
+
return;
|
|
3864
|
+
}
|
|
3865
|
+
if (this.authToken && values.get("authorization")) {
|
|
3866
|
+
return;
|
|
3867
|
+
}
|
|
3868
|
+
if (nulls.has("authorization")) {
|
|
3869
|
+
return;
|
|
3870
|
+
}
|
|
3871
|
+
throw new Error('Could not resolve authentication method. Expected either apiKey or authToken to be set. Or for one of the "X-Api-Key" or "Authorization" headers to be explicitly omitted');
|
|
3872
|
+
}
|
|
3873
|
+
async authHeaders(opts) {
|
|
3874
|
+
return buildHeaders([await this.apiKeyAuth(opts), await this.bearerAuth(opts)]);
|
|
3875
|
+
}
|
|
3876
|
+
async apiKeyAuth(opts) {
|
|
3877
|
+
if (this.apiKey == null) {
|
|
3878
|
+
return;
|
|
3879
|
+
}
|
|
3880
|
+
return buildHeaders([{ "X-Api-Key": this.apiKey }]);
|
|
3881
|
+
}
|
|
3882
|
+
async bearerAuth(opts) {
|
|
3883
|
+
if (this.authToken == null) {
|
|
3884
|
+
return;
|
|
3885
|
+
}
|
|
3886
|
+
return buildHeaders([{ Authorization: `Bearer ${this.authToken}` }]);
|
|
3887
|
+
}
|
|
3888
|
+
stringifyQuery(query) {
|
|
3889
|
+
return stringifyQuery(query);
|
|
3890
|
+
}
|
|
3891
|
+
getUserAgent() {
|
|
3892
|
+
return `${this.constructor.name}/JS ${VERSION}`;
|
|
3893
|
+
}
|
|
3894
|
+
defaultIdempotencyKey() {
|
|
3895
|
+
return `stainless-node-retry-${uuid4()}`;
|
|
3896
|
+
}
|
|
3897
|
+
makeStatusError(status, error2, message, headers) {
|
|
3898
|
+
return APIError.generate(status, error2, message, headers);
|
|
3899
|
+
}
|
|
3900
|
+
buildURL(path2, query, defaultBaseURL) {
|
|
3901
|
+
const baseURL = !__classPrivateFieldGet(this, _BaseAnthropic_instances, "m", _BaseAnthropic_baseURLOverridden).call(this) && defaultBaseURL || this.baseURL;
|
|
3902
|
+
const url = isAbsoluteURL(path2) ? new URL(path2) : new URL(baseURL + (baseURL.endsWith("/") && path2.startsWith("/") ? path2.slice(1) : path2));
|
|
3903
|
+
const defaultQuery = this.defaultQuery();
|
|
3904
|
+
const pathQuery = Object.fromEntries(url.searchParams);
|
|
3905
|
+
if (!isEmptyObj(defaultQuery) || !isEmptyObj(pathQuery)) {
|
|
3906
|
+
query = { ...pathQuery, ...defaultQuery, ...query };
|
|
3907
|
+
}
|
|
3908
|
+
if (typeof query === "object" && query && !Array.isArray(query)) {
|
|
3909
|
+
url.search = this.stringifyQuery(query);
|
|
3910
|
+
}
|
|
3911
|
+
return url.toString();
|
|
3912
|
+
}
|
|
3913
|
+
_calculateNonstreamingTimeout(maxTokens) {
|
|
3914
|
+
const defaultTimeout = 10 * 60;
|
|
3915
|
+
const expectedTimeout = 60 * 60 * maxTokens / 128000;
|
|
3916
|
+
if (expectedTimeout > defaultTimeout) {
|
|
3917
|
+
throw new AnthropicError("Streaming is required for operations that may take longer than 10 minutes. " + "See https://github.com/anthropics/anthropic-sdk-typescript#streaming-responses for more details");
|
|
3918
|
+
}
|
|
3919
|
+
return defaultTimeout * 1000;
|
|
3920
|
+
}
|
|
3921
|
+
async prepareOptions(options) {}
|
|
3922
|
+
async prepareRequest(request, { url, options }) {}
|
|
3923
|
+
get(path2, opts) {
|
|
3924
|
+
return this.methodRequest("get", path2, opts);
|
|
3925
|
+
}
|
|
3926
|
+
post(path2, opts) {
|
|
3927
|
+
return this.methodRequest("post", path2, opts);
|
|
3928
|
+
}
|
|
3929
|
+
patch(path2, opts) {
|
|
3930
|
+
return this.methodRequest("patch", path2, opts);
|
|
3931
|
+
}
|
|
3932
|
+
put(path2, opts) {
|
|
3933
|
+
return this.methodRequest("put", path2, opts);
|
|
3934
|
+
}
|
|
3935
|
+
delete(path2, opts) {
|
|
3936
|
+
return this.methodRequest("delete", path2, opts);
|
|
3937
|
+
}
|
|
3938
|
+
methodRequest(method, path2, opts) {
|
|
3939
|
+
return this.request(Promise.resolve(opts).then((opts2) => {
|
|
3940
|
+
return { method, path: path2, ...opts2 };
|
|
3941
|
+
}));
|
|
3942
|
+
}
|
|
3943
|
+
request(options, remainingRetries = null) {
|
|
3944
|
+
return new APIPromise(this, this.makeRequest(options, remainingRetries, undefined));
|
|
3945
|
+
}
|
|
3946
|
+
async makeRequest(optionsInput, retriesRemaining, retryOfRequestLogID) {
|
|
3947
|
+
const options = await optionsInput;
|
|
3948
|
+
const maxRetries = options.maxRetries ?? this.maxRetries;
|
|
3949
|
+
if (retriesRemaining == null) {
|
|
3950
|
+
retriesRemaining = maxRetries;
|
|
3951
|
+
}
|
|
3952
|
+
await this.prepareOptions(options);
|
|
3953
|
+
const { req, url, timeout } = await this.buildRequest(options, {
|
|
3954
|
+
retryCount: maxRetries - retriesRemaining
|
|
3955
|
+
});
|
|
3956
|
+
await this.prepareRequest(req, { url, options });
|
|
3957
|
+
const requestLogID = "log_" + (Math.random() * (1 << 24) | 0).toString(16).padStart(6, "0");
|
|
3958
|
+
const retryLogStr = retryOfRequestLogID === undefined ? "" : `, retryOf: ${retryOfRequestLogID}`;
|
|
3959
|
+
const startTime = Date.now();
|
|
3960
|
+
loggerFor(this).debug(`[${requestLogID}] sending request`, formatRequestDetails({
|
|
3961
|
+
retryOfRequestLogID,
|
|
3962
|
+
method: options.method,
|
|
3963
|
+
url,
|
|
3964
|
+
options,
|
|
3965
|
+
headers: req.headers
|
|
3966
|
+
}));
|
|
3967
|
+
if (options.signal?.aborted) {
|
|
3968
|
+
throw new APIUserAbortError;
|
|
3969
|
+
}
|
|
3970
|
+
const controller = new AbortController;
|
|
3971
|
+
const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(castToError);
|
|
3972
|
+
const headersTime = Date.now();
|
|
3973
|
+
if (response instanceof globalThis.Error) {
|
|
3974
|
+
const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
|
|
3975
|
+
if (options.signal?.aborted) {
|
|
3976
|
+
throw new APIUserAbortError;
|
|
3977
|
+
}
|
|
3978
|
+
const isTimeout = isAbortError(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
|
|
3979
|
+
if (retriesRemaining) {
|
|
3980
|
+
loggerFor(this).info(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} - ${retryMessage}`);
|
|
3981
|
+
loggerFor(this).debug(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} (${retryMessage})`, formatRequestDetails({
|
|
3982
|
+
retryOfRequestLogID,
|
|
3983
|
+
url,
|
|
3984
|
+
durationMs: headersTime - startTime,
|
|
3985
|
+
message: response.message
|
|
3986
|
+
}));
|
|
3987
|
+
return this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? requestLogID);
|
|
3988
|
+
}
|
|
3989
|
+
loggerFor(this).info(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} - error; no more retries left`);
|
|
3990
|
+
loggerFor(this).debug(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} (error; no more retries left)`, formatRequestDetails({
|
|
3991
|
+
retryOfRequestLogID,
|
|
3992
|
+
url,
|
|
3993
|
+
durationMs: headersTime - startTime,
|
|
3994
|
+
message: response.message
|
|
3995
|
+
}));
|
|
3996
|
+
if (isTimeout) {
|
|
3997
|
+
throw new APIConnectionTimeoutError;
|
|
3998
|
+
}
|
|
3999
|
+
throw new APIConnectionError({ cause: response });
|
|
4000
|
+
}
|
|
4001
|
+
const specialHeaders = [...response.headers.entries()].filter(([name]) => name === "request-id").map(([name, value]) => ", " + name + ": " + JSON.stringify(value)).join("");
|
|
4002
|
+
const responseInfo = `[${requestLogID}${retryLogStr}${specialHeaders}] ${req.method} ${url} ${response.ok ? "succeeded" : "failed"} with status ${response.status} in ${headersTime - startTime}ms`;
|
|
4003
|
+
if (!response.ok) {
|
|
4004
|
+
const shouldRetry = await this.shouldRetry(response);
|
|
4005
|
+
if (retriesRemaining && shouldRetry) {
|
|
4006
|
+
const retryMessage2 = `retrying, ${retriesRemaining} attempts remaining`;
|
|
4007
|
+
await CancelReadableStream(response.body);
|
|
4008
|
+
loggerFor(this).info(`${responseInfo} - ${retryMessage2}`);
|
|
4009
|
+
loggerFor(this).debug(`[${requestLogID}] response error (${retryMessage2})`, formatRequestDetails({
|
|
4010
|
+
retryOfRequestLogID,
|
|
4011
|
+
url: response.url,
|
|
4012
|
+
status: response.status,
|
|
4013
|
+
headers: response.headers,
|
|
4014
|
+
durationMs: headersTime - startTime
|
|
4015
|
+
}));
|
|
4016
|
+
return this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? requestLogID, response.headers);
|
|
4017
|
+
}
|
|
4018
|
+
const retryMessage = shouldRetry ? `error; no more retries left` : `error; not retryable`;
|
|
4019
|
+
loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
|
|
4020
|
+
const errText = await response.text().catch((err2) => castToError(err2).message);
|
|
4021
|
+
const errJSON = safeJSON(errText);
|
|
4022
|
+
const errMessage = errJSON ? undefined : errText;
|
|
4023
|
+
loggerFor(this).debug(`[${requestLogID}] response error (${retryMessage})`, formatRequestDetails({
|
|
4024
|
+
retryOfRequestLogID,
|
|
4025
|
+
url: response.url,
|
|
4026
|
+
status: response.status,
|
|
4027
|
+
headers: response.headers,
|
|
4028
|
+
message: errMessage,
|
|
4029
|
+
durationMs: Date.now() - startTime
|
|
4030
|
+
}));
|
|
4031
|
+
const err = this.makeStatusError(response.status, errJSON, errMessage, response.headers);
|
|
4032
|
+
throw err;
|
|
4033
|
+
}
|
|
4034
|
+
loggerFor(this).info(responseInfo);
|
|
4035
|
+
loggerFor(this).debug(`[${requestLogID}] response start`, formatRequestDetails({
|
|
4036
|
+
retryOfRequestLogID,
|
|
4037
|
+
url: response.url,
|
|
4038
|
+
status: response.status,
|
|
4039
|
+
headers: response.headers,
|
|
4040
|
+
durationMs: headersTime - startTime
|
|
4041
|
+
}));
|
|
4042
|
+
return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
|
|
4043
|
+
}
|
|
4044
|
+
getAPIList(path2, Page2, opts) {
|
|
4045
|
+
return this.requestAPIList(Page2, opts && "then" in opts ? opts.then((opts2) => ({ method: "get", path: path2, ...opts2 })) : { method: "get", path: path2, ...opts });
|
|
4046
|
+
}
|
|
4047
|
+
requestAPIList(Page2, options) {
|
|
4048
|
+
const request = this.makeRequest(options, null, undefined);
|
|
4049
|
+
return new PagePromise(this, request, Page2);
|
|
4050
|
+
}
|
|
4051
|
+
async fetchWithTimeout(url, init, ms, controller) {
|
|
4052
|
+
const { signal, method, ...options } = init || {};
|
|
4053
|
+
const abort = this._makeAbort(controller);
|
|
4054
|
+
if (signal)
|
|
4055
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
4056
|
+
const timeout = setTimeout(abort, ms);
|
|
4057
|
+
const isReadableBody = globalThis.ReadableStream && options.body instanceof globalThis.ReadableStream || typeof options.body === "object" && options.body !== null && Symbol.asyncIterator in options.body;
|
|
4058
|
+
const fetchOptions = {
|
|
4059
|
+
signal: controller.signal,
|
|
4060
|
+
...isReadableBody ? { duplex: "half" } : {},
|
|
4061
|
+
method: "GET",
|
|
4062
|
+
...options
|
|
4063
|
+
};
|
|
4064
|
+
if (method) {
|
|
4065
|
+
fetchOptions.method = method.toUpperCase();
|
|
4066
|
+
}
|
|
4067
|
+
try {
|
|
4068
|
+
return await this.fetch.call(undefined, url, fetchOptions);
|
|
4069
|
+
} finally {
|
|
4070
|
+
clearTimeout(timeout);
|
|
4071
|
+
}
|
|
4072
|
+
}
|
|
4073
|
+
async shouldRetry(response) {
|
|
4074
|
+
const shouldRetryHeader = response.headers.get("x-should-retry");
|
|
4075
|
+
if (shouldRetryHeader === "true")
|
|
4076
|
+
return true;
|
|
4077
|
+
if (shouldRetryHeader === "false")
|
|
4078
|
+
return false;
|
|
4079
|
+
if (response.status === 408)
|
|
4080
|
+
return true;
|
|
4081
|
+
if (response.status === 409)
|
|
4082
|
+
return true;
|
|
4083
|
+
if (response.status === 429)
|
|
4084
|
+
return true;
|
|
4085
|
+
if (response.status >= 500)
|
|
4086
|
+
return true;
|
|
4087
|
+
return false;
|
|
4088
|
+
}
|
|
4089
|
+
async retryRequest(options, retriesRemaining, requestLogID, responseHeaders) {
|
|
4090
|
+
let timeoutMillis;
|
|
4091
|
+
const retryAfterMillisHeader = responseHeaders?.get("retry-after-ms");
|
|
4092
|
+
if (retryAfterMillisHeader) {
|
|
4093
|
+
const timeoutMs = parseFloat(retryAfterMillisHeader);
|
|
4094
|
+
if (!Number.isNaN(timeoutMs)) {
|
|
4095
|
+
timeoutMillis = timeoutMs;
|
|
4096
|
+
}
|
|
4097
|
+
}
|
|
4098
|
+
const retryAfterHeader = responseHeaders?.get("retry-after");
|
|
4099
|
+
if (retryAfterHeader && !timeoutMillis) {
|
|
4100
|
+
const timeoutSeconds = parseFloat(retryAfterHeader);
|
|
4101
|
+
if (!Number.isNaN(timeoutSeconds)) {
|
|
4102
|
+
timeoutMillis = timeoutSeconds * 1000;
|
|
4103
|
+
} else {
|
|
4104
|
+
timeoutMillis = Date.parse(retryAfterHeader) - Date.now();
|
|
4105
|
+
}
|
|
4106
|
+
}
|
|
4107
|
+
if (timeoutMillis === undefined) {
|
|
4108
|
+
const maxRetries = options.maxRetries ?? this.maxRetries;
|
|
4109
|
+
timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
|
|
4110
|
+
}
|
|
4111
|
+
await sleep(timeoutMillis);
|
|
4112
|
+
return this.makeRequest(options, retriesRemaining - 1, requestLogID);
|
|
4113
|
+
}
|
|
4114
|
+
calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries) {
|
|
4115
|
+
const initialRetryDelay = 0.5;
|
|
4116
|
+
const maxRetryDelay = 8;
|
|
4117
|
+
const numRetries = maxRetries - retriesRemaining;
|
|
4118
|
+
const sleepSeconds = Math.min(initialRetryDelay * Math.pow(2, numRetries), maxRetryDelay);
|
|
4119
|
+
const jitter = 1 - Math.random() * 0.25;
|
|
4120
|
+
return sleepSeconds * jitter * 1000;
|
|
4121
|
+
}
|
|
4122
|
+
calculateNonstreamingTimeout(maxTokens, maxNonstreamingTokens) {
|
|
4123
|
+
const maxTime = 60 * 60 * 1000;
|
|
4124
|
+
const defaultTime = 60 * 10 * 1000;
|
|
4125
|
+
const expectedTime = maxTime * maxTokens / 128000;
|
|
4126
|
+
if (expectedTime > defaultTime || maxNonstreamingTokens != null && maxTokens > maxNonstreamingTokens) {
|
|
4127
|
+
throw new AnthropicError("Streaming is required for operations that may take longer than 10 minutes. See https://github.com/anthropics/anthropic-sdk-typescript#long-requests for more details");
|
|
4128
|
+
}
|
|
4129
|
+
return defaultTime;
|
|
4130
|
+
}
|
|
4131
|
+
async buildRequest(inputOptions, { retryCount = 0 } = {}) {
|
|
4132
|
+
const options = { ...inputOptions };
|
|
4133
|
+
const { method, path: path2, query, defaultBaseURL } = options;
|
|
4134
|
+
const url = this.buildURL(path2, query, defaultBaseURL);
|
|
4135
|
+
if ("timeout" in options)
|
|
4136
|
+
validatePositiveInteger("timeout", options.timeout);
|
|
4137
|
+
options.timeout = options.timeout ?? this.timeout;
|
|
4138
|
+
const { bodyHeaders, body } = this.buildBody({ options });
|
|
4139
|
+
const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
|
|
4140
|
+
const req = {
|
|
4141
|
+
method,
|
|
4142
|
+
headers: reqHeaders,
|
|
4143
|
+
...options.signal && { signal: options.signal },
|
|
4144
|
+
...globalThis.ReadableStream && body instanceof globalThis.ReadableStream && { duplex: "half" },
|
|
4145
|
+
...body && { body },
|
|
4146
|
+
...this.fetchOptions ?? {},
|
|
4147
|
+
...options.fetchOptions ?? {}
|
|
4148
|
+
};
|
|
4149
|
+
return { req, url, timeout: options.timeout };
|
|
4150
|
+
}
|
|
4151
|
+
async buildHeaders({ options, method, bodyHeaders, retryCount }) {
|
|
4152
|
+
let idempotencyHeaders = {};
|
|
4153
|
+
if (this.idempotencyHeader && method !== "get") {
|
|
4154
|
+
if (!options.idempotencyKey)
|
|
4155
|
+
options.idempotencyKey = this.defaultIdempotencyKey();
|
|
4156
|
+
idempotencyHeaders[this.idempotencyHeader] = options.idempotencyKey;
|
|
4157
|
+
}
|
|
4158
|
+
const headers = buildHeaders([
|
|
4159
|
+
idempotencyHeaders,
|
|
4160
|
+
{
|
|
4161
|
+
Accept: "application/json",
|
|
4162
|
+
"User-Agent": this.getUserAgent(),
|
|
4163
|
+
"X-Stainless-Retry-Count": String(retryCount),
|
|
4164
|
+
...options.timeout ? { "X-Stainless-Timeout": String(Math.trunc(options.timeout / 1000)) } : {},
|
|
4165
|
+
...getPlatformHeaders(),
|
|
4166
|
+
...this._options.dangerouslyAllowBrowser ? { "anthropic-dangerous-direct-browser-access": "true" } : undefined,
|
|
4167
|
+
"anthropic-version": "2023-06-01"
|
|
4168
|
+
},
|
|
4169
|
+
await this.authHeaders(options),
|
|
4170
|
+
this._options.defaultHeaders,
|
|
4171
|
+
bodyHeaders,
|
|
4172
|
+
options.headers
|
|
4173
|
+
]);
|
|
4174
|
+
this.validateHeaders(headers);
|
|
4175
|
+
return headers.values;
|
|
4176
|
+
}
|
|
4177
|
+
_makeAbort(controller) {
|
|
4178
|
+
return () => controller.abort();
|
|
4179
|
+
}
|
|
4180
|
+
buildBody({ options: { body, headers: rawHeaders } }) {
|
|
4181
|
+
if (!body) {
|
|
4182
|
+
return { bodyHeaders: undefined, body: undefined };
|
|
4183
|
+
}
|
|
4184
|
+
const headers = buildHeaders([rawHeaders]);
|
|
4185
|
+
if (ArrayBuffer.isView(body) || body instanceof ArrayBuffer || body instanceof DataView || typeof body === "string" && headers.values.has("content-type") || globalThis.Blob && body instanceof globalThis.Blob || body instanceof FormData || body instanceof URLSearchParams || globalThis.ReadableStream && body instanceof globalThis.ReadableStream) {
|
|
4186
|
+
return { bodyHeaders: undefined, body };
|
|
4187
|
+
} else if (typeof body === "object" && ((Symbol.asyncIterator in body) || (Symbol.iterator in body) && ("next" in body) && typeof body.next === "function")) {
|
|
4188
|
+
return { bodyHeaders: undefined, body: ReadableStreamFrom(body) };
|
|
4189
|
+
} else if (typeof body === "object" && headers.values.get("content-type") === "application/x-www-form-urlencoded") {
|
|
4190
|
+
return {
|
|
4191
|
+
bodyHeaders: { "content-type": "application/x-www-form-urlencoded" },
|
|
4192
|
+
body: this.stringifyQuery(body)
|
|
4193
|
+
};
|
|
4194
|
+
} else {
|
|
4195
|
+
return __classPrivateFieldGet(this, _BaseAnthropic_encoder, "f").call(this, { body, headers });
|
|
4196
|
+
}
|
|
4197
|
+
}
|
|
4198
|
+
}
|
|
4199
|
+
var _BaseAnthropic_instances, _a, _BaseAnthropic_encoder, _BaseAnthropic_baseURLOverridden, HUMAN_PROMPT = "\\n\\nHuman:", AI_PROMPT = "\\n\\nAssistant:", Anthropic;
|
|
4200
|
+
var init_client = __esm(() => {
|
|
4201
|
+
init_tslib();
|
|
4202
|
+
init_uuid();
|
|
4203
|
+
init_values();
|
|
4204
|
+
init_sleep();
|
|
4205
|
+
init_errors();
|
|
4206
|
+
init_detect_platform();
|
|
4207
|
+
init_shims();
|
|
4208
|
+
init_request_options();
|
|
4209
|
+
init_query();
|
|
4210
|
+
init_version();
|
|
4211
|
+
init_error();
|
|
4212
|
+
init_pagination();
|
|
4213
|
+
init_uploads2();
|
|
4214
|
+
init_resources();
|
|
4215
|
+
init_api_promise();
|
|
4216
|
+
init_completions();
|
|
4217
|
+
init_models2();
|
|
4218
|
+
init_beta();
|
|
4219
|
+
init_messages2();
|
|
4220
|
+
init_detect_platform();
|
|
4221
|
+
init_headers();
|
|
4222
|
+
init_env();
|
|
4223
|
+
init_log();
|
|
4224
|
+
init_values();
|
|
4225
|
+
_a = BaseAnthropic, _BaseAnthropic_encoder = new WeakMap, _BaseAnthropic_instances = new WeakSet, _BaseAnthropic_baseURLOverridden = function _BaseAnthropic_baseURLOverridden2() {
|
|
4226
|
+
return this.baseURL !== "https://api.anthropic.com";
|
|
4227
|
+
};
|
|
4228
|
+
BaseAnthropic.Anthropic = _a;
|
|
4229
|
+
BaseAnthropic.HUMAN_PROMPT = HUMAN_PROMPT;
|
|
4230
|
+
BaseAnthropic.AI_PROMPT = AI_PROMPT;
|
|
4231
|
+
BaseAnthropic.DEFAULT_TIMEOUT = 600000;
|
|
4232
|
+
BaseAnthropic.AnthropicError = AnthropicError;
|
|
4233
|
+
BaseAnthropic.APIError = APIError;
|
|
4234
|
+
BaseAnthropic.APIConnectionError = APIConnectionError;
|
|
4235
|
+
BaseAnthropic.APIConnectionTimeoutError = APIConnectionTimeoutError;
|
|
4236
|
+
BaseAnthropic.APIUserAbortError = APIUserAbortError;
|
|
4237
|
+
BaseAnthropic.NotFoundError = NotFoundError;
|
|
4238
|
+
BaseAnthropic.ConflictError = ConflictError;
|
|
4239
|
+
BaseAnthropic.RateLimitError = RateLimitError;
|
|
4240
|
+
BaseAnthropic.BadRequestError = BadRequestError;
|
|
4241
|
+
BaseAnthropic.AuthenticationError = AuthenticationError;
|
|
4242
|
+
BaseAnthropic.InternalServerError = InternalServerError;
|
|
4243
|
+
BaseAnthropic.PermissionDeniedError = PermissionDeniedError;
|
|
4244
|
+
BaseAnthropic.UnprocessableEntityError = UnprocessableEntityError;
|
|
4245
|
+
BaseAnthropic.toFile = toFile;
|
|
4246
|
+
Anthropic = class Anthropic extends BaseAnthropic {
|
|
4247
|
+
constructor() {
|
|
4248
|
+
super(...arguments);
|
|
4249
|
+
this.completions = new Completions(this);
|
|
4250
|
+
this.messages = new Messages2(this);
|
|
4251
|
+
this.models = new Models2(this);
|
|
4252
|
+
this.beta = new Beta(this);
|
|
4253
|
+
}
|
|
4254
|
+
};
|
|
4255
|
+
Anthropic.Completions = Completions;
|
|
4256
|
+
Anthropic.Messages = Messages2;
|
|
4257
|
+
Anthropic.Models = Models2;
|
|
4258
|
+
Anthropic.Beta = Beta;
|
|
4259
|
+
});
|
|
4260
|
+
|
|
4261
|
+
export { AnthropicError, APIError, APIUserAbortError, APIConnectionError, APIConnectionTimeoutError, AuthenticationError, NotFoundError, init_error, Stream, init_api_promise, init_pagination, init_uploads2 as init_uploads, init_error2 as init_error1, init_streaming2 as init_streaming, Beta, Completions, Messages2 as Messages, init_resources, BaseAnthropic, Anthropic, init_client };
|