@bkm016/basalt 0.1.8 → 0.1.10
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/{chunk-0039s4jt.js → chunk-02d3x4mj.js} +3 -3
- package/{chunk-ky55taar.js → chunk-0mjb3sm3.js} +327 -316
- package/{chunk-ckjw3b61.js → chunk-13gvs0ax.js} +2 -2
- package/{chunk-0d51ggzj.js → chunk-1n7dat03.js} +4 -4
- package/{chunk-ppxv5q7y.js → chunk-1zj3zvw5.js} +3 -3
- package/{chunk-2ek3wq4b.js → chunk-29qrxygd.js} +1 -1
- package/{chunk-7p6e2f5s.js → chunk-30rjf7my.js} +3 -3
- package/{chunk-v2srrqcv.js → chunk-38g3gctw.js} +2 -2
- package/chunk-3mqf9ped.js +479 -0
- package/{chunk-3j2kkgsc.js → chunk-4dw43syb.js} +1 -1
- package/{chunk-t66jqz12.js → chunk-4gtgqcct.js} +2 -2
- package/{chunk-qmdpgbg3.js → chunk-755sy11p.js} +1 -1
- package/{chunk-n015c8nx.js → chunk-7zkswxvk.js} +1 -1
- package/{chunk-91r5nvth.js → chunk-82v8jh1h.js} +2 -2
- package/{chunk-12trygzx.js → chunk-95964592.js} +16 -16
- package/{chunk-nmtk9xra.js → chunk-9as0p561.js} +2 -2
- package/{chunk-pn413hjw.js → chunk-a1352w87.js} +1 -1
- package/{chunk-rnt1ckk9.js → chunk-a1rb1a48.js} +5 -5
- package/{chunk-fzcmzbsq.js → chunk-a98wma9j.js} +1 -1
- package/{chunk-kgkrccr1.js → chunk-asyr3gnq.js} +2 -2
- package/{chunk-5gxj9560.js → chunk-ax04trym.js} +1 -1
- package/chunk-b2bxqeb4.js +2 -0
- package/{chunk-xjw78yey.js → chunk-bdjr0kfr.js} +4 -4
- package/{chunk-7kjr9gdx.js → chunk-bk4rpnm8.js} +2 -2
- package/{chunk-47vf66t6.js → chunk-c0zfefq8.js} +1 -1
- package/{chunk-kpvaqb7c.js → chunk-c6q04xrd.js} +2 -2
- package/chunk-c71173py.js +25 -0
- package/{chunk-adys4qq4.js → chunk-cmwdjes8.js} +5 -5
- package/{chunk-dcwdmpw2.js → chunk-d0a1jxk5.js} +1 -1
- package/{chunk-2nrkqq45.js → chunk-d5j74pcp.js} +7 -7
- package/{chunk-pkpj7s2k.js → chunk-dfh9m9n7.js} +1 -1
- package/{chunk-26cz8et8.js → chunk-dq01v5eq.js} +1 -1
- package/{chunk-fpxc6qjr.js → chunk-e1x629v0.js} +2 -2
- package/{chunk-86xhmz7k.js → chunk-en218k4y.js} +1 -1
- package/{chunk-3hg7yn1t.js → chunk-fgwda4m0.js} +1 -1
- package/chunk-gbjn6d81.js +2 -0
- package/{chunk-x496kg3v.js → chunk-gkf5jwvj.js} +1 -1
- package/{chunk-k3q5jqjj.js → chunk-hb4f2v34.js} +2 -2
- package/{chunk-mr807v9n.js → chunk-hbnmymaq.js} +1 -1
- package/{chunk-818nd6s1.js → chunk-jj4hqbrx.js} +2 -2
- package/{chunk-jyv9cae6.js → chunk-jn5pqy5v.js} +1 -1
- package/{chunk-yyy2yp6f.js → chunk-jtsve11b.js} +9 -9
- package/chunk-m1eam0s5.js +2 -0
- package/{chunk-6vnjg5x9.js → chunk-mbpb5c7w.js} +1 -1
- package/{chunk-t40fag3z.js → chunk-msm9hmk9.js} +1 -1
- package/{chunk-j781n7ca.js → chunk-n0ybj4h9.js} +2 -2
- package/{chunk-jp5afrwm.js → chunk-n2jcx65v.js} +2 -2
- package/{chunk-2ks2tnac.js → chunk-nrsd810j.js} +2 -2
- package/chunk-pnspvnyd.js +2 -0
- package/chunk-pz2afna8.js +2 -0
- package/{chunk-d37gemt2.js → chunk-q9f4xb0w.js} +3 -3
- package/{chunk-hd3x1w46.js → chunk-qaeyhe65.js} +1 -1
- package/chunk-qnkrrwmg.js +2 -0
- package/{chunk-e6c2mzxc.js → chunk-r4ttdkrz.js} +2 -2
- package/{chunk-r9aatvwm.js → chunk-stj493dn.js} +2 -2
- package/{chunk-g3ed130w.js → chunk-tevejprz.js} +4 -4
- package/{chunk-k3rmjrf1.js → chunk-v3ee9z3f.js} +1 -1
- package/{chunk-4n49ptbz.js → chunk-vtqr7dm8.js} +2 -2
- package/{chunk-z3ch1wg6.js → chunk-xh444pfn.js} +14 -14
- package/{chunk-pehyqj8k.js → chunk-zc9ar0r4.js} +1 -1
- package/{chunk-ef9yhnk3.js → chunk-zyyzk5ha.js} +1 -1
- package/compiled.js +9 -9
- package/package.json +1 -1
- package/ui-test-worker.js +8 -8
- package/web/chunk-045d3b5d.js +1 -0
- package/web/{chunk-r4ffr96e.js → chunk-0770q5e1.js} +1 -1
- package/web/chunk-12qf1r6m.js +1 -0
- package/web/{chunk-s7e93552.js → chunk-18neka5g.js} +4 -4
- package/web/{chunk-et8q775x.js → chunk-1ev0n3n4.js} +5 -5
- package/web/chunk-1ex3wgms.js +2 -0
- package/web/{chunk-svh2gkx8.js → chunk-1qh7f5kr.js} +1 -1
- package/web/{chunk-s38s9ff9.js → chunk-26ecc2xh.js} +30 -30
- package/web/chunk-2cz7tx8q.js +1 -0
- package/web/chunk-32ty2xfn.js +1 -0
- package/web/{chunk-q1xxs319.js → chunk-3eexx7y5.js} +4 -4
- package/web/{chunk-v14s4vgc.js → chunk-46jnkghq.js} +1 -1
- package/web/chunk-4am8j3k3.js +1 -0
- package/web/{chunk-85gdsmt4.js → chunk-5qvmefq2.js} +1 -1
- package/web/chunk-5svqfj4g.js +3 -0
- package/web/{chunk-f93pe4kb.js → chunk-5v5q13hz.js} +4 -4
- package/web/chunk-5z2n4z9x.css +1 -0
- package/web/{chunk-qcge7d6s.js → chunk-6e87m0nm.js} +2 -2
- package/web/chunk-6y55gk1n.js +1 -0
- package/web/chunk-7np1jp3x.js +8 -0
- package/web/chunk-87e8d1hv.js +1 -0
- package/web/{chunk-33w36n91.js → chunk-88wd49xe.js} +2 -2
- package/web/chunk-8h2x89tw.js +2 -0
- package/web/chunk-8y2526ve.js +1 -0
- package/web/chunk-905vw286.js +2 -0
- package/web/chunk-918e5t4x.js +2 -0
- package/web/chunk-96m2m3e8.js +1 -0
- package/web/chunk-9f4zzqbx.js +1 -0
- package/web/{chunk-fe31sv6t.js → chunk-9yfftz38.js} +1 -1
- package/web/{chunk-z0zrp8n8.js → chunk-a1n4468c.js} +1 -1
- package/web/chunk-arnzrqnm.js +1 -0
- package/web/{chunk-c01176kn.js → chunk-awkdw9rw.js} +2 -2
- package/web/{chunk-m5y2d4zv.js → chunk-b46ws7rf.js} +1 -1
- package/web/chunk-bc3ajvfg.js +24 -0
- package/web/chunk-bwy3e58v.js +1 -0
- package/web/{chunk-ja7w629n.js → chunk-c57f714b.js} +2 -2
- package/web/chunk-d5gshd1a.js +1 -0
- package/web/chunk-de40q05r.js +30 -0
- package/web/chunk-dp0k5vhd.js +1 -0
- package/web/{chunk-qq2v8h6d.js → chunk-dv1berk6.js} +5 -5
- package/web/{chunk-jzte2phh.js → chunk-eh7wp62z.js} +1 -1
- package/web/{chunk-823b7866.js → chunk-ehtmb6sn.js} +18 -18
- package/web/{chunk-d9wdsjkk.js → chunk-eqndhs21.js} +2 -2
- package/web/chunk-et1hytyv.js +1 -0
- package/web/chunk-f7jpakwh.js +1 -0
- package/web/chunk-f9m9seam.js +1 -0
- package/web/{chunk-7a4xk6j9.js → chunk-fmmrthpa.js} +5 -5
- package/web/{chunk-fv6vm14n.js → chunk-frnh4zqf.js} +2 -2
- package/web/chunk-g2erm7k0.js +1 -0
- package/web/chunk-g3kbn0t2.js +1 -0
- package/web/{chunk-h5cfg3vv.js → chunk-g7dc4hrd.js} +2 -2
- package/web/{chunk-dgwkqcz6.js → chunk-g7kz8f7q.js} +2 -2
- package/web/chunk-ght0t49g.js +1 -0
- package/web/{chunk-jjjtv2r1.js → chunk-ghwm7bdj.js} +2 -2
- package/web/{chunk-sda7cyrt.js → chunk-grm2208k.js} +21 -21
- package/web/{chunk-0zwc2rvh.js → chunk-gsw1tv96.js} +1 -1
- package/web/chunk-gw8x1g61.js +24 -0
- package/web/chunk-gx340asc.js +1 -0
- package/web/chunk-h2txs73e.js +39 -0
- package/web/chunk-h3tkacc7.js +1 -0
- package/web/{chunk-cyjnert7.js → chunk-h5ckjk48.js} +16 -16
- package/web/{chunk-1s8zg6fb.js → chunk-j37p0b13.js} +5 -5
- package/web/chunk-j89s11x8.js +78 -0
- package/web/{chunk-jam45rqg.js → chunk-jccz14ye.js} +2 -2
- package/web/chunk-je78j3vr.js +1 -0
- package/web/chunk-jke2ev6m.js +2 -0
- package/web/{chunk-1gx0zpmp.js → chunk-js6kb05s.js} +9 -9
- package/web/{chunk-30b33r2w.js → chunk-k0cg4n2k.js} +2 -2
- package/web/{chunk-tkp72r9b.js → chunk-knm82fw9.js} +1 -1
- package/web/{chunk-xb9m0092.js → chunk-kxdtg9dt.js} +1 -1
- package/web/{chunk-w37n09px.js → chunk-m4fxd5d9.js} +10 -10
- package/web/chunk-m9xzt9p7.js +1 -0
- package/web/{chunk-8773nwdc.js → chunk-myd6sc76.js} +1 -1
- package/web/{chunk-sf101c23.js → chunk-mykrm8ba.js} +2 -2
- package/web/chunk-mzzaet63.js +1 -0
- package/web/{chunk-2axwda8c.js → chunk-n4yzs2q0.js} +7 -7
- package/web/{chunk-wj3ymejj.js → chunk-nawxgz87.js} +4 -4
- package/web/chunk-ngt1j8py.js +1139 -0
- package/web/{chunk-hstbgb83.js → chunk-p55vhns6.js} +5 -5
- package/web/{chunk-xabcx3ry.js → chunk-pgwf37s2.js} +3 -3
- package/web/chunk-q34as3v6.js +1 -0
- package/web/{chunk-dtg5yhhs.js → chunk-q4bst4an.js} +1 -1
- package/web/chunk-qdzy124b.js +4 -0
- package/web/chunk-qe0bgeda.js +1 -0
- package/web/{chunk-sd3cdqcm.js → chunk-qh62nkem.js} +2 -2
- package/web/{chunk-j1bw5v1g.js → chunk-qq6m2my8.js} +2 -2
- package/web/{chunk-8dp7h6w8.js → chunk-qy1zx2yw.js} +16 -16
- package/web/chunk-rag65pfs.js +4 -0
- package/web/chunk-rbqnre6q.js +36 -0
- package/web/{chunk-hbkasy6c.js → chunk-rh3xb76f.js} +22 -22
- package/web/{chunk-fx4mackk.js → chunk-rwfmccmh.js} +4 -4
- package/web/{chunk-mf6xng5b.js → chunk-rxvm70w5.js} +2 -2
- package/web/chunk-sat7zyva.js +1 -0
- package/web/{chunk-cn0tmwjs.js → chunk-sc63488q.js} +2 -2
- package/web/{chunk-xsz1dfm2.js → chunk-sd3xat3r.js} +20 -20
- package/web/{chunk-nky3bqfg.js → chunk-se4h6wx0.js} +1 -1
- package/web/chunk-sjkg40ay.js +7 -0
- package/web/chunk-sk0hpa80.js +1 -0
- package/web/{chunk-xqyazzm7.js → chunk-t5nvgz7z.js} +5 -5
- package/web/{chunk-3q0v8w45.js → chunk-tfqarvdx.js} +80 -80
- package/web/{chunk-d0m0h0eb.js → chunk-tqze6d6b.js} +1 -1
- package/web/{chunk-rbdvc8x7.js → chunk-tt93zbn4.js} +7 -7
- package/web/chunk-tvcxrx6h.js +1 -0
- package/web/chunk-tzpnh70q.js +1 -0
- package/web/{chunk-8wg44w91.js → chunk-vasppf6b.js} +2 -2
- package/web/chunk-vb7g4xg6.js +1 -0
- package/web/chunk-w3zgfhjb.js +2 -0
- package/web/{chunk-0j9a7811.js → chunk-wrevb4ew.js} +6 -6
- package/web/chunk-wtvch4ad.js +106 -0
- package/web/chunk-wzfe6jtq.js +1 -0
- package/web/{chunk-cez1k71m.js → chunk-x5g1yy12.js} +1 -1
- package/web/chunk-x850q01z.js +1 -0
- package/web/chunk-xh4xn1az.js +1 -0
- package/web/chunk-xk904wqv.js +1 -0
- package/web/chunk-xtn305fd.js +1 -0
- package/web/chunk-xzwxcxb4.js +1 -0
- package/web/{chunk-4anjs6yp.js → chunk-y2rzeb4v.js} +2 -2
- package/web/chunk-yekaz74b.js +1 -0
- package/web/{chunk-8nv7q5ac.js → chunk-yppgejg7.js} +15 -15
- package/web/chunk-ys2tns0p.js +1 -0
- package/web/chunk-z4bp6p32.js +62 -0
- package/web/{chunk-p0cjvjdx.js → chunk-z5qn0xev.js} +1 -1
- package/web/{chunk-rkjkynm3.js → chunk-zms6mrqk.js} +12 -12
- package/web/{chunk-6e38yf3a.js → chunk-zse05v6j.js} +4 -4
- package/web/{chunk-cn1xpg3q.js → chunk-zz1qkaar.js} +2 -2
- package/web/index.html +1 -1
- package/worker.js +1 -1
- package/chunk-2gcp3xdc.js +0 -2
- package/chunk-320174qe.js +0 -2
- package/chunk-dvb5nd2x.js +0 -2
- package/chunk-frt9k18g.js +0 -480
- package/chunk-ndt6rjt9.js +0 -2
- package/chunk-xy2bxwq8.js +0 -2
- package/chunk-yzevjkms.js +0 -25
- package/chunk-zdyd8hbn.js +0 -2
- package/web/chunk-0jfda4jw.js +0 -2
- package/web/chunk-2p3fkhy8.js +0 -1
- package/web/chunk-3sz5qcwj.js +0 -1
- package/web/chunk-433c80pc.js +0 -1
- package/web/chunk-48cnmhvd.js +0 -106
- package/web/chunk-5r37rwq1.js +0 -4
- package/web/chunk-6bwgdvf6.js +0 -1
- package/web/chunk-7f1t7z72.js +0 -2
- package/web/chunk-7x35g67d.js +0 -78
- package/web/chunk-8pzg8qw4.js +0 -1
- package/web/chunk-8r0s8tx7.js +0 -1
- package/web/chunk-9p5dfvav.js +0 -1
- package/web/chunk-9q9w9pay.js +0 -1
- package/web/chunk-a3teqvz2.js +0 -39
- package/web/chunk-ahztazsg.js +0 -1
- package/web/chunk-bd8ftfxn.js +0 -3
- package/web/chunk-c03bt2pz.js +0 -1
- package/web/chunk-c1ha2xg6.js +0 -8
- package/web/chunk-cgng31df.js +0 -1
- package/web/chunk-cvd4f51j.js +0 -1
- package/web/chunk-cybvxssy.js +0 -1
- package/web/chunk-d22wq71s.js +0 -1
- package/web/chunk-dynajx8x.js +0 -2
- package/web/chunk-f3vv7n52.js +0 -1
- package/web/chunk-fmthkpff.js +0 -1
- package/web/chunk-fpa81dv7.js +0 -62
- package/web/chunk-g17n6asp.js +0 -1
- package/web/chunk-g9dzaw9e.js +0 -30
- package/web/chunk-gcwhx3av.js +0 -1139
- package/web/chunk-gf8vm6b5.js +0 -1
- package/web/chunk-gnmeyy4h.js +0 -1
- package/web/chunk-hn7mhsbg.js +0 -1
- package/web/chunk-jfvxxp5c.js +0 -1
- package/web/chunk-k8h8zx6r.js +0 -24
- package/web/chunk-m3ajw575.js +0 -1
- package/web/chunk-mbwwj216.js +0 -1
- package/web/chunk-mz9b5bsa.js +0 -1
- package/web/chunk-np33kmn4.js +0 -1
- package/web/chunk-nvk8mazs.js +0 -1
- package/web/chunk-nyw5ewgv.js +0 -1
- package/web/chunk-p56dcqpr.js +0 -1
- package/web/chunk-pdn4r8x4.js +0 -1
- package/web/chunk-qpt34d8d.js +0 -1
- package/web/chunk-qskt3tqa.js +0 -1
- package/web/chunk-qt3n897m.js +0 -4
- package/web/chunk-r1rt48h9.js +0 -1
- package/web/chunk-r7tgd2fm.js +0 -7
- package/web/chunk-rznszqmy.js +0 -1
- package/web/chunk-s1pefd34.js +0 -1
- package/web/chunk-sc29azev.js +0 -1
- package/web/chunk-t4jc4nac.js +0 -1
- package/web/chunk-t7g366a5.js +0 -24
- package/web/chunk-thbqwq6b.js +0 -1
- package/web/chunk-v94v68xg.js +0 -36
- package/web/chunk-wcphswcx.js +0 -2
- package/web/chunk-wwcnvyjh.css +0 -1
- package/web/chunk-xce8n339.js +0 -1
- package/web/chunk-xfd3b01q.js +0 -1
- package/web/chunk-xtss82z2.js +0 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
3
|
-
`);if(r[r.length-1]==="")r.pop();return r}function Mt(a,r){return/^[\x20-\x7E]+$/.test(r)&&!/[\\^#]/.test(r)&&!(a==="unzip"&&r.startsWith("-"))}function
|
|
2
|
+
import{So,St,st,w,un,wo}from"./chunk-b2bxqeb4.js";import{o,e,u,Ot,vt,T,ue,E,To,Mr,Dt}from"./chunk-vtqr7dm8.js";import*as b from"fs/promises";import*as ne from"fs";import*as v from"path";import*as $e from"child_process";import*as ct from"crypto";import*as lt from"readline";function C(a){if(a.inputSchema.type!=="object")throw Error(`JSON schema for tool "${a.name}" must be an object, but got ${a.inputSchema.type}`);return{type:"custom",name:a.name,input_schema:a.inputSchema,description:a.description,run:a.run,parse:(r)=>r,...a.close?{close:a.close}:{}}}var F=st.promises,J=448,yt=384;function ae(a,r){let t=w.relative(a,r);return t===""||!t.startsWith(".."+w.sep)&&t!==".."&&!w.isAbsolute(t)}async function Ee(a,r){for(let t of a)if(ae(await X(w.resolve(t)),r))return t;return}var wt=40;function Z(a){let r=a?.code;return typeof r==="string"?r:void 0}async function X(a){let r=[],t=a,i=0;for(;;){let n;try{n=await F.realpath(t)}catch(s){let c;try{c=(await F.lstat(t)).isSymbolicLink()}catch(l){let f=Z(l);if(f!=="ENOENT"&&f!=="ENOTDIR")throw l;let h=w.dirname(t);if(h===t)throw l;r.push(w.basename(t)),t=h;continue}if(!c)throw s;if(++i>wt)throw Object.assign(Error("too many levels of symbolic links"),{code:"ELOOP"});t=w.resolve(w.dirname(t),await F.readlink(t));continue}return r.length?w.join(n,...r.reverse()):n}}async function Ae(a,r,t){let i=t?.allowedRoots??[],n=await X(w.resolve(a)),s;try{s=await X(w.resolve(n,r))}catch(l){throw new E(q(l,`path ${JSON.stringify(r)}`))}if(ae(n,s)||await Ee(i,s)!==void 0)return s;let c=i.length?"the session's working directory and its other permitted directories":"the session's working directory";throw new E(`path ${JSON.stringify(r)} is outside ${c}`)}async function be(a,r){let t=w.dirname(a),i=w.join(t,`.tmp-${process.pid}-${St.randomUUID()}`),n=await F.stat(a).then((c)=>c.mode&511,()=>{return}),s;try{if(s=await F.open(i,"wx",yt),n!==void 0)await s.chmod(n);await s.writeFile(r,"utf-8"),await s.sync(),await s.close(),s=void 0,await F.rename(i,a)}catch(c){if(s)await s.close().catch(()=>{});throw await F.unlink(i).catch(()=>{}),c}}function q(a,r){let t=Z(a);switch(t){case"ENOENT":return`${r}: no such file or directory`;case"EACCES":case"EPERM":return`${r}: permission denied`;case"ENOTDIR":return`${r}: not a directory`;case"EISDIR":return`${r}: is a directory`;case"ELOOP":return`${r}: too many levels of symbolic links`;case"ENAMETOOLONG":return`${r}: file name too long`;case"ENOSPC":return`${r}: no space left on device`;case"EMFILE":case"ENFILE":return`${r}: too many open files`;default:return`${r}: ${t!==void 0?`i/o error (${t})`:"i/o error"}`}}var R=st.promises,_t=wo.promisify(So.execFile);async function gt(a){let{client:r,sessionId:t}=a;if(!r)return async()=>{};let i=T(r),n=a.session;if(!n){if(t===void 0)return async()=>{};i.warn("AgentToolContext.sessionId is deprecated and costs an extra session fetch; fetch the session once and set `session` instead",{component:"agent-tool-context"}),n=await r.beta.sessions.retrieve(t)}let s=w.resolve(a.workdir,"skills"),c=[];for(let l of n.agent.skills)try{let f=await r.beta.skills.versions.retrieve(l.version,{skill_id:l.skill_id}),h=w.basename(f.name.trim());if(h===""||h==="."||h==="..")h=l.skill_id;let d=w.resolve(s,h);if(d!==s&&!d.startsWith(s+w.sep)){i.warn("skill name escapes the skills dir; skipping",{component:"agent-tool-context",name:f.name});continue}let m=await r.beta.skills.versions.download(f.id,{skill_id:l.skill_id});await R.rm(d,{recursive:!0,force:!0}),await R.mkdir(d,{recursive:!0,mode:J}),c.push(d),await Ce(m,d),i.info("downloaded skill",{component:"agent-tool-context",skill_id:l.skill_id,version:f.id,dest:d})}catch(f){i.warn("failed to download skill",{component:"agent-tool-context",skill_id:l.skill_id,error:String(f)})}return async()=>{for(let l of c)await R.rm(l,{recursive:!0,force:!0}).catch((f)=>{i.warn("failed to clean up skill",{component:"agent-tool-context",dest:l,error:String(f)})})}}function Et(a){for(let r of a){let t=r.trim();if(!t)continue;if(w.isAbsolute(t)||t.split(/[\\/]/).includes(".."))throw new u(`refusing to extract unsafe archive member: ${t}`)}}var Me="skill archive listing is inconsistent; refusing to extract",bt={unzip:new Set(["-","d","?"]),tar:new Set(["-","d","C"])};function xe(a){let r=a.split(`
|
|
3
|
+
`);if(r[r.length-1]==="")r.pop();return r}function Mt(a,r){return/^[\x20-\x7E]+$/.test(r)&&!/[\\^#]/.test(r)&&!(a==="unzip"&&r.startsWith("-"))}function kt(a,r,t){let i=xe(r),n=xe(t);if(i.length!==n.length)throw new u(Me);let s=[],c=[];return i.forEach((l,f)=>{if(bt[a].has(n[f].charAt(0))){s.push(l);return}if(!Mt(a,l))throw new u(`refusing to extract archive: cannot safely exclude member ${JSON.stringify(l)}`);c.push(l)}),{plain:s,special:c}}async function De(a){for(let r of await R.readdir(a,{withFileTypes:!0}))if(r.isDirectory())await De(w.join(a,r.name));else if(!r.isFile())throw new u(Me)}async function Oe(a,r){try{let{stdout:t}=await _t(a,r);return t}catch(t){if(Z(t)==="ENOENT")throw new u(`skill extraction requires the \`${a}\` command, but it was not found on PATH`);throw t}}function It(a){let r,t=!1;for(let i of a){let n=i.trim().split("/").filter((c)=>c!==""&&c!==".");if(n.length===0)continue;let s=n[0];if(r===void 0)r=s;else if(s!==r)return"";if(n.length>1)t=!0}return r!==void 0&&t?r:""}async function Ce(a,r){let t=w.join(r,`.skill-archive-${process.pid}-${Date.now()}`);if(!a.body)throw new u("skill download response had no body");await un.promises.pipeline(un.Readable.fromWeb(a.body),st.createWriteStream(t));let i=w.join(w.dirname(r),`.skill-stage-${process.pid}-${Date.now()}`),n=w.join(w.dirname(r),`.skill-exclude-${process.pid}-${Date.now()}`);try{let s=await Nt(t,4),c=s.length>=4&&s[0]===80&&s[1]===75&&s[2]===3&&s[3]===4,l=c?"unzip":"tar",f=await Oe(l,c?["-Z1",t]:["-tf",t]),h=await Oe(l,c?["-Z","--h","--t",t]:["-tvf",t]),{plain:d,special:m}=kt(l,f,h);Et([...d,...m]);let g=It(d);if(await R.mkdir(i,{recursive:!0,mode:J}),d.length>0)await Oe(l,await Rt(l,t,i,m,n));await De(i);let O=g?w.join(i,g):i,D=await R.readdir(O).catch((k)=>{throw Z(k)==="ENOENT"?new u(Me):k});for(let k of D)await R.rename(w.join(O,k),w.join(r,k))}finally{await R.rm(t,{force:!0}),await R.rm(n,{force:!0}),await R.rm(i,{recursive:!0,force:!0})}}async function Rt(a,r,t,i,n){let s=i.map((c)=>c.replace(/[*?[\\]/g,"\\$&"));if(a==="unzip")return["-oq",r,"-d",t,...s.length>0?["-x",...s]:[]];if(s.length===0)return["-xf",r,"-C",t];return await R.writeFile(n,s.join(`
|
|
4
4
|
`)+`
|
|
5
|
-
`,{flag:"wx",mode:384}),["-xf",r,"-C",t,"-X",n]}async function
|
|
6
|
-
${a}`,"utf-8").digest("hex")}var qt=30000,zt=100,Gt=20,Ht=16,Kt=32,Vt=8,Xt=50;class P extends
|
|
7
|
-
${t.memoryStoreId}`);for await(let[i,n]of e(this,_,"m",
|
|
8
|
-
`),ie=102400,tr=2000,rr=200;class dt extends
|
|
9
|
-
} </dev/null 2>&1; printf '\\n${
|
|
10
|
-
`;if(e(this,M,"f").stdin.write(
|
|
11
|
-
${g}`;return{output:g,exitCode:
|
|
12
|
-
`),
|
|
13
|
-
`)}})}async function lr(a,r,t,i,n){let s=new fr(r,t,i,n);if(s.rangeIsEmpty())return"";let
|
|
14
|
-
`)}})}function pr(a){return Y(a.unrestrictedPaths),C({name:"grep",description:"Search file contents for a regex. Uses ripgrep if available, otherwise a built-in walker.",inputSchema:{type:"object",properties:{pattern:{type:"string"},path:{type:"string"}},required:["pattern"]},run:async({pattern:r,path:t},i)=>{if(!r)throw new E("grep: pattern is required");let n=v.resolve(a.workdir);if(t)n=await oe(a,t);let s=await Sr();return s?yr(s,r,n,i?.signal):wr(r,n,i?.signal)}})}function yr(a,r,t,i){return new Promise((n,s)=>{let
|
|
15
|
-
[output truncated at ${ie} bytes]`);if(
|
|
16
|
-
`)}async function
|
|
5
|
+
`,{flag:"wx",mode:384}),["-xf",r,"-C",t,"-X",n]}async function Nt(a,r){let t=await R.open(a,"r");try{let i=Buffer.alloc(r),{bytesRead:n}=await t.read(i,0,r,0);return i.subarray(0,n)}finally{await t.close()}}var S=st.promises,z=st.constants,Ue=448,Tt=384,Lt=448,ke=z.O_NOFOLLOW??0,$t=z.O_NONBLOCK??0,y=(()=>{class a extends Error{constructor(r,t){super(`path ${JSON.stringify(t)} ${r}`);this.name="FileStoreError",this.reason=r,this.relPath=t}}return a.ESCAPES_ROOT="escapes the store root",a.IS_A_SYMLINK="is a symlink",a.NOT_A_FILE="is not a regular file",a.NOT_A_DIRECTORY="is not a directory",a.NOT_UTF8="is not valid utf-8",a.MOVE_DESTINATION_EXISTS="already exists",a})();function Ie(a){return a.startsWith("/")&&!a.split("/").includes("..")}var ve=(()=>{class a{constructor(r,t,i=!1){this.hashes=new Map,this.rootPath=r,this.removedOnDispose=t,this.decoder=i?new TextDecoder("utf-8",{fatal:!0}):void 0}static async open(r,t){if(!At())throw Error("FileStore requires O_NOFOLLOW support on this platform");let i=!1;try{await S.lstat(r)}catch(n){if(n.code!=="ENOENT")throw n;i=!0}return new a(w.resolve(r),i,t?.utf8??!1)}async createRoot(){await xt(this.rootPath)}root(){return{path:this.rootPath,removedOnDispose:this.removedOnDispose}}async dispose(){if(!this.removedOnDispose)return;await S.rm(this.rootPath,{recursive:!0,force:!0})}async put(r,t,i){let n=r.replace(/\\/g,"/");if(n.endsWith("/")||n.endsWith("/.")||n===""||n===".")throw new y(y.NOT_A_FILE,r);let s=this.resolveUnderRoot(r),c=typeof t==="string"?Ot(t):t;this.requireUtf8(r,c),await Fe(this.rootPath,w.dirname(s)),await Ct(s,c,i?.executable??!1)}async get(r){let t=this.resolveUnderRoot(r),i;try{i=await je(r,t)}catch(s){if(s.code==="ENOENT")return null;throw s}let n;try{let s=await i.readFile();n=new Uint8Array(s.buffer,s.byteOffset,s.byteLength)}finally{await i.close()}return this.requireUtf8(r,n),n}async ls(r="/"){let t=this.resolveUnderRoot(r);return new Set((await Pe(this.rootPath,r,t)).map(([i])=>i))}async findSymlinks(r="/"){let t=this.resolveUnderRoot(r);return Pt(this.rootPath,r,t)}async hashtree(r="/"){let t=this.resolveUnderRoot(r),i=ce.nowNs(),n=Object.create(null);for(let[s,c]of await Pe(this.rootPath,r,t)){let l=await this.hashViaCache(s,c,i);if(l!==null)n[s]=l}return n}async hashFile(r){let t=this.resolveUnderRoot(r),i;try{i=await S.lstat(t,{bigint:!0})}catch(s){if(s.code==="ENOENT")return null;throw s}if(i.isSymbolicLink())throw new y(y.IS_A_SYMLINK,r);if(!i.isFile())throw new y(y.NOT_A_FILE,r);let n=w.relative(this.rootPath,t).split(w.sep).join("/");return this.hashViaCache(n,t,ce.nowNs())}async move(r,t){let i=this.resolveUnderRoot(r),n=this.resolveUnderRoot(t);if(i===this.rootPath||n===this.rootPath)return;if(await S.stat(n).then(()=>!0,()=>!1))throw new y(y.MOVE_DESTINATION_EXISTS,t);await Fe(this.rootPath,w.dirname(n)),await S.rename(i,n)}async remove(r){let t=this.resolveUnderRoot(r);if(t===this.rootPath)return;let i;try{i=await S.lstat(t,{bigint:!0})}catch(n){if(n.code==="ENOENT")return;throw n}if(i.isDirectory())await S.rm(t,{recursive:!0,force:!0});else try{await S.unlink(t)}catch(n){if(n.code!=="ENOENT")throw n}}resolveUnderRoot(r){let t=r.replace(/\\/g,"/").replace(/^\/+/,""),i=t.split("/").filter((n)=>n!==""&&n!==".");if(w.posix.isAbsolute(t)||i.includes(".."))throw new y(y.ESCAPES_ROOT,r);return i.length===0?this.rootPath:w.join(this.rootPath,...i)}requireUtf8(r,t){if(!this.decoder)return;try{this.decoder.decode(t)}catch{throw new y(y.NOT_UTF8,r)}}async hashViaCache(r,t,i){let n;try{n=await S.lstat(t,{bigint:!0})}catch(l){if(l.code==="ENOENT")return null;throw l}if(!n.isFile())return null;let s=this.hashes.get(r),c;if(s!==void 0&&Ut(s,n))c=s.sha;else try{c=await ce.hashFile(t)}catch(l){let f=l.code;if(f==="ENOENT"||l instanceof y)return null;if(f==="ELOOP"||f==="EMLINK")return null;throw l}if(jt(n,i))this.hashes.set(r,{mtimeNs:n.mtimeNs,ctimeNs:n.ctimeNs,size:n.size,sha:c});return c}}return a.isPathLegal=Ie,a})();function At(){return ke!==0}async function xt(a){let r=[],t=a;for(;;){try{await S.stat(t);break}catch(n){let s=n.code;if(s!=="ENOENT"&&s!=="ENOTDIR"&&s!=="ELOOP")throw n}r.push(t);let i=w.dirname(t);if(i===t)break;t=i}for(let i of r.reverse())try{await S.mkdir(i,{mode:Ue})}catch(n){if(n.code!=="EEXIST")throw n}}async function Fe(a,r){let t=w.relative(a,r);if(t==="")return;let i=a;for(let n of t.split(w.sep)){i=w.join(i,n);try{await S.mkdir(i,{mode:Ue})}catch(s){if(s.code!=="EEXIST")throw s}}}async function Ct(a,r,t){let i=t?Lt:Tt,n=w.join(w.dirname(a),`.fs-${St.randomBytes(8).toString("hex")}.tmp`),s;try{s=await S.open(n,z.O_WRONLY|z.O_CREAT|z.O_EXCL|ke,i),await s.writeFile(r),await s.close(),s=void 0,await S.rename(n,a)}catch(c){if(s)await s.close().catch(()=>{});throw await S.unlink(n).catch(()=>{}),c}}async function je(a,r){let t;try{t=await S.open(r,z.O_RDONLY|ke|$t)}catch(i){let n=i.code;if(n==="ELOOP"||n==="EMLINK")throw new y(y.IS_A_SYMLINK,a);throw i}try{if(!(await t.stat()).isFile())throw new y(y.NOT_A_FILE,a)}catch(i){throw await t.close().catch(()=>{}),i}return t}async function Ft(a){let r=St.createHash("sha256"),t=await je(w.basename(a),a),i=new Uint8Array(1048576);try{for(;;){let{bytesRead:n}=await t.read(i,0,i.length);if(n===0)break;r.update(i.subarray(0,n))}}finally{await t.close()}return r.digest("hex")}async function Pe(a,r,t){if(!await Wt(r,t))return[];let i=[];return await Be(t,(n,s)=>{if(s.isFile())i.push([w.relative(a,n).split(w.sep).join("/"),n])}),i.sort(),i}async function Pt(a,r,t){let i=(c)=>w.relative(a,c).split(w.sep).join("/"),n;try{n=await S.lstat(t,{bigint:!0})}catch(c){let l=c.code;if(l==="ENOENT"||l==="ENOTDIR")return new Set;throw c}if(n.isSymbolicLink())return new Set([i(t)]);if(!n.isDirectory())throw new y(y.NOT_A_DIRECTORY,r);let s=new Set;return await Be(t,(c,l)=>{if(l.isSymbolicLink())s.add(i(c))}),s}async function Wt(a,r){let t;try{t=await S.lstat(r,{bigint:!0})}catch(i){let n=i.code;if(n==="ENOENT"||n==="ENOTDIR")return!1;throw i}if(!t.isDirectory())throw new y(y.NOT_A_DIRECTORY,a);return!0}async function Be(a,r){let t=[a];while(t.length){let i=t.pop(),n;try{n=await S.readdir(i,{withFileTypes:!0})}catch(s){if(s.code==="ENOENT")continue;throw s}for(let s of n){let c=w.join(i,s.name);if(r(c,s),s.isDirectory()&&!s.isSymbolicLink())t.push(c)}}}function Ut(a,r){return r.mtimeNs===a.mtimeNs&&r.ctimeNs===a.ctimeNs&&r.size===a.size}function jt(a,r){return(a.mtimeNs>a.ctimeNs?a.mtimeNs:a.ctimeNs)<r-ce.timestampTrustMarginNs}var Bt=2000000000n,ce={hashFile:Ft,timestampTrustMarginNs:Bt,nowNs:()=>BigInt(Date.now())*1000000n},Ye=ve,We=Symbol.asyncDispose;if(We)Object.defineProperty(ve.prototype,We,{value:ve.prototype.dispose,configurable:!0,writable:!0});var _,L,le,Q,fe,p,G,de,A,qe,he,ze,Ge,Re,Ne,He,Ke,Te,Ve,Xe,me,pe,Je,Ze,Yt=30000,K=".anthropic-memory-store",et=1;function Qe(a){return St.createHash("sha256").update(`version ${et}
|
|
6
|
+
${a}`,"utf-8").digest("hex")}var qt=30000,zt=100,Gt=20,Ht=16,Kt=32,Vt=8,Xt=50;class P extends u{constructor(a,r){super(a);if(this.name="SessionMemoryError",r!==void 0)this.cause=r}}class tt{constructor(a,r,t){this.mode=a,this.cap=r,this.waiveWindow=t,this.attempted=0,this.capped=0,this.suppressed=0}takeSlot(){if(this.attempted>=this.cap)return this.capped++,!1;return this.attempted++,!0}}var Jt=(()=>{class a{constructor(r,t){_.add(this),L.set(this,void 0),le.set(this,void 0),Q.set(this,void 0),fe.set(this,void 0),p.set(this,void 0),G.set(this,void 0),de.set(this,!1),A.set(this,[]),o(this,L,r,"f"),o(this,le,t.workdir,"f"),o(this,Q,t.syncIntervalMs??To,"f"),Mr(e(this,Q,"f"),"syncIntervalMs"),o(this,fe,t.syncDeletions??"enabled","f"),o(this,p,T(r),"f"),o(this,G,Date.now(),"f")}get roots(){return e(this,A,"f").map((r)=>r.files.root().path)}get readOnlyRoots(){return e(this,A,"f").filter((r)=>r.readOnly).map((r)=>r.files.root().path)}async download(r){for(let t of r.resources){if(t.type!=="memory_store")continue;let i=e(this,_,"m",qe).call(this,t),n;try{if(n={memoryStoreId:t.memory_store_id,files:await Ye.open(i,{utf8:!0}),readOnly:t.access==="read_only",baseline:new Map,refusedShas:new Map,pendingDeletes:new Map},!n.files.root().removedOnDispose)throw new P(`something already exists at the memory store's path: ${i} (memory_store_id=${t.memory_store_id}); it must not exist when the session starts`);try{await n.files.createRoot()}catch(s){if(!H(s))throw s;throw new P(`cannot create the memory store's folder: ${i} (memory_store_id=${t.memory_store_id}): ${s}; the worker host must make this mount path writable`,s)}await e(this,_,"m",Ne).call(this,n),e(this,p,"f").info("downloaded memories",{count:n.baseline.size,memory_store_id:n.memoryStoreId,dest:n.files.root().path}),e(this,A,"f").push(n)}catch(s){if(n)await n.files.dispose().catch(()=>{});if(s instanceof P)throw s;throw new P(`failed to download memory store memory_store_id=${t.memory_store_id}: ${s}`,s)}}o(this,G,Date.now(),"f")}async finish(){if(e(this,de,"f"))throw new u("finish() was already called: it is the session's last sync and runs once");o(this,de,!0,"f"),await this.syncAll(!0)}async syncAll(r){await Promise.all(e(this,A,"f").map((t)=>e(this,_,"m",ze).call(this,t,r))),o(this,G,Date.now(),"f")}async syncIfDue(){if(Date.now()-e(this,G,"f")<e(this,Q,"f"))return;await this.syncAll(!1)}async flushWrites(r){await Promise.all(e(this,A,"f").map((t)=>e(this,_,"m",Ge).call(this,t,r)))}async dispose(){for(let r of e(this,A,"f")){let t=r.files.root();try{let i=await e(this,_,"m",he).call(this,r);if(!i.markerOk&&Object.keys(i.files).length>0){e(this,p,"f").warn(`${i.distrustReason}; leaving the memory store folder on disk`,{root:t.path,memory_store_id:r.memoryStoreId});continue}await r.files.dispose()}catch(i){if(!(i instanceof y)&&!H(i))throw i;e(this,p,"f").warn("failed to remove the memory store folder",{root:r.files.root().path,memory_store_id:r.memoryStoreId,error:String(i)});continue}if(t.removedOnDispose)e(this,p,"f").info("removed memory store dir",{dest:t.path,memory_store_id:r.memoryStoreId})}}}return L=new WeakMap,le=new WeakMap,Q=new WeakMap,fe=new WeakMap,p=new WeakMap,G=new WeakMap,de=new WeakMap,A=new WeakMap,_=new WeakSet,qe=function(t){if(t.mount_path){if(!Ie(t.mount_path))throw new P(`memory store mount_path is not a clean absolute path: ${JSON.stringify(t.mount_path)} (memory_store_id=${t.memory_store_id})`);return t.mount_path}return w.join(e(this,le,"f"),"memory",t.name||t.memory_store_id)},he=async function(t){let i=await t.files.hashtree(),n=i[K];if(delete i[K],n===Qe(t.memoryStoreId))return{files:i,markerOk:!0,distrustReason:null};return{files:i,markerOk:!1,distrustReason:n!==void 0?"the marker file does not match this store":"the marker file is gone"}},ze=async function(t,i){try{let n=await e(this,_,"m",he).call(this,t),s=n.files;if(!n.markerOk){if(Object.keys(s).length>0){e(this,p,"f").warn(`${n.distrustReason}; leaving the memory store folder as found and not syncing`,{root:t.files.root().path,memory_store_id:t.memoryStoreId});return}await e(this,_,"m",Re).call(this,t,"the folder or its marker is gone");return}if(Object.keys(s).length===0&&t.baseline.size>1){await e(this,_,"m",Re).call(this,t,"every memory file is gone at once");return}let c=new Map;for await(let[m,g]of e(this,_,"m",me).call(this,t.memoryStoreId))c.set(m,g);let l=new tt(e(this,fe,"f"),Math.max(Vt,Math.min(Xt,Math.floor(t.baseline.size/4))),i),f=[],h=new Map,d=[...new Set([...c.keys(),...Object.keys(s),...t.baseline.keys()])].sort();for(let m of d){let g=c.get(m),O=s[m],D=t.baseline.get(m),k;if(O===void 0&&D!==void 0&&g!==void 0&&g.content_sha256===D&&!t.readOnly)k=await e(this,_,"m",Je).call(this,t,m,g,D,l);else k=await e(this,_,"m",He).call(this,t,m,g,O,f);if(k!==void 0)h.set(m,k)}if(t.baseline=h,await e(this,_,"m",Ve).call(this,t,f),l.suppressed>0)e(this,p,"f").debug("remote deletes are disabled; locally deleted memories stay on the server",{count:l.suppressed,memory_store_id:t.memoryStoreId});if(l.capped>0)e(this,p,"f").warn(`delete cap reached: ${l.mode==="log_only"?"would send":"sent"} ${l.attempted} deletes, held ${l.capped} for later syncs`,{memory_store_id:t.memoryStoreId})}catch(n){e(this,p,"f").warn("memory sync failed",{memory_store_id:t.memoryStoreId,error:String(n)})}},Ge=async function(t,i){let n=new Map,s=new Set,c=async()=>{if(t.readOnly)return;let l=await e(this,_,"m",he).call(this,t);if(!l.markerOk){e(this,p,"f").warn(`${l.distrustReason}; not uploading anything from the memory store folder`,{root:t.files.root().path,memory_store_id:t.memoryStoreId});return}for(let[d,m]of Object.entries(l.files))if(m!==t.baseline.get(d)&&t.refusedShas.get(d)!==m)n.set(d,m),s.add(d);if(n.size===0||i?.aborted)return;let f=new Map;for await(let[d,m]of e(this,_,"m",me).call(this,t.memoryStoreId)){if(i?.aborted)return;f.set(d,m)}let h=[];for(let d of[...n.keys()].sort()){let m=n.get(d),g=t.baseline.get(d),O=f.get(d);if(O!==void 0&&O.content_sha256===m){t.baseline.set(d,O.content_sha256),s.delete(d);continue}if(O!==void 0&&O.content_sha256!==g){e(this,p,"f").warn("memory changed both locally and remotely; the flush leaves the remote version",{path:d,memory_store_id:t.memoryStoreId}),s.delete(d);continue}h.push([d,m,O])}await e(this,_,"m",Xe).call(this,t,h,s,i)};try{if(await Zt(c(),i),i?.aborted&&s.size>0)e(this,p,"f").warn(`memory flush cut off part-way; ${s.size} of ${n.size} changed files had not finished uploading`,{memory_store_id:t.memoryStoreId})}catch(l){e(this,p,"f").warn("memory flush failed",{memory_store_id:t.memoryStoreId,error:String(l)})}},Re=async function(t,i){e(this,p,"f").warn(`${i}; re-downloading the memory store folder instead of syncing`,{root:t.files.root().path,memory_store_id:t.memoryStoreId}),await t.files.createRoot(),await e(this,_,"m",Ne).call(this,t)},Ne=async function(t){t.baseline=new Map,t.pendingDeletes.clear(),await t.files.put(K,`version ${et}
|
|
7
|
+
${t.memoryStoreId}`);for await(let[i,n]of e(this,_,"m",me).call(this,t.memoryStoreId,"full"))if(await e(this,_,"m",Te).call(this,t,i,n.content??""))t.baseline.set(i,n.content_sha256)},He=async function(t,i,n,s,c){let l=t.baseline.get(i);if(s!==void 0)t.pendingDeletes.delete(i);if(!n){if(s===void 0){t.pendingDeletes.delete(i);return}if(l!==void 0){if(s===l){let g=await e(this,_,"m",Ke).call(this,t,i,l);if(g===void 0)return;if(g===l)return l;s=g}if(t.readOnly)e(this,p,"f").warn("memory deleted remotely but edited locally; keeping the file, which a read-only store cannot push",{path:i,memory_store_id:t.memoryStoreId});else if(t.refusedShas.get(i)!==s)e(this,p,"f").info("memory deleted remotely but edited locally; re-creating it from the file",{path:i,memory_store_id:t.memoryStoreId})}if(t.readOnly)return;if(t.refusedShas.get(i)===s)return;return await e(this,_,"m",pe).call(this,t,i,s,void 0)}let f=n.content_sha256,h=f!==l,d=s!==void 0&&s!==l&&s!==f,m=!t.readOnly&&d;if(s===void 0&&l!==void 0){if(h)e(this,p,"f").warn("memory deleted locally but changed remotely; restoring the remote version",{path:i,memory_store_id:t.memoryStoreId}),t.pendingDeletes.delete(i),c.push([i,n]);return l}if(h){if(s===f)return f;if(d)e(this,p,"f").warn("memory changed both locally and remotely; keeping the remote version",{path:i,memory_store_id:t.memoryStoreId});return c.push([i,n]),l}if(m){if(t.refusedShas.get(i)===s)return f;return await e(this,_,"m",pe).call(this,t,i,s,n)??f}return f},Ke=async function(t,i,n){let s;try{s=await t.files.hashFile(i)}catch(c){if(!(c instanceof y)&&!H(c))throw c;return n}if(s===null)return;if(s!==n)return s;try{await t.files.remove(i)}catch(c){if(!(c instanceof y)&&!H(c))throw c;return e(this,p,"f").warn("failed to remove memory deleted remotely",{path:i,memory_store_id:t.memoryStoreId,error:String(c)}),n}return},Te=async function(t,i,n){try{await t.files.put(i,n)}catch(s){if(!(s instanceof y)&&!H(s))throw s;return e(this,p,"f").warn("failed to write memory",{path:i,memory_store_id:t.memoryStoreId,error:String(s)}),!1}return!0},Ve=async function(t,i){if(i.length===0)return;let n=async(l,f)=>{let h;try{h=await e(this,L,"f").beta.memoryStores.memories.retrieve(f.id,{memory_store_id:t.memoryStoreId,view:"full"})}catch(d){if(ue(d,404))return;e(this,p,"f").warn("failed to fetch memory content",{path:l,memory_store_id:t.memoryStoreId,error:String(d)});return}if(await e(this,_,"m",Te).call(this,t,l,h.content??""))t.baseline.set(l,h.content_sha256)},s=i[Symbol.iterator](),c=async()=>{for(let[l,f]of s)await n(l,f)};await Promise.all(Array.from({length:Math.min(Ht,i.length)},c))},Xe=async function(t,i,n,s){let c=i[Symbol.iterator](),l=async()=>{for(let[f,h,d]of c){if(s?.aborted)return;let m=await e(this,_,"m",pe).call(this,t,f,h,d);if(n.delete(f),m!==void 0)t.baseline.set(f,m)}};await Promise.all(Array.from({length:Math.min(Kt,i.length)},l))},me=async function*(t,i="basic"){let n=i==="basic"?zt:Gt;for await(let s of e(this,L,"f").beta.memoryStores.memories.list(t,{view:i,limit:n})){if(s.type!=="memory")continue;let c=s.path.replace(/^\/+/,"");if(c===K){e(this,p,"f").warn("the server listed the reserved marker path; skipping",{path:s.path,memory_store_id:t});continue}yield[c,s]}},pe=async function r(t,i,n,s){try{let c=await t.files.get(i);if(c===null)return;let l=vt(c),f=s?await e(this,L,"f").beta.memoryStores.memories.update(s.id,{memory_store_id:t.memoryStoreId,content:l,precondition:{type:"content_sha256",content_sha256:s.content_sha256}}):await e(this,L,"f").beta.memoryStores.memories.create(t.memoryStoreId,{path:"/"+i,content:l});return t.refusedShas.delete(i),f.content_sha256}catch(c){if(s&&ue(c,404))return await e(this,_,"m",r).call(this,t,i,n,void 0);let l=c instanceof y||ue(c,400)||ue(c,413);if(s&&ue(c,409))e(this,p,"f").warn("memory changed both locally and remotely; the upload was refused and the local edit loses",{path:i,memory_store_id:t.memoryStoreId});else if(l&&n!==void 0)t.refusedShas.set(i,n),e(this,p,"f").warn("the server rejected this memory file, so it stays un-synced until its content changes",{path:i,memory_store_id:t.memoryStoreId,rejection:String(c)});else e(this,p,"f").warn("failed to upload memory",{path:i,memory_store_id:t.memoryStoreId,error:String(c)});return}},Je=async function(t,i,n,s,c){if(c.mode==="disabled")return c.suppressed++,s;let l=t.pendingDeletes.get(i);if(l===void 0)l=Date.now(),t.pendingDeletes.set(i,l);if(!c.waiveWindow&&Date.now()-l<qt)return s;let f,h;try{f=await t.files.hashFile(K)===Qe(t.memoryStoreId),h=await t.files.hashFile(i)===null}catch(m){if(!(m instanceof y)&&!H(m))throw m;f=h=!1}if(!f)return s;if(!h)return t.pendingDeletes.delete(i),s;if(!c.takeSlot())return s;if(c.mode==="log_only")return e(this,p,"f").info("log-only: sync would delete this memory on the server",{path:i,memory_store_id:t.memoryStoreId}),s;let d=await e(this,_,"m",Ze).call(this,t,i,n,s);if(d===void 0)t.pendingDeletes.delete(i);return d},Ze=async function(t,i,n,s){try{await e(this,L,"f").beta.memoryStores.memories.delete(n.id,{memory_store_id:t.memoryStoreId,expected_content_sha256:s})}catch(c){if(ue(c,404))return;if(ue(c,409)||ue(c,412))e(this,p,"f").warn("memory deleted locally but changed remotely; keeping the remote version",{path:i,memory_store_id:t.memoryStoreId});else e(this,p,"f").warn("failed to delete memory",{path:i,memory_store_id:t.memoryStoreId,error:String(c)});return s}e(this,p,"f").info("propagated local deletion",{path:i,memory_store_id:t.memoryStoreId});return},a})();function H(a){return typeof a==="object"&&a!==null&&typeof a.code==="string"}async function Zt(a,r){if(!r){await a;return}let t,i=new Promise((n)=>{if(t=n,r.aborted)n()});r.addEventListener("abort",t,{once:!0});try{await Promise.race([a,i])}finally{r.removeEventListener("abort",t)}}var ye,M,I,ee,W,N,Le,we,te,_e,ge,U,j,V,B,re,x,rt,it,nt=102400,ft=120000,Qt=262144,er=65536,ot=Buffer.from(`
|
|
8
|
+
`),ie=102400,tr=2000,rr=200;class dt extends u{constructor(a){super(`bash command timed out after ${a}ms`);this.name="BashTimeoutError",this.timeoutMs=a}}var ir=/\x1b\[[0-9;?]*[ -/]*[@-~]/g,nr=b.glob;function ht(a){return a===void 0?Qt:a}function Y(a){if(a===void 0)return;throw new u("The `unrestrictedPaths` option you passed to the agent toolset (AgentToolContext) is no longer supported. The toolset's file tools (read, write, edit, glob, grep) are now always confined to the working directory plus the directories listed in `allowedRoots`. Remove `unrestrictedPaths` from your context; to let the file tools reach any other directory, add it to `allowedRoots`.")}function Xr(a){return[ar(a),cr(a),dr(a),hr(a),ur(a),pr(a)]}async function oe(a,r){return Y(a.unrestrictedPaths),Ae(a.workdir,r,{allowedRoots:a.allowedRoots??[]})}function mt(a,r){return Ee(a.readOnlyRoots??[],r)}function or(){let a={};for(let[r,t]of Object.entries(process.env)){if(r.startsWith("ANTHROPIC_"))continue;a[r]=t}return a}var sr=(()=>{class a{constructor(r,t=or()){ye.add(this),M.set(this,void 0),I.set(this,""),ee.set(this,!1),W.set(this,!1),N.set(this,null),o(this,M,$e.spawn("/bin/bash",["--noprofile","--norc"],{cwd:r,env:{...t,PS1:"",PS2:"",TERM:"dumb"},stdio:["pipe","pipe","pipe"],detached:!0}),"f"),e(this,M,"f").stdout.setEncoding("utf8"),e(this,M,"f").stderr.setEncoding("utf8"),e(this,M,"f").stdout.on("data",(i)=>e(this,ye,"m",Le).call(this,i)),e(this,M,"f").stderr.on("data",(i)=>e(this,ye,"m",Le).call(this,i)),e(this,M,"f").once("close",()=>{o(this,W,!0,"f");let i=e(this,N,"f");o(this,N,null,"f"),i?.resolve()})}get closed(){return e(this,W,"f")}async exec(r,t={}){if(e(this,W,"f"))throw new u("bash session terminated");let i=t.timeoutMs??ft,n=t.signal;n?.throwIfAborted(),o(this,I,"","f"),o(this,ee,!1,"f");let s=`__ANT_CMD_${ct.randomUUID()}_DONE__`,c=`${s.slice(0,8)}''${s.slice(8)}`,l=`{ ${r}
|
|
9
|
+
} </dev/null 2>&1; printf '\\n${c}%d\\n' $?
|
|
10
|
+
`;if(e(this,M,"f").stdin.write(l),e(this,I,"f").indexOf(s)<0){let{promise:O,resolve:D}=Dt();o(this,N,{sentinel:s,resolve:D},"f");let k,se;try{await Promise.race([O,new Promise((pt,Se)=>{k=setTimeout(()=>Se(new dt(i)),i)}),new Promise((pt,Se)=>{if(!n)return;se=()=>Se(n.reason),n.addEventListener("abort",se,{once:!0})})])}finally{if(k)clearTimeout(k);if(se&&n)n.removeEventListener("abort",se);o(this,N,null,"f")}}let f=e(this,I,"f").indexOf(s);if(f<0)throw new u("bash session terminated");let d=e(this,I,"f").slice(f+s.length).match(/^(-?\d+)/),m=d?parseInt(d[1],10):-1,g=e(this,I,"f").slice(0,f).replace(ir,"").replace(/\n+$/,"");if(e(this,ee,"f"))g=`[output truncated]
|
|
11
|
+
${g}`;return{output:g,exitCode:m}}close(){if(e(this,W,"f"))return;o(this,W,!0,"f");let r=e(this,N,"f");o(this,N,null,"f"),r?.resolve(),e(this,M,"f").stdout.destroy(),e(this,M,"f").stderr.destroy(),e(this,M,"f").stdin.destroy();try{process.kill(-e(this,M,"f").pid,"SIGKILL")}catch{e(this,M,"f").kill("SIGKILL")}e(this,M,"f").unref()}}return M=new WeakMap,I=new WeakMap,ee=new WeakMap,W=new WeakMap,N=new WeakMap,ye=new WeakSet,Le=function(t){if(o(this,I,e(this,I,"f")+t,"f"),e(this,I,"f").length>nt)o(this,I,e(this,I,"f").slice(e(this,I,"f").length-nt),"f"),o(this,ee,!0,"f");if(e(this,N,"f")&&e(this,I,"f").indexOf(e(this,N,"f").sentinel)>=0){let i=e(this,N,"f");o(this,N,null,"f"),i.resolve()}},a})();function ar(a){Y(a.unrestrictedPaths);let r,t=Promise.resolve();return C({name:"bash",description:"Run a bash command in a persistent shell. State (cwd, env vars) persists across calls.",inputSchema:{type:"object",properties:{command:{type:"string",description:"The command to run"},restart:{type:"boolean",description:"Restart the persistent shell before running"},timeout_ms:{type:"integer",description:"Per-call timeout in milliseconds"}}},run:async({command:i,restart:n,timeout_ms:s},c)=>{let l=t,f=Dt();t=f.promise;try{await l}catch{}try{if(n)r?.close(),r=void 0;if(!i){if(n)return"bash session restarted";throw new E("bash: command is required")}r??(r=new sr(a.workdir,a.env));try{let{output:h,exitCode:d}=await r.exec(i,{timeoutMs:s??ft,signal:c?.signal});if(d!==0)throw new E(h||`exit ${d}`);return h}catch(h){if(h instanceof E)throw h;throw r.close(),r=void 0,new E(`bash: ${h instanceof Error?h.message:String(h)}`)}}finally{f.resolve()}},close:()=>{r?.close(),r=void 0}})}function cr(a){return Y(a.unrestrictedPaths),C({name:"read",description:"Read a UTF-8 text file relative to the workdir.",inputSchema:{type:"object",properties:{file_path:{type:"string"},view_range:{type:"array",items:{type:"integer"},description:"[start_line, end_line] 1-indexed inclusive"}},required:["file_path"]},run:async({file_path:r,view_range:t})=>{if(!r)throw new E("read: file_path is required");let i=await oe(a,r);if(t?.length&&t.length!==2)throw new E("read: view_range must be [start_line, end_line]");let n;try{let d=await b.stat(i);if(!d.isFile())throw new E(`read: ${r} is not a regular file`);let m=ht(a.maxFileBytes);if(m!==null&&d.size>m){if(!t?.length)throw new E(`read: ${r} is ${d.size} bytes, exceeds ${m}-byte limit. Use the view_range parameter to read specific line ranges, e.g. view_range: [1, 500].`);let[g,O]=t;return await lr(i,r,g,O,m)}n=await b.readFile(i,"utf8")}catch(d){if(d instanceof E)throw d;throw new E(`read: ${q(d,r)}`)}if(!t?.length)return n;let[s,c]=t,l=n.split(`
|
|
12
|
+
`),f=Math.max(0,s-1),h=c>0?c:l.length;return l.slice(f,h).join(`
|
|
13
|
+
`)}})}async function lr(a,r,t,i,n){let s=new fr(r,t,i,n);if(s.rangeIsEmpty())return"";let c=ne.createReadStream(a,{highWaterMark:er});try{for await(let l of c)if(s.collectFrom(l),s.rangeIsCollected())break}finally{c.destroy()}return s.text()}var fr=(()=>{class a{constructor(r,t,i,n){we.add(this),te.set(this,void 0),_e.set(this,void 0),ge.set(this,void 0),U.set(this,void 0),j.set(this,void 0),V.set(this,void 0),B.set(this,0),re.set(this,[]),x.set(this,0),o(this,te,r,"f"),o(this,_e,t,"f"),o(this,ge,i,"f"),o(this,U,Math.max(0,t-1),"f"),o(this,j,i>0?i:1/0,"f"),o(this,V,n,"f")}rangeIsEmpty(){return e(this,j,"f")<=e(this,U,"f")}rangeIsCollected(){return e(this,B,"f")>=e(this,j,"f")}collectFrom(r){var t;let i=0;while(i<r.length&&!this.rangeIsCollected()){let n=r.indexOf(10,i),s=n<0?r.length:n;if(e(this,B,"f")>=e(this,U,"f"))e(this,we,"m",rt).call(this,r.subarray(i,s),n>=0);if(n<0)break;o(this,B,(t=e(this,B,"f"),t++,t),"f"),i=n+1}}text(){return Buffer.concat(e(this,re,"f"),e(this,x,"f")).toString("utf8")}}return te=new WeakMap,_e=new WeakMap,ge=new WeakMap,U=new WeakMap,j=new WeakMap,V=new WeakMap,B=new WeakMap,re=new WeakMap,x=new WeakMap,we=new WeakSet,rt=function(t,i){if(e(this,re,"f").push(t),o(this,x,e(this,x,"f")+t.length,"f"),i&&e(this,B,"f")+1<e(this,j,"f"))e(this,re,"f").push(ot),o(this,x,e(this,x,"f")+ot.length,"f");if(e(this,x,"f")>e(this,V,"f"))throw e(this,we,"m",it).call(this)},it=function(){if(e(this,j,"f")-e(this,U,"f")===1)return new E(`read: line ${e(this,U,"f")+1} of ${e(this,te,"f")} alone exceeds ${e(this,V,"f")}-byte limit. The read tool cannot return part of a line, so view_range cannot narrow this further.`);return new E(`read: view_range [${e(this,_e,"f")}, ${e(this,ge,"f")}] of ${e(this,te,"f")} exceeds ${e(this,V,"f")}-byte limit. Narrow the view_range to read a smaller portion.`)},a})();function dr(a){return Y(a.unrestrictedPaths),C({name:"write",description:"Write a UTF-8 text file relative to the workdir, creating parent directories as needed.",inputSchema:{type:"object",properties:{file_path:{type:"string"},content:{type:"string"}},required:["file_path","content"]},run:async({file_path:r,content:t})=>{if(!r)throw new E("write: file_path is required");let i=await oe(a,r),n=await mt(a,i);if(n!==void 0)throw new E(`write: ${r} is inside read-only directory ${n}`);try{await b.mkdir(v.dirname(i),{recursive:!0,mode:J}),await be(i,t??"")}catch(s){throw new E(`write: ${q(s,r)}`)}return`wrote ${Buffer.byteLength(t??"")} bytes to ${r}`}})}function hr(a){return Y(a.unrestrictedPaths),C({name:"edit",description:"Replace old_string with new_string in a file. old_string must be unique unless replace_all.",inputSchema:{type:"object",properties:{file_path:{type:"string"},old_string:{type:"string"},new_string:{type:"string"},replace_all:{type:"boolean"}},required:["file_path","old_string","new_string"]},run:async({file_path:r,old_string:t,new_string:i,replace_all:n})=>{if(!r)throw new E("edit: file_path is required");if(!t)throw new E("edit: old_string is required");let s=await oe(a,r),c=await mt(a,s);if(c!==void 0)throw new E(`edit: ${r} is inside read-only directory ${c}`);let l;try{let d=await b.stat(s);if(!d.isFile())throw new E(`edit: ${r} is not a regular file`);let m=ht(a.maxFileBytes);if(m!==null&&d.size>m)throw new E(`edit: ${r} is ${d.size} bytes, exceeds ${m}-byte limit. The edit tool loads the whole file and cannot modify a file this large.`);l=await b.readFile(s,"utf8")}catch(d){if(d instanceof E)throw d;throw new E(`edit: ${q(d,r)}`)}let f=l.split(t).length-1;if(f===0)throw new E(`edit: old_string not found in ${r}`);let h;if(n)h=l.split(t).join(i);else{if(f>1)throw new E(`edit: old_string appears ${f} times in ${r} (must be unique)`);h=l.replace(t,()=>i)}try{await be(s,h)}catch(d){throw new E(`edit: write: ${q(d,r)}`)}return`edited ${r} (${n?f:1} replacement(s))`}})}function mr(a){return a.split(/[\\/{},]/).includes("..")}function ur(a){return Y(a.unrestrictedPaths),C({name:"glob",description:"Match files under the workdir against a glob pattern. Results are mtime-sorted, newest first.",inputSchema:{type:"object",properties:{pattern:{type:"string"},path:{type:"string",description:"Directory to search in. Defaults to the workdir."}},required:["pattern"]},run:async({pattern:r,path:t})=>{if(!r)throw new E("glob: pattern is required");if(v.isAbsolute(r))throw new E("glob: absolute pattern not permitted; pass a relative pattern (and optionally path)");if(mr(r))throw new E('glob: ".." is not permitted in the pattern');let i=t?await oe(a,t):v.resolve(a.workdir),n=t?i:await X(i),s=[],c=ut;try{for await(let l of nr(r,{cwd:i,withFileTypes:!0,exclude:(f)=>f.name===".git"||f.name==="node_modules"})){if(c--<=0)break;if(!l.isFile())continue;let f=v.join(l.parentPath,l.name),h;try{h=await b.realpath(f)}catch{continue}if(!ae(n,h))continue;let d=0;try{d=(await b.stat(f)).mtimeMs}catch{}s.push({path:f,mtime:d})}}catch(l){throw new E(`glob: ${l instanceof Error?l.message:String(l)}`)}if(s.length===0)return"no matches";return s.sort((l,f)=>f.mtime-l.mtime),s.slice(0,rr).map((l)=>l.path).join(`
|
|
14
|
+
`)}})}function pr(a){return Y(a.unrestrictedPaths),C({name:"grep",description:"Search file contents for a regex. Uses ripgrep if available, otherwise a built-in walker.",inputSchema:{type:"object",properties:{pattern:{type:"string"},path:{type:"string"}},required:["pattern"]},run:async({pattern:r,path:t},i)=>{if(!r)throw new E("grep: pattern is required");let n=v.resolve(a.workdir);if(t)n=await oe(a,t);let s=await Sr();return s?yr(s,r,n,i?.signal):wr(r,n,i?.signal)}})}function yr(a,r,t,i){return new Promise((n,s)=>{let c=$e.spawn(a,["-n","--no-heading","-e",r,"--",t],{...i?{signal:i}:{}}),l="",f="",h=!1;c.stdout.on("data",(d)=>{if(h)return;if(l+=d,l.length>ie)h=!0,l=l.slice(0,ie),c.kill("SIGKILL")}),c.stderr.on("data",(d)=>f+=d),c.on("close",(d)=>{if(i?.aborted)return s(new E("grep: aborted"));if(h)return n(l+`
|
|
15
|
+
[output truncated at ${ie} bytes]`);if(d===0)return n(l);if(d===1)return n("no matches");s(new E(`grep: rg failed: ${f||`exit ${d}`}`))}),c.on("error",(d)=>{if(i?.aborted)return s(new E("grep: aborted"));s(new E(`grep: rg failed: ${d.message}`))})})}async function wr(a,r,t){let i;try{i=new RegExp(a)}catch(f){throw new E(`grep: invalid regex: ${f instanceof Error?f.message:String(f)}`)}let n=[],s=ie,c=(f)=>{if(s-=f.length+1,s<0)return n.push(`[output truncated at ${ie} bytes]`),!1;return n.push(f),!0};if((await b.stat(r).catch(()=>null))?.isFile())await at(r,i,c);else await gr(r,"",(f)=>at(v.join(r,f),i,c),t);if(t?.aborted)throw new E("grep: aborted");if(n.length===0)return"no matches";return n.join(`
|
|
16
|
+
`)}async function at(a,r,t){let i=ne.createReadStream(a,{encoding:"utf8"}),n=lt.createInterface({input:i,crlfDelay:1/0}),s=0;try{for await(let c of n){if(s++,c.length>tr)continue;if(r.test(c)&&!t(`${a}:${s}:${c}`))return!1}}catch{}finally{i.destroy()}return!0}var _r=40,ut=50000;async function gr(a,r,t,i){let n=ut;async function s(c,l){if(l>_r)return!0;if(i?.aborted)return!1;let f;try{f=await b.readdir(v.join(a,c),{withFileTypes:!0})}catch{return!0}for(let h of f){if(h.name===".git"||h.name==="node_modules")continue;if(n--<=0)return!1;if(i?.aborted)return!1;let d=c?v.join(c,h.name):h.name;if(h.isDirectory()){if(!await s(d,l+1))return!1}else if(h.isFile()){if(await t(d)===!1)return!1}}return!0}await s(r,0)}async function Sr(){let a=(process.env.PATH??"").split(v.delimiter);for(let r of a){let t=v.join(r,"rg");try{return await b.access(t,ne.constants.X_OK),t}catch{}}return null}export{Yt as MEMORY_FLUSH_TIMEOUT_MS,P as SessionMemoryError,Jt as SessionMemoryStores,Xr as betaAgentToolset20260401,gt as setupSkills};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{L}from"./chunk-
|
|
2
|
+
import{L}from"./chunk-tevejprz.js";import{b,H}from"./chunk-cmwdjes8.js";import{i}from"./chunk-bwawt15q.js";var N=i(L()),p=i(b());var f=i(b()),A=i(H());import{createHash as K,createPrivateKey as _,createPublicKey as v,sign as B}from"crypto";import{promises as E}from"fs";import{homedir as q}from"os";import{dirname as U,join as P}from"path";class d{profileData;init;callerClientConfig;static REFRESH_THRESHOLD=300000;constructor(e,t,s){this.profileData=e,this.init=t,this.callerClientConfig=s}async loadCredentials(){let e=await this.loadToken();if(!e)throw new f.CredentialsProviderError(`Failed to load a token for session ${this.loginSession}, please re-authenticate using aws login`,{tryNextLink:!1,logger:this.logger});let t=e.accessToken,s=Date.now();if(new Date(t.expiresAt).getTime()-s<=d.REFRESH_THRESHOLD)return this.refresh(e);return this.toCredentials(e.accessToken)}get logger(){return this.init?.logger}get loginSession(){return this.profileData.login_session}toCredentials(e){return{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey,sessionToken:e.sessionToken,accountId:e.accountId,expiration:new Date(e.expiresAt)}}async refresh(e){let t=await this.loadToken().catch(()=>e),s=Date.now(),r=new Date(t.accessToken.expiresAt).getTime(),n=new Date(e.accessToken.expiresAt).getTime(),o=r<=s&&n>s?e:t;if(new Date(o.accessToken.expiresAt).getTime()-Date.now()>d.REFRESH_THRESHOLD)return this.toCredentials(o.accessToken);let{SigninClient:h,CreateOAuth2TokenCommand:y}=await import("./chunk-mbpb5c7w.js"),{logger:m,userAgentAppId:T}=this.callerClientConfig??{},x=((a)=>a?.metadata?.handlerProtocol==="h2")(this.callerClientConfig?.requestHandler)?void 0:this.callerClientConfig?.requestHandler,u=this.profileData.region??await this.callerClientConfig?.region?.()??process.env.AWS_REGION,k=new h({credentials:{accessKeyId:"",secretAccessKey:""},region:u,requestHandler:x,logger:m,userAgentAppId:T,...this.init?.clientConfig});this.createDPoPInterceptor(k.middlewareStack);let D={tokenInput:{clientId:o.clientId,refreshToken:o.refreshToken,grantType:"refresh_token"}};try{let a=await k.send(new y(D)),{accessKeyId:l,secretAccessKey:w,sessionToken:g}=a.tokenOutput?.accessToken??{},{refreshToken:C,expiresIn:R}=a.tokenOutput??{};if(!l||!w||!g||!C)throw new f.CredentialsProviderError("Token refresh response missing required fields",{logger:this.logger,tryNextLink:!1});let F=(R??900)*1000,O=new Date(Date.now()+F),I={...o,accessToken:{...o.accessToken,accessKeyId:l,secretAccessKey:w,sessionToken:g,expiresAt:O.toISOString()},refreshToken:C};return await this.saveToken(I),this.toCredentials(I.accessToken)}catch(a){if(a.name==="AccessDeniedException"){let w=a.error,g;switch(w){case"TOKEN_EXPIRED":g="Your session has expired. Please reauthenticate.";break;case"USER_CREDENTIALS_CHANGED":g="Unable to refresh credentials because of a change in your password. Please reauthenticate with your new password.";break;case"INSUFFICIENT_PERMISSIONS":g="Unable to refresh credentials due to insufficient permissions. You may be missing permission for the 'CreateOAuth2Token' action.";break;default:g=`Failed to refresh token: ${String(a)}. Please re-authenticate using \`aws login\``}throw new f.CredentialsProviderError(g,{logger:this.logger,tryNextLink:!1})}if(new Date(o.accessToken.expiresAt).getTime()>Date.now())return this.logger?.warn?.(`Failed to refresh token: ${String(a)}. Using existing token until expiry.`),this.toCredentials(o.accessToken);throw new f.CredentialsProviderError(`Failed to refresh token: ${String(a)}. Please re-authenticate using aws login`,{logger:this.logger})}}async loadToken(){let e=this.getTokenFilePath();try{let t=await E.readFile(e,"utf8"),s=JSON.parse(t),r=["accessToken","clientId","refreshToken","dpopKey"].filter((n)=>!s[n]);if(!s.accessToken?.accountId)r.push("accountId");if(r.length>0)throw new f.CredentialsProviderError(`Token validation failed, missing fields: ${r.join(", ")}`,{logger:this.logger,tryNextLink:!1});return s}catch(t){throw new f.CredentialsProviderError(`Failed to load token from ${e}: ${String(t)}`,{logger:this.logger,tryNextLink:!1})}}async saveToken(e){let t=this.getTokenFilePath(),s=U(t);try{await E.mkdir(s,{recursive:!0})}catch(r){}await E.writeFile(t,JSON.stringify(e,null,2),"utf8")}getTokenFilePath(){let e=process.env.AWS_LOGIN_CACHE_DIRECTORY??P(q(),".aws","login","cache"),t=Buffer.from(this.loginSession,"utf8"),s=K("sha256").update(t).digest("hex");return P(e,`${s}.json`)}derToRawSignature(e){let t=2;if(e[t]!==2)throw Error("Invalid DER signature");t++;let s=e[t++],r=e.subarray(t,t+s);if(t+=s,e[t]!==2)throw Error("Invalid DER signature");t++;let n=e[t++],o=e.subarray(t,t+n);r=r[0]===0?r.subarray(1):r,o=o[0]===0?o.subarray(1):o;let c=Buffer.concat([Buffer.alloc(32-r.length),r]),h=Buffer.concat([Buffer.alloc(32-o.length),o]);return Buffer.concat([c,h])}createDPoPInterceptor(e){e.add((t)=>async(s)=>{if(A.HttpRequest.isInstance(s.request)){let r=s.request,n=`${r.protocol}//${r.hostname}${r.port?`:${r.port}`:""}${r.path}`,o=await this.generateDpop(r.method,n);r.headers={...r.headers,DPoP:o}}return t(s)},{step:"finalizeRequest",name:"dpopInterceptor",override:!0})}async generateDpop(e="POST",t){let s=await this.loadToken();try{let r=_({key:s.dpopKey,format:"pem",type:"sec1"}),o=v(r).export({format:"der",type:"spki"}),c=-1;for(let l=0;l<o.length;l++)if(o[l]===4){c=l;break}let h=o.slice(c+1,c+33),y=o.slice(c+33,c+65),m={alg:"ES256",typ:"dpop+jwt",jwk:{kty:"EC",crv:"P-256",x:h.toString("base64url"),y:y.toString("base64url")}},T={jti:crypto.randomUUID(),htm:e,htu:t,iat:Math.floor(Date.now()/1000)},S=Buffer.from(JSON.stringify(m)).toString("base64url"),x=Buffer.from(JSON.stringify(T)).toString("base64url"),u=`${S}.${x}`,k=B("sha256",Buffer.from(u),r),a=this.derToRawSignature(k).toString("base64url");return`${u}.${a}`}catch(r){throw new f.CredentialsProviderError(`Failed to generate Dpop proof: ${r instanceof Error?r.message:String(r)}`,{logger:this.logger,tryNextLink:!1})}}}var j=(e)=>async({callerClientConfig:t}={})=>{e?.logger?.debug?.("@aws-sdk/credential-providers - fromLoginCredentials");let s=await p.parseKnownFiles(e||{}),r=p.getProfileName({profile:e?.profile??t?.profile}),n=s[r];if(!n?.login_session)throw new p.CredentialsProviderError(`Profile ${r} does not contain login_session.`,{tryNextLink:!0,logger:e?.logger});let c=await new d(n,e,t).loadCredentials();return N.setCredentialFeature(c,"CREDENTIALS_LOGIN","AD")};export{j as fromLoginCredentials};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{fr,
|
|
2
|
+
import{fr,Tt,zt,jt,Vt,Kt,gr,yr,kt,br,Sr,wr,xr,vr,_r}from"./chunk-jtsve11b.js";import{P}from"./chunk-c4qr1f41.js";import{ee}from"./chunk-tvm4zmgj.js";import{q,V}from"./chunk-ypqjfv3a.js";import{K}from"./chunk-r4ttdkrz.js";import{y}from"./chunk-3k627vf2.js";import{ye}from"./chunk-nrsd810j.js";import{U,me,oe,Oe,Q,G}from"./chunk-1n7dat03.js";import{M}from"./chunk-n2jcx65v.js";var b="v1",O="gcp-vertex-credentials",R=0,C=(e,o,t)=>{let i=new M,u=Oe(o);return(async()=>{let n={role:"assistant",content:[],api:"google-vertex",provider:e.provider,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"pending",timestamp:Date.now()};try{if(t?.fetch&&t.fetch!==globalThis.fetch)throw Error("Custom fetch is not supported by the Google Vertex adapter");let c=L(t),g=c?S(e,c,t?.headers):I(e,D(t),N(t),t?.headers,t?.env),h=j(e,u,t),m=await t?.onPayload?.(h,e);if(m!==void 0)h=m;let p=await _r(()=>g.models.generateContentStream(h),t);i.push({type:"start",partial:n});let r=null,f=n.content,l=()=>f.length-1;for await(let s of p){await t?.onProviderStreamEvent?.(s,e),n.responseId||=s.responseId;let k=s.candidates?.[0];if(k?.content?.parts)for(let a of k.content.parts){if(a.text!==void 0){let d=yr(a);if(!r||d&&r.type!=="thinking"||!d&&r.type!=="text"){if(r)if(r.type==="text")i.push({type:"text_end",contentIndex:f.length-1,content:r.text,partial:n});else i.push({type:"thinking_end",contentIndex:l(),content:r.thinking,partial:n});if(d)r={type:"thinking",thinking:"",thinkingSignature:void 0},n.content.push(r),i.push({type:"thinking_start",contentIndex:l(),partial:n});else r={type:"text",text:""},n.content.push(r),i.push({type:"text_start",contentIndex:l(),partial:n})}if(r.type==="thinking")r.thinking+=a.text,r.thinkingSignature=kt(r.thinkingSignature,a.thoughtSignature),i.push({type:"thinking_delta",contentIndex:l(),delta:a.text,partial:n});else r.text+=a.text,r.textSignature=kt(r.textSignature,a.thoughtSignature),i.push({type:"text_delta",contentIndex:l(),delta:a.text,partial:n})}if(a.functionCall){if(r){if(r.type==="text")i.push({type:"text_end",contentIndex:l(),content:r.text,partial:n});else i.push({type:"thinking_end",contentIndex:l(),content:r.thinking,partial:n});r=null}let d=a.functionCall.id,x={type:"toolCall",id:!d||n.content.some((T)=>T.type==="toolCall"&&T.id===d)?`${a.functionCall.name}_${Date.now()}_${++R}`:d,name:a.functionCall.name||"",arguments:a.functionCall.args??{},...a.thoughtSignature&&{thoughtSignature:a.thoughtSignature}};n.content.push(x),i.push({type:"toolcall_start",contentIndex:l(),partial:n}),i.push({type:"toolcall_delta",contentIndex:l(),delta:JSON.stringify(x.arguments),partial:n}),i.push({type:"toolcall_end",contentIndex:l(),toolCall:x,partial:n})}}if(k?.finishReason){if(n.rawStopReason=k.finishReason,n.stopReason=vr(k.finishReason),n.content.some((a)=>a.type==="toolCall")&&n.stopReason==="stop")n.stopReason="toolUse"}if(s.usageMetadata)n.usage={input:(s.usageMetadata.promptTokenCount||0)-(s.usageMetadata.cachedContentTokenCount||0),output:(s.usageMetadata.candidatesTokenCount||0)+(s.usageMetadata.thoughtsTokenCount||0),cacheRead:s.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,reasoning:s.usageMetadata.thoughtsTokenCount||0,totalTokens:s.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},Q(e,n.usage)}if(r)if(r.type==="text")i.push({type:"text_end",contentIndex:l(),content:r.text,partial:n});else i.push({type:"thinking_end",contentIndex:l(),content:r.thinking,partial:n});if(t?.signal?.aborted)throw Error("Request was aborted");if(n.stopReason==="pending")throw Error("Google Vertex stream ended without a finish reason");if(n.stopReason==="aborted"||n.stopReason==="error"){let s=n.rawStopReason?`Provider stopped with: ${n.rawStopReason}`:"An unknown error occurred";throw Error(s)}i.push({type:"done",reason:n.stopReason,message:n}),i.end()}catch(c){for(let g of n.content)if("index"in g)delete g.index;n.stopReason=t?.signal?.aborted?"aborted":"error",n.errorMessage=V(q(c)),i.push({type:"error",reason:n.stopReason,error:n}),i.end()}})(),i},ue=(e,o,t)=>{let i={...K(e,o,t,void 0),toolChoice:t?.toolChoice};if(!t?.reasoning)return C(e,o,{...i,thinking:{enabled:!1}});let u=G(e,t.reasoning);if(u==="off")return C(e,o,{...i,thinking:{enabled:!1}});let n=zt(e,u);if(jt(e))return C(e,o,{...i,thinking:{enabled:!0,level:Vt(n)}});return C(e,o,{...i,thinking:{enabled:!0,budgetTokens:B(e,n,t.thinkingBudgets)}})};function I(e,o,t,i,u){let n=E(u);return new Tt({vertexai:!0,project:o,location:t,apiVersion:b,...n?{googleAuthOptions:n}:{},httpOptions:v(e,i)})}function S(e,o,t){return new Tt({vertexai:!0,apiKey:o,apiVersion:b,httpOptions:v(e,t)})}function v(e,o){let t={},i=w(e.baseUrl);if(i){if(t.baseUrl=i,t.baseUrlResourceScope=fr.COLLECTION,_(i))t.apiVersion=""}let u=ye({"User-Agent":ee(),...e.headers,...o});if(u)t.headers=u;return Object.keys(t).length>0?t:void 0}function w(e){let o=e.trim();if(!o||o.includes("{location}"))return;return o}function _(e){try{return new URL(e).pathname.split("/").some((t)=>/^v\d+(?:beta\d*)?$/.test(t))}catch{return/(?:^|\/)v\d+(?:beta\d*)?(?:\/|$)/.test(e)}}function E(e){let o=P("GOOGLE_APPLICATION_CREDENTIALS",e);return o?{keyFilename:o}:void 0}function L(e){let o=e?.apiKey?.trim();if(!o||o===O||A(o))return;return o}function A(e){return/^<[^>]+>$/.test(e)}function D(e){let o=e?.project||P("GOOGLE_CLOUD_PROJECT",e?.env)||P("GCLOUD_PROJECT",e?.env);if(!o)throw Error("Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.");return o}function N(e){let o=e?.location||P("GOOGLE_CLOUD_LOCATION",e?.env);if(!o)throw Error("Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.");return o}function j(e,o,t={}){let i=br(e,o),u=me(o.messages),n=oe(o.messages),c={};if(t.temperature!==void 0)c.temperature=t.temperature;if(t.maxTokens!==void 0)c.maxOutputTokens=t.maxTokens;let g=wr(e.id),h=n.length>0?xr(n,t.toolChoice,g):void 0,m=u?U(u):"",p={...Object.keys(c).length>0&&c,...m&&{systemInstruction:y(m)},...n.length>0&&{tools:Sr(n,!1,g)},...h!==void 0&&{toolConfig:{functionCallingConfig:{mode:h}}}};if(t.thinking?.enabled&&e.reasoning){let f={includeThoughts:!0};if(t.thinking.level!==void 0)f.thinkingLevel=Kt(t.thinking.level);else if(t.thinking.budgetTokens!==void 0)f.thinkingBudget=t.thinking.budgetTokens;p.thinkingConfig=f}else if(e.reasoning&&t.thinking&&!t.thinking.enabled)p.thinkingConfig=gr(e);if(t.signal){if(t.signal.aborted)throw Error("Request aborted");p.abortSignal=t.signal}return{model:e.id,contents:i,config:p}}function B(e,o,t){if(t?.[o]!==void 0)return t[o];if(e.id.includes("2.5-pro"))return{minimal:128,low:2048,medium:8192,high:32768}[o];if(e.id.includes("2.5-flash"))return{minimal:128,low:2048,medium:8192,high:24576}[o];return-1}export{C as stream,ue as streamSimple};
|