mailcycle-mcp 0.2.1 → 0.2.2
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/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Copyright (c) 2026 Northlab Studios Ltd. All rights reserved. See LICENSE.
|
|
3
|
-
var Ke=Object.defineProperty;var Oe=(e,r)=>{for(var t in r)Ke(e,t,{get:r[t],enumerable:!0})};var S=class extends Error{constructor(t,o,n){super(n);this.status=t;this.code=o;this.name="MailcycleError"}};function _(e){return e instanceof S&&e.status===401}var w=class{constructor(r,t){this.baseUrl=r;this.token=t}async request(r,t,o,n){let a=await this.fetch(r,t,o,n),i=await a.text(),s=i?JSON.parse(i):{};if(!a.ok)throw new S(a.status,String(s.code??"error"),String(s.message??`Mailcycle answered ${a.status}.`));return s}async fetch(r,t,o,n){try{return await this.rawFetch(r,t,o,n)}catch(a){throw a.name==="AbortError"?a:new S(0,"unreachable",`Could not reach Mailcycle at ${this.baseUrl}. Check the connection.`)}}rawFetch(r,t,o,n){return fetch(`${this.baseUrl}${t}`,{method:r,headers:{...this.token?{Authorization:`Bearer ${this.token}`}:{},...o===void 0?{}:{"Content-Type":"application/json"},"User-Agent":"mailcycle-mcp/0.2"},...o===void 0?{}:{body:JSON.stringify(o)},...n?{signal:n}:{}})}createPairingSession(r){return this.request("POST","/workers/pairing-session",{platform:"agent",deviceName:r})}pollPairing(r){return this.request("GET",`/workers/pairing-session/${encodeURIComponent(r)}`)}self(){return this.request("GET","/workers/self")}heartbeat(r){return this.request("POST","/workers/heartbeat",{lastActiveAt:r})}messages(r,t){let o=new URLSearchParams;for(let[n,a]of Object.entries(r))a!==void 0&&o.set(n,String(a));return this.request("GET",`/workers/messages?${o}`,void 0,t)}send(r){return this.request("POST","/messages/send",r)}};var ie={};Oe(ie,{getRandomValues:()=>ae});var ae=void 0;var j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";function v(e){let r=[];for(let t=0;t<e.length;t+=1){let o=e.charCodeAt(t);if(o>=55296&&o<=56319&&t+1<e.length){let n=e.charCodeAt(t+1);n>=56320&&n<=57343&&(o=65536+(o-55296<<10)+(n-56320),t+=1)}o<128?r.push(o):o<2048?r.push(192|o>>6,128|o&63):o<65536?r.push(224|o>>12,128|o>>6&63,128|o&63):r.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|o&63)}return new Uint8Array(r)}function I(e){let r="";for(let t=0;t<e.length;){let o=e[t],n;o<128?(n=o,t+=1):o<224?(n=(o&31)<<6|e[t+1]&63,t+=2):o<240?(n=(o&15)<<12|(e[t+1]&63)<<6|e[t+2]&63,t+=3):(n=(o&7)<<18|(e[t+1]&63)<<12|(e[t+2]&63)<<6|e[t+3]&63,t+=4),n>65535?(n-=65536,r+=String.fromCharCode(55296+(n>>10),56320+(n&1023))):r+=String.fromCharCode(n)}return r}function N(e){let r="";for(let t=0;t<e.length;t+=3){let o=e[t],n=t+1<e.length?e[t+1]:-1,a=t+2<e.length?e[t+2]:-1;if(r+=j[o>>2],r+=j[(o&3)<<4|(n>=0?n>>4:0)],n<0||(r+=j[(n&15)<<2|(a>=0?a>>6:0)],a<0))break;r+=j[a&63]}return r}var P=class extends Error{constructor(r="Not canonical base64url."){super(r),this.name="Base64UrlError"}};function h(e){if(e.length%4===1)throw new P("Truncated base64url.");let t=new Uint8Array(Math.floor(e.length*6/8)),o=0,n=0,a=0;for(let i=0;i<e.length;i+=1){let s=j.indexOf(e[i]);if(s<0)throw new P(`Unexpected character at ${i}.`);o=o<<6|s,n+=6,n>=8&&(n-=8,t[a]=o>>n&255,a+=1)}if(n>0&&(o&(1<<n)-1)!==0)throw new P("Non-canonical trailing bits.");return t}function V(...e){let r=e.reduce((n,a)=>n+a.length,0),t=new Uint8Array(r),o=0;for(let n of e)t.set(n,o),o+=n.length;return t}function ye(){let e=[],r=globalThis.crypto;return typeof r?.getRandomValues=="function"&&e.push({name:"webcrypto",fill:t=>void r.getRandomValues(t)}),typeof ie?.getRandomValues=="function"&&e.push({name:"expo-crypto",fill:t=>void(void 0)(t)}),e}var J=class extends Error{constructor(){super("No cryptographically secure random source available. Mailcycle will not generate key material without one."),this.name="NoRandomSourceError"}};function K(e){let r=ye()[0];if(!r)throw new J;let t=new Uint8Array(e);return r.fill(t),t}function G(e,r){return(e<<r|e>>>32-r)>>>0}function k(e,r,t,o,n){e[r]=e[r]+e[t]>>>0,e[n]=G(e[n]^e[r],16),e[o]=e[o]+e[n]>>>0,e[t]=G(e[t]^e[o],12),e[r]=e[r]+e[t]>>>0,e[n]=G(e[n]^e[r],8),e[o]=e[o]+e[n]>>>0,e[t]=G(e[t]^e[o],7)}function O(e,r,t){if(e.length!==32)throw new Error("ChaCha20 key must be 32 bytes.");if(r.length!==12)throw new Error("ChaCha20 nonce must be 12 bytes.");let o=new DataView(e.buffer,e.byteOffset,e.byteLength),n=new DataView(r.buffer,r.byteOffset,r.byteLength),a=new Uint32Array(16);a[0]=1634760805,a[1]=857760878,a[2]=2036477234,a[3]=1797285236;for(let l=0;l<8;l+=1)a[4+l]=o.getUint32(l*4,!0);a[13]=n.getUint32(0,!0),a[14]=n.getUint32(4,!0),a[15]=n.getUint32(8,!0);let i=new Uint8Array(t.length),s=new Uint32Array(16),c=new Uint8Array(64),m=new DataView(c.buffer);for(let l=0;l*64<t.length;l+=1){s.set(a),s[12]=l;for(let f=0;f<10;f+=1)k(s,0,4,8,12),k(s,1,5,9,13),k(s,2,6,10,14),k(s,3,7,11,15),k(s,0,5,10,15),k(s,1,6,11,12),k(s,2,7,8,13),k(s,3,4,9,14);for(let f=0;f<16;f+=1){let oe=f===12?s[f]+l>>>0:s[f]+a[f]>>>0;m.setUint32(f*4,oe,!0)}let u=l*64,g=Math.min(64,t.length-u);for(let f=0;f<g;f+=1)i[u+f]=t[u+f]^c[f]}return i}var ze=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),se=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),E=64,we=32,X=8,d=new Uint32Array(64),T=new Uint32Array(X),ce=new Uint32Array(X);function Fe(){d.fill(0),T.fill(0),ce.fill(0)}function z(e){for(let m=16;m<64;m+=1){let l=d[m-15],u=d[m-2],g=(l>>>7|l<<25)^(l>>>18|l<<14)^l>>>3,f=(u>>>17|u<<15)^(u>>>19|u<<13)^u>>>10;d[m]=d[m-16]+g+d[m-7]+f>>>0}let r=e[0],t=e[1],o=e[2],n=e[3],a=e[4],i=e[5],s=e[6],c=e[7];for(let m=0;m<64;m+=1){let l=(a>>>6|a<<26)^(a>>>11|a<<21)^(a>>>25|a<<7),u=a&i^~a&s,g=c+l+u+ze[m]+d[m]>>>0,f=(r>>>2|r<<30)^(r>>>13|r<<19)^(r>>>22|r<<10),oe=r&t^r&o^t&o,Ne=f+oe>>>0;c=s,s=i,i=a,a=n+g>>>0,n=o,o=t,t=r,r=g+Ne>>>0}e[0]=e[0]+r>>>0,e[1]=e[1]+t>>>0,e[2]=e[2]+o>>>0,e[3]=e[3]+n>>>0,e[4]=e[4]+a>>>0,e[5]=e[5]+i>>>0,e[6]=e[6]+s>>>0,e[7]=e[7]+c>>>0}function be(e,r){for(let t=0;t<16;t+=1){let o=r+t*4;d[t]=(e[o]<<24|e[o+1]<<16|e[o+2]<<8|e[o+3])>>>0}}function xe(e,r,t){let o=r.length,n=o-o%E;for(let u=0;u<n;u+=E)be(r,u),z(e);let a=o-n,i=new Uint8Array(a+9+63>=128?128:64);i.set(r.subarray(n)),i[a]=128;let s=(t+o)*8,c=i.length,m=Math.floor(s/4294967296),l=s>>>0;i[c-8]=m>>>24&255,i[c-7]=m>>>16&255,i[c-6]=m>>>8&255,i[c-5]=m&255,i[c-4]=l>>>24&255,i[c-3]=l>>>16&255,i[c-2]=l>>>8&255,i[c-1]=l&255;for(let u=0;u<c;u+=E)be(i,u),z(e)}function Ae(e){let r=new Uint8Array(we);for(let t=0;t<X;t+=1){let o=e[t],n=t*4;r[n]=o>>>24&255,r[n+1]=o>>>16&255,r[n+2]=o>>>8&255,r[n+3]=o&255}return r}function F(e){let r=new Uint32Array(se);return xe(r,e,0),Ae(r)}function We(e){let r=new Uint8Array(E);r.set(e.length>E?F(e):e);let t=new Uint32Array(se);for(let n=0;n<16;n+=1){let a=n*4;d[n]=((r[a]^54)<<24|(r[a+1]^54)<<16|(r[a+2]^54)<<8|r[a+3]^54)>>>0}z(t);let o=new Uint32Array(se);for(let n=0;n<16;n+=1){let a=n*4;d[n]=((r[a]^92)<<24|(r[a+1]^92)<<16|(r[a+2]^92)<<8|r[a+3]^92)>>>0}return z(o),{inner:t,outer:o}}function De(e,r,t){T.set(e.inner),xe(T,r,E),ce.set(T),T.set(e.outer),Le(ce),z(T),t.set(T)}function Le(e){d[0]=e[0],d[1]=e[1],d[2]=e[2],d[3]=e[3],d[4]=e[4],d[5]=e[5],d[6]=e[6],d[7]=e[7],d[8]=2147483648,d[9]=0,d[10]=0,d[11]=0,d[12]=0,d[13]=0,d[14]=0,d[15]=(E+we)*8}function U(e,r){let t=new Uint32Array(X);return De(We(e),r,t),Fe(),Ae(t)}function Z(e,r){if(e.length!==r.length)return!1;let t=0;for(let o=0;o<e.length;o+=1)t|=e[o]^r[o];return t===0}function qe(e){if(e.length!==64)throw new Error("Expected a 64-byte secret.");return{encryption:e.slice(0,32),mac:e.slice(32,64)}}var R=class extends Error{constructor(r="This data could not be decrypted with the key provided."){super(r),this.name="DecryptionError"}};function He(e,r,t=""){let{encryption:o,mac:n}=qe(e),a=h(r.n),i=h(r.c),s=U(n,V(a,i,v(t)));if(a.length!==12)throw new R;if(!Z(s,h(r.t)))throw new R;return O(o,a,i)}function ue(e,r,t=""){return JSON.parse(I(He(e,r,t)))}function b(e){let r=new Float64Array(16);if(e)for(let t=0;t<e.length;t+=1)r[t]=e[t];return r}var Ye=b([56129,1]);function L(e){let r=1;for(let t=0;t<16;t+=1){let o=e[t]+r+65535;r=Math.floor(o/65536),e[t]=o-r*65536}e[0]=e[0]+(r-1)+37*(r-1)}function W(e,r,t){let o=~(t-1);for(let n=0;n<16;n+=1){let a=o&(e[n]^r[n]);e[n]=e[n]^a,r[n]=r[n]^a}}function Je(e,r){let t=b(),o=b();for(let n=0;n<16;n+=1)o[n]=r[n];L(o),L(o),L(o);for(let n=0;n<2;n+=1){t[0]=o[0]-65517;for(let i=1;i<15;i+=1)t[i]=o[i]-65535-(t[i-1]>>16&1),t[i-1]=t[i-1]&65535;t[15]=o[15]-32767-(t[14]>>16&1);let a=t[15]>>16&1;t[14]=t[14]&65535,W(o,t,1-a)}for(let n=0;n<16;n+=1)e[2*n]=o[n]&255,e[2*n+1]=o[n]>>8}function Ve(e,r){for(let t=0;t<16;t+=1)e[t]=r[2*t]+(r[2*t+1]<<8);e[15]=e[15]&32767}function Q(e,r,t){for(let o=0;o<16;o+=1)e[o]=r[o]+t[o]}function ee(e,r,t){for(let o=0;o<16;o+=1)e[o]=r[o]-t[o]}var Ge=new Float64Array(31);function x(e,r,t){let o=Ge;for(let n=0;n<31;n+=1)o[n]=0;for(let n=0;n<16;n+=1){let a=r[n];for(let i=0;i<16;i+=1)o[n+i]=o[n+i]+a*t[i]}for(let n=0;n<15;n+=1)o[n]=o[n]+38*o[n+16];for(let n=0;n<16;n+=1)e[n]=o[n];L(e),L(e),o.fill(0)}function D(e,r){x(e,r,r)}function Xe(e,r){let t=b();for(let o=0;o<16;o+=1)t[o]=r[o];for(let o=253;o>=0;o-=1)D(t,t),o!==2&&o!==4&&x(t,t,r);for(let o=0;o<16;o+=1)e[o]=t[o]}function ve(e,r){if(e.length!==32)throw new Error("x25519: scalar must be 32 bytes");if(r.length!==32)throw new Error("x25519: point must be 32 bytes");let t=new Uint8Array(32);for(let u=0;u<31;u+=1)t[u]=e[u];t[31]=e[31]&127|64,t[0]=t[0]&248;let o=b();Ve(o,r);let n=b(),a=b(),i=b(),s=b(),c=b(),m=b();for(let u=0;u<16;u+=1)a[u]=o[u];n[0]=1,s[0]=1;for(let u=254;u>=0;u-=1){let g=t[u>>>3]>>>(u&7)&1;W(n,a,g),W(i,s,g),Q(c,n,i),ee(n,n,i),Q(i,a,s),ee(a,a,s),D(s,c),D(m,n),x(n,i,n),x(i,a,c),Q(c,n,i),ee(n,n,i),D(a,n),ee(i,s,m),x(n,i,Ye),Q(n,n,s),x(i,i,n),x(n,s,m),x(s,a,o),D(a,c),W(n,a,g),W(i,s,g)}Xe(i,i),x(n,n,i);let l=new Uint8Array(32);return Je(l,n),l}var ke=new Uint8Array(32);ke[0]=9;function Ze(e){return ve(e,ke)}function q(e){return Ze(e)}function Ue(e,r){return ve(e,r)}function Se(e){let r=0;for(let t=0;t<e.length;t+=1)r|=e[t];return r===0}var me=["able","about","above","absent","absorb","abstract","accent","accident","account","accuse","ache","achieve","acid","acorn","acquire","across","action","actor","actual","adapt","addict","address","adjust","admit","adopt","adult","advance","advice","affair","afford","afraid","after","again","agent","agree","ahead","aim","air","alarm","album","alert","alien","align","alike","alive","allow","almost","alone","alpha","already","also","alter","always","amateur","amazing","amber","ambush","among","amount","ample","amused","anchor","ancient","anger","angle","angry","animal","ankle","announce","annual","another","answer","antenna","antique","anxiety","any","apart","apology","appear","apple","april","arch","arctic","area","arena","argue","arise","armed","armor","army","around","arrange","arrest","arrive","arrow","art","artist","artwork","ashamed","aside","ask","aspect","asphalt","assault","asset","assist","assume","asthma","athlete","atlas","atom","attack","attend","attitude","attract","auction","audit","august","aunt","author","auto","autumn","average","avocado","avoid","awake","aware","away","awesome","awful","awkward","axis","baby","bachelor","bacon","badge","bag","balance","balcony","ball","bamboo","banana","banner","bar","barely","bargain","barrel","base","basic","basket","battle","beach","bean","beauty","because","become","beef","before","begin","behave","behind","believe","below","belt","bench","benefit","berry","best","betray","better","between","beyond","bicycle","bid","bike","bind","biology","birch","bird","birth","bitter","black","blade","blame","blanket","blast","bleak","bless","blind","blood","blossom","blouse","blue","blur","blush","board","boat","body","boil","bomb","bone","bonus","book","boost","border","boring","borrow","boss","bottom","bounce","box","boy","bracket","brain","brand","brass","brave","bread","breeze","brick","bridge","brief","bright","bring","brisk","broccoli","broken","bronze","broom","brother","brown","brush","bubble","buddy","budget","buffalo","build","bulb","bulk","bullet","bundle","bunker","burden","burger","burst","bus","business","busy","butter","buyer","buzz","cabbage","cabin","cable","cactus","cage","cake","call","calm","camera","camp","canal","cancel","candy","cannon","canoe","canvas","canyon","capable","capital","captain","carbon","card","cargo","carpet","carry","cart","case","cash","casino","castle","casual","cat","catalog","catch","cattle","caught","cause","caution","cave","cedar","ceiling","celery","cement","census","century","cereal","certain","chair","chalk","champion","change","chaos","chapter","charge","chase","chat","cheap","check","cheese","chef","cherry","chest","chicken","chief","child","chimney","choice","choose","chronic","chuckle","chunk","churn","cigar","cinnamon","circle","citizen","city","civil","claim","clap","clarify","claw","clay","clean","clerk","clever","click","client","cliff","climb","clinic","clip","clock","clog","close","cloth","cloud","clown","club","clump","cluster","clutch","coach","coast","coconut","code","coffee","coil","coin","collect","color","column","combine","come","comfort","comic","common","company","concert","conduct","confirm","congress","connect","consider","control","convince","cook","cool","copper","copy","coral","core","corn","correct","cost","cotton","couch","country","couple","course","cousin","cover","coyote","crack","cradle","craft","cram","crane","crash","crater","crawl","crazy","cream","credit","creek","crew","cricket","crime","crisp","critic","crop","cross","crouch","crowd","crucial","cruel","cruise","crumble","crunch","crush","cry","crystal","cube","culture","cup","curious","current","curtain","curve","cushion","custom","cute","cycle","dad","damage","damp","dance","danger","daring","dash","daughter","dawn","day","deal","debate","debris","decade","december","decide","decline","decorate","decrease","deer","defense","define","defy","degree","delay","deliver","demand","demise","denial","dentist","deny","depart","depend","deposit","depth","deputy","derive","describe","desert","design","desk","despair","destroy","detail","detect","develop","device","devote","diagram","dial","diamond","diary","dice","diesel","diet","differ","digital","dignity","dilemma","dinner","dinosaur","direct","dirt","disagree","discover","disease","dish","dismiss","disorder","display","distance","divert","divide","divorce","dizzy","doctor","document","dog","doll","dolphin","domain","donate","donkey","donor","door","dose","double","dove","draft","dragon","drama","drastic","draw","dream","dress","drift","drill","drink","drip","drive","drop","drum","dry","duck","dumb","dune","during","dust","dutch","duty","dwarf","dynamic","eager","eagle","early","earn","earth","easily","east","easy","echo","ecology","economy","edge","edit","educate","effort","egg","eight","either","elbow","elder","electric","elegant","element","elephant","elevator","elite","else","embark","embody","embrace","emerge","emotion","employ","empower","empty","enable","enact","end","endless","endorse","enemy","energy","enforce","engage","engine","enhance","enjoy","enlist","enough","enrich","enroll","ensure","enter","entire","entry","envelope","episode","equal","equip","era","erase","erode","erosion","error","erupt","escape","essay","essence","estate","eternal","ethics","evidence","evil","evoke","evolve","exact","example","excess","exchange","excite","exclude","excuse","execute","exercise","exhaust","exhibit","exile","exist","exit","exotic","expand","expect","expire","explain","expose","express","extend","extra","eye","eyebrow","fabric","face","faculty","fade","faint","faith","fall","false","fame","family","famous","fan","fancy","fantasy","farm","fashion","fat","fatal","father","fatigue","fault","favorite","feature","february","federal","fee","feed","feel","female","fence","fern","festival","fetch","fever","few","fiber","fiction","field","figure","file","film","filter","final","find","fine","finger","finish","fire","firm","first","fiscal","fish","fit","fitness","fix","flag","flame","flash","flat","flavor","flee","flight","flip","float","flock","floor","flower","fluid","flush","fly","foam","focus","fog","foil","fold","follow","food","foot","force","forest","forget","fork","fortune","forum","forward","fossil","foster","found","fox","fragile","frame","frequent","fresh","friend","fringe","frog","front","frost","frown","frozen","fruit","fuel","fun","funny","furnace","fury","future","gadget","gain","galaxy","gallery","game","gap","garage","garbage","garden","garlic","garment","gas","gasp","gate","gather","gauge","gaze","general","genius","genre","gentle","genuine","gesture","ghost","giant","gift","giggle","ginger","giraffe","girl","give","glad","glance","glare","glass","glide","glimpse","globe","gloom","glory","glove","glow","glue","goat","goddess","gold","good","goose","gorilla","gospel","gossip","govern","gown","grab","grace","grain","grant","grape","grass","gravity","great","green","grid","grief","grit","grocery","group","grow","grunt","guard","guess","guide","guilt","guitar","gun","gym","habit","hair","half","hammer","hamster","hand","happy","harbor","hard","harsh","harvest","hat","have","hawk","hazard","head","health","heart","heavy","hedgehog","height","hello","helmet","help","hen","hero","hidden","high","hill","hint","hip","hire","history","hobby","hockey","hold","hole","holiday","hollow","home","honey","hood","hope","horn","horror","horse","hospital","host","hotel","hour","hover","hub","huge","human","humble","humor","hundred","hungry","hunt","hurdle","hurry","hurt","husband","hybrid","ice","icon","idea","identify","idle","ignore","ill","illegal","illness","image","imitate","immense","immune","impact","impose","improve","impulse","inch","include","income","increase","index","indicate","indoor","industry","infant","inflict","inform","inhale","inherit","initial","inject","injury","inmate","inner","innocent","input","inquiry","insane","insect","inside","inspire","install","intact","interest","into","invest","invite","involve","iron","island","isolate","issue","item","ivory","ivy","jacket","jaguar","jar","jazz","jealous","jeans","jelly","jewel","job","join","joke","journey","joy","judge","juice","jump","jungle","junior","junk","just","kangaroo","keen","keep","ketchup","key","kick","kid","kidney","kind","kingdom","kiss","kit","kitchen","kite","kitten","kiwi","knee","knife","knock","know","lab","label","labor","ladder","lady","lake","lamp","language","laptop","large","later","latin","laugh","laundry","lava","law","lawn","lawsuit","layer","lazy","leader","leaf","learn","leave","lecture","left","leg","legal","legend","leisure","lemon","lend","length","lens","leopard","lesson","letter","level","liar","liberty","library","license","life","lift","light","like","limb","limit","link","lion","liquid","list","little","live","lizard","load","loan","lobster","local","lock","logic","lonely","long","loop","lottery","loud","lounge","love","loyal","lucky","luggage","lumber","lunar","lunch","luxury","lyrics","machine","mad","magic","magnet","maid","mail","main","major","make","mammal","man","manage","mandate","mango","mansion","manual","maple","marble","march","margin","marine","market","marriage","mask","mass","master","match","material","math","matrix","matter","maximum","maze","meadow","mean","measure","meat","mechanic","medal","media","melody","melt","member","memory","mention","menu","mercy","merge","merit","merry","mesh","message","metal","method","middle","midnight","milk","million","mimic","mind","minimum","minor","minute","miracle","mirror","misery","miss","mistake","mix","mixed","mixture","mobile","model","modify","mom","moment","monitor","monkey","monster","month","moon","moral","more","morning","mosquito","moss","mother","motion","motor","mountain","mouse","move","movie","much","muffin","mule","multiply","muscle","museum","mushroom","music","must","mutual","myself","mystery","myth","naive","name","napkin","narrow","nasty","nation","nature","near","neck","need","negative","neglect","neither","nephew","nerve","nest","net","network","neutral","never","news","next","nice","night","noble","noise","nominee","noodle","normal","north","nose","notable","note","nothing","notice","novel","now","nuclear","number","nurse","nut","oak","obey","object","oblige","obscure","observe","obtain","obvious","occur","ocean","october","odor","off","offer","office","often","oil","okay","old","olive","olympic","omit","once","one","onion","online","only","open","opera","opinion","oppose","option","orange","orbit","orchard","order","ordinary","organ","orient","original","orphan","ostrich","other","outdoor","outer","output","outside","oval","oven","over","own","owner","oxygen","oyster","ozone","pact","paddle","page","pair","palace","palm","panda","panel","panic","panther","paper","parade","parent","park","parrot","party","pass","patch","path","patient","patrol","pattern","pause","pave","payment","peace","peanut","pear","peasant","pelican","pen","penalty","pencil","people","pepper","perfect","permit","person","pet","phone","photo","phrase","physical","piano","picnic","picture","piece","pig","pigeon","pill","pilot","pink","pioneer","pipe","pistol","pitch","pizza","place","planet","plastic","plate","play","please","pledge","pluck","plug","plum","plunge","poem","poet","point","polar","pole","police","pond","pony","pool","popular","portion","position","possible","post","potato","pottery","poverty","powder","power","practice","praise","predict","prefer","prepare","present","pretty","prevent","price","pride","primary","print","priority","prison","private","prize","problem","process","produce","profit","program","project","promote","proof","property","prosper","protect","proud","provide","public","pudding","pull","pulp","pulse","pumpkin","punch","pupil","puppy","purchase","purity","purpose","purse","push","put","puzzle","pyramid","quality","quantum","quarter","question","quick","quiet","quit","quiz","quote","rabbit","raccoon","race","rack","radar","radio","rail","rain","raise","rally","ramp","ranch","random","range","rapid","rare","rate","rather","raven","raw","razor","ready","real","reason","rebel","rebuild","recall","receive","recipe","record","recycle","reduce","reflect","reform","refuse","region","regret","regular","reject","relax","release","relief","rely","remain","remember","remind","remove","render","renew","rent","reopen","repair","repeat","replace","report","require","rescue","resemble","resist","resource","response","result","retire","retreat","return","reunion","reveal","review","reward","rhythm","rib","ribbon","rice","rich","ride","ridge","rifle","right","rigid","ring","riot","ripple","risk","ritual","rival","river","road","roast","robot","robust","rocket","romance","roof","rookie","room","rose","rotate","rough","round","route","royal","rubber","rude","rug","rule","run","runway","rural","sad","saddle","sadness","safe","sail","salad","salmon","salon","salt","salute","same","sample","sand","satisfy","satoshi","sauce","sausage","save","say","scale","scan","scare","scatter","scene","scheme","school","science","scissors","scorpion","scout","scrap","screen","script","scrub","sea","search","season","seat","second","secret","section","security","seed","seek","segment","select","sell","seminar","senior","sense","sentence","series","service","session","settle","setup","seven","shadow","shaft","shallow","share","shed","shell","sheriff","shield","shift","shine","ship","shiver","shock","shoe","shoot","shop","short","shoulder","shove","shrimp","shrug","shuffle","shy","sibling","sick","side","siege","sight","sign","silent","silk","silly","silver","similar","simple","since","sing","siren","sister","situate","six","size","skate","sketch","ski","skill","skin","skirt","skull","slab","slam","sleep","slender","slice","slide","slight","slim","slogan","slot","slow","slush","small","smart","smile","smoke","smooth","snack","snake","snap","sniff","snow","soap","soccer","social","sock","soda","soft","solar","soldier","solid","solution","solve","someone","song","soon","sorry","sort","soul","sound","soup","source","south","space","spare","spatial","spawn","speak","special","speed","spell","spend","sphere","spice","spider","spike","spin","spirit","split","spoil","sponsor","spoon","sport","spot","spray","spread","spring","spy","square","squeeze","squirrel","stable","stadium","staff","stage","stairs","stamp","stand","start","state","stay","steak","steel","stem","step","stereo","stick","still","sting","stock","stomach","stone","stool","story","stove","strategy","street","strike","strong","struggle","student","stuff","stumble","style","subject","submit","subway","success","such","sudden","suffer","sugar","suggest","suit","summer","sun","sunny","sunset","super","supply","supreme","sure","surface","surge","surprise","surround","survey","suspect","sustain","swallow","swamp","swap","swarm","swear","sweet","swift","swim","swing","switch","sword","symbol","symptom","syrup","system","table","tackle","tag","tail","talent","talk","tank","tape","target","task","taste","tattoo","taxi","teach","team","tell","ten","tenant","tennis","tent","term","test","text","thank","that","theme","then","theory","there","they","thing","this","thought","three","thrive","throw","thumb","thunder","ticket","tide","tiger","tilt","timber","time","tiny","tip","tired","tissue","title","toast","tobacco","today","toddler","toe","together","toilet","token","tomato","tomorrow","tone","tongue","tonight","tool","tooth","top","topic","topple","torch","tornado","tortoise","toss","total","tourist","toward","tower","town","toy","track","trade","traffic","tragic","train","transfer","trap","trash","travel","tray","treat","tree","trend","trial","tribe","trick","trigger","trim","trip","trophy","trouble","truck","true","truly","trumpet","trust","truth","try","tube","tuition","tumble","tuna","tunnel","turkey","turn","turtle","twelve","twenty","twice","twin","twist","two","type","typical","ugly","umbrella","unable","unaware","uncle","uncover","under","undo","unfair","unfold","unhappy","uniform","unique","unit","universe","unknown","unlock","until","unusual","unveil","update","upgrade","uphold","upon","upper","upset","urban","urge","usage","use","used","useful","useless","usual","utility","vacant","vacuum","vague","valid","valley","valve","van","vanish","vapor","various","vast","vault","vehicle","velvet","vendor","venture","venue","verb","verify","version","very","vessel","veteran","viable","vibrant","vicious","victory","video","view","village","vintage","violin","virtual","virus","visa","visit","visual","vital","vivid","vocal","voice","void","volcano","volume","vote","voyage","wage","wagon","wait","walk","wall","walnut","want","warfare","warm","warrior","wash","wasp","waste","water","wave","way","wealth","weapon","wear","weasel","weather","web","wedding","weekend","weird","welcome","west","wet","whale","what","wheat","wheel","when","where","whip","whisper","wide","width","wife","wild","will","win","window","wine","wing","wink","winner","winter","wire","wisdom","wise","wish","witness","wolf","woman","wonder","wood","wool","word","work","world","worry","worth","wrap","wreck","wrestle","wrist","write","wrong","yard","year","yellow","you","young","youth","zebra","zero","zone","zoo"],rr=me.length,tr=new Map(me.map((e,r)=>[e,r]));var nr=128,at=nr/32;var A=class extends Error{constructor(r="This data could not be decrypted with the key provided."){super(r),this.name="OpenError"}};function re(...e){let r=0;for(let n of e)r+=n.length;let t=new Uint8Array(r),o=0;for(let n of e)t.set(n,o),o+=n.length;return t}function Ee(e){e.fill(0)}var or=new Uint8Array([47,101,110,99]),ar=new Uint8Array([47,109,97,99]),ir=new Uint8Array([109,97,105,108,99,121,99,108,101,47,118,49,47,115,101,97,108,45,116,111,45,112,117,98,108,105,99]);function sr(e,r,t){let o=re(ir,e,r,t),n=new Uint8Array(64);return n.set(U(e,re(o,or)),0),n.set(U(e,re(o,ar)),32),n}function Be(e,r,t){if(e.length!==32)throw new A("Private key must be 32 bytes.");if(r.ephemeralPublicKey.length!==32)throw new A;if(r.nonce.length!==12)throw new A;let o=Ue(e,r.ephemeralPublicKey);if(Se(o))throw new A;let n=sr(o,r.ephemeralPublicKey,q(e));try{let a=U(n.subarray(32,64),re(r.nonce,r.ciphertext,t));if(!Z(a,r.tag))throw new A;return O(n.subarray(0,32),r.nonce,r.ciphertext)}finally{Ee(o),Ee(n)}}function cr(e){return{ephemeralPublicKey:h(e.epk),nonce:h(e.n),ciphertext:h(e.c),tag:h(e.t)}}function Ce(e){return typeof e=="object"&&e!==null&&typeof e.epk=="string"}function _e(e,r,t=""){try{return Be(e,cr(r),v(t))}catch(o){throw o instanceof A?new R:o}}var Tt=80;var ne=class{symmetric=new Map;sealing=new Map;senderName=null;load(r,t,o){let n=h(r);if(n.length!==64)throw new Error("The saved wrap secret is malformed. Run `mailcycle-mcp pair` again.");let a=ue(n,o,t);this.symmetric=new Map(Object.entries(a.keys).map(([i,s])=>[i,h(s)])),this.sealing=new Map(Object.entries(a.sealingKeys??{}).map(([i,s])=>[i,h(s)])),this.senderName=a.senderName?.trim()||null}has(r){return this.sealing.has(r)||this.symmetric.has(r)}open(r,t,o){if(Ce(o)){let a=this.sealing.get(r);if(!a)throw new $(r);return JSON.parse(I(_e(a,o,`${r}:${t}`)))}let n=this.symmetric.get(r);if(!n)throw new $(r);return ue(n,o,t)}},$=class extends Error{constructor(t){super("This agent has no key for that address yet. Open the agent in the Mailcycle app and add the address again.");this.inboxId=t;this.name="MissingKeyError"}};var y=e=>typeof e=="string"?e:"";function lr(e){return typeof e=="string"?e:e&&typeof e=="object"?y(e.address):""}function ur(e){return e.replace(/<(script|style)[^>]*>[\s\S]*?<\/\1>/gi,"").replace(/<br\s*\/?>/gi,`
|
|
3
|
+
var Ke=Object.defineProperty;var Oe=(e,r)=>{for(var t in r)Ke(e,t,{get:r[t],enumerable:!0})};var S=class extends Error{constructor(t,o,n){super(n);this.status=t;this.code=o;this.name="MailcycleError"}};function _(e){return e instanceof S&&e.status===401}var w=class{constructor(r,t){this.baseUrl=r;this.token=t}async request(r,t,o,n){let a=await this.fetch(r,t,o,n),i=await a.text(),s=i?JSON.parse(i):{};if(!a.ok)throw new S(a.status,String(s.code??"error"),String(s.message??`Mailcycle answered ${a.status}.`));return s}async fetch(r,t,o,n){try{return await this.rawFetch(r,t,o,n)}catch(a){throw a.name==="AbortError"?a:new S(0,"unreachable",`Could not reach Mailcycle at ${this.baseUrl}. Check the connection.`)}}rawFetch(r,t,o,n){return fetch(`${this.baseUrl}${t}`,{method:r,headers:{...this.token?{Authorization:`Bearer ${this.token}`}:{},...o===void 0?{}:{"Content-Type":"application/json"},"User-Agent":"mailcycle-mcp/0.2"},...o===void 0?{}:{body:JSON.stringify(o)},...n?{signal:n}:{}})}createPairingSession(r){return this.request("POST","/workers/pairing-session",{platform:"agent",deviceName:r})}pollPairing(r){return this.request("GET",`/workers/pairing-session/${encodeURIComponent(r)}`)}self(){return this.request("GET","/workers/self")}heartbeat(){return this.request("POST","/workers/heartbeat",{})}messages(r,t){let o=new URLSearchParams;for(let[n,a]of Object.entries(r))a!==void 0&&o.set(n,String(a));return this.request("GET",`/workers/messages?${o}`,void 0,t)}send(r){return this.request("POST","/messages/send",r)}};var ie={};Oe(ie,{getRandomValues:()=>ae});var ae=void 0;var j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";function v(e){let r=[];for(let t=0;t<e.length;t+=1){let o=e.charCodeAt(t);if(o>=55296&&o<=56319&&t+1<e.length){let n=e.charCodeAt(t+1);n>=56320&&n<=57343&&(o=65536+(o-55296<<10)+(n-56320),t+=1)}o<128?r.push(o):o<2048?r.push(192|o>>6,128|o&63):o<65536?r.push(224|o>>12,128|o>>6&63,128|o&63):r.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|o&63)}return new Uint8Array(r)}function I(e){let r="";for(let t=0;t<e.length;){let o=e[t],n;o<128?(n=o,t+=1):o<224?(n=(o&31)<<6|e[t+1]&63,t+=2):o<240?(n=(o&15)<<12|(e[t+1]&63)<<6|e[t+2]&63,t+=3):(n=(o&7)<<18|(e[t+1]&63)<<12|(e[t+2]&63)<<6|e[t+3]&63,t+=4),n>65535?(n-=65536,r+=String.fromCharCode(55296+(n>>10),56320+(n&1023))):r+=String.fromCharCode(n)}return r}function N(e){let r="";for(let t=0;t<e.length;t+=3){let o=e[t],n=t+1<e.length?e[t+1]:-1,a=t+2<e.length?e[t+2]:-1;if(r+=j[o>>2],r+=j[(o&3)<<4|(n>=0?n>>4:0)],n<0||(r+=j[(n&15)<<2|(a>=0?a>>6:0)],a<0))break;r+=j[a&63]}return r}var P=class extends Error{constructor(r="Not canonical base64url."){super(r),this.name="Base64UrlError"}};function h(e){if(e.length%4===1)throw new P("Truncated base64url.");let t=new Uint8Array(Math.floor(e.length*6/8)),o=0,n=0,a=0;for(let i=0;i<e.length;i+=1){let s=j.indexOf(e[i]);if(s<0)throw new P(`Unexpected character at ${i}.`);o=o<<6|s,n+=6,n>=8&&(n-=8,t[a]=o>>n&255,a+=1)}if(n>0&&(o&(1<<n)-1)!==0)throw new P("Non-canonical trailing bits.");return t}function V(...e){let r=e.reduce((n,a)=>n+a.length,0),t=new Uint8Array(r),o=0;for(let n of e)t.set(n,o),o+=n.length;return t}function ye(){let e=[],r=globalThis.crypto;return typeof r?.getRandomValues=="function"&&e.push({name:"webcrypto",fill:t=>void r.getRandomValues(t)}),typeof ie?.getRandomValues=="function"&&e.push({name:"expo-crypto",fill:t=>void(void 0)(t)}),e}var J=class extends Error{constructor(){super("No cryptographically secure random source available. Mailcycle will not generate key material without one."),this.name="NoRandomSourceError"}};function K(e){let r=ye()[0];if(!r)throw new J;let t=new Uint8Array(e);return r.fill(t),t}function G(e,r){return(e<<r|e>>>32-r)>>>0}function k(e,r,t,o,n){e[r]=e[r]+e[t]>>>0,e[n]=G(e[n]^e[r],16),e[o]=e[o]+e[n]>>>0,e[t]=G(e[t]^e[o],12),e[r]=e[r]+e[t]>>>0,e[n]=G(e[n]^e[r],8),e[o]=e[o]+e[n]>>>0,e[t]=G(e[t]^e[o],7)}function O(e,r,t){if(e.length!==32)throw new Error("ChaCha20 key must be 32 bytes.");if(r.length!==12)throw new Error("ChaCha20 nonce must be 12 bytes.");let o=new DataView(e.buffer,e.byteOffset,e.byteLength),n=new DataView(r.buffer,r.byteOffset,r.byteLength),a=new Uint32Array(16);a[0]=1634760805,a[1]=857760878,a[2]=2036477234,a[3]=1797285236;for(let l=0;l<8;l+=1)a[4+l]=o.getUint32(l*4,!0);a[13]=n.getUint32(0,!0),a[14]=n.getUint32(4,!0),a[15]=n.getUint32(8,!0);let i=new Uint8Array(t.length),s=new Uint32Array(16),c=new Uint8Array(64),m=new DataView(c.buffer);for(let l=0;l*64<t.length;l+=1){s.set(a),s[12]=l;for(let f=0;f<10;f+=1)k(s,0,4,8,12),k(s,1,5,9,13),k(s,2,6,10,14),k(s,3,7,11,15),k(s,0,5,10,15),k(s,1,6,11,12),k(s,2,7,8,13),k(s,3,4,9,14);for(let f=0;f<16;f+=1){let oe=f===12?s[f]+l>>>0:s[f]+a[f]>>>0;m.setUint32(f*4,oe,!0)}let u=l*64,g=Math.min(64,t.length-u);for(let f=0;f<g;f+=1)i[u+f]=t[u+f]^c[f]}return i}var ze=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),se=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),E=64,we=32,X=8,d=new Uint32Array(64),T=new Uint32Array(X),ce=new Uint32Array(X);function Fe(){d.fill(0),T.fill(0),ce.fill(0)}function z(e){for(let m=16;m<64;m+=1){let l=d[m-15],u=d[m-2],g=(l>>>7|l<<25)^(l>>>18|l<<14)^l>>>3,f=(u>>>17|u<<15)^(u>>>19|u<<13)^u>>>10;d[m]=d[m-16]+g+d[m-7]+f>>>0}let r=e[0],t=e[1],o=e[2],n=e[3],a=e[4],i=e[5],s=e[6],c=e[7];for(let m=0;m<64;m+=1){let l=(a>>>6|a<<26)^(a>>>11|a<<21)^(a>>>25|a<<7),u=a&i^~a&s,g=c+l+u+ze[m]+d[m]>>>0,f=(r>>>2|r<<30)^(r>>>13|r<<19)^(r>>>22|r<<10),oe=r&t^r&o^t&o,Ne=f+oe>>>0;c=s,s=i,i=a,a=n+g>>>0,n=o,o=t,t=r,r=g+Ne>>>0}e[0]=e[0]+r>>>0,e[1]=e[1]+t>>>0,e[2]=e[2]+o>>>0,e[3]=e[3]+n>>>0,e[4]=e[4]+a>>>0,e[5]=e[5]+i>>>0,e[6]=e[6]+s>>>0,e[7]=e[7]+c>>>0}function be(e,r){for(let t=0;t<16;t+=1){let o=r+t*4;d[t]=(e[o]<<24|e[o+1]<<16|e[o+2]<<8|e[o+3])>>>0}}function xe(e,r,t){let o=r.length,n=o-o%E;for(let u=0;u<n;u+=E)be(r,u),z(e);let a=o-n,i=new Uint8Array(a+9+63>=128?128:64);i.set(r.subarray(n)),i[a]=128;let s=(t+o)*8,c=i.length,m=Math.floor(s/4294967296),l=s>>>0;i[c-8]=m>>>24&255,i[c-7]=m>>>16&255,i[c-6]=m>>>8&255,i[c-5]=m&255,i[c-4]=l>>>24&255,i[c-3]=l>>>16&255,i[c-2]=l>>>8&255,i[c-1]=l&255;for(let u=0;u<c;u+=E)be(i,u),z(e)}function Ae(e){let r=new Uint8Array(we);for(let t=0;t<X;t+=1){let o=e[t],n=t*4;r[n]=o>>>24&255,r[n+1]=o>>>16&255,r[n+2]=o>>>8&255,r[n+3]=o&255}return r}function F(e){let r=new Uint32Array(se);return xe(r,e,0),Ae(r)}function We(e){let r=new Uint8Array(E);r.set(e.length>E?F(e):e);let t=new Uint32Array(se);for(let n=0;n<16;n+=1){let a=n*4;d[n]=((r[a]^54)<<24|(r[a+1]^54)<<16|(r[a+2]^54)<<8|r[a+3]^54)>>>0}z(t);let o=new Uint32Array(se);for(let n=0;n<16;n+=1){let a=n*4;d[n]=((r[a]^92)<<24|(r[a+1]^92)<<16|(r[a+2]^92)<<8|r[a+3]^92)>>>0}return z(o),{inner:t,outer:o}}function Le(e,r,t){T.set(e.inner),xe(T,r,E),ce.set(T),T.set(e.outer),De(ce),z(T),t.set(T)}function De(e){d[0]=e[0],d[1]=e[1],d[2]=e[2],d[3]=e[3],d[4]=e[4],d[5]=e[5],d[6]=e[6],d[7]=e[7],d[8]=2147483648,d[9]=0,d[10]=0,d[11]=0,d[12]=0,d[13]=0,d[14]=0,d[15]=(E+we)*8}function U(e,r){let t=new Uint32Array(X);return Le(We(e),r,t),Fe(),Ae(t)}function Z(e,r){if(e.length!==r.length)return!1;let t=0;for(let o=0;o<e.length;o+=1)t|=e[o]^r[o];return t===0}function qe(e){if(e.length!==64)throw new Error("Expected a 64-byte secret.");return{encryption:e.slice(0,32),mac:e.slice(32,64)}}var R=class extends Error{constructor(r="This data could not be decrypted with the key provided."){super(r),this.name="DecryptionError"}};function He(e,r,t=""){let{encryption:o,mac:n}=qe(e),a=h(r.n),i=h(r.c),s=U(n,V(a,i,v(t)));if(a.length!==12)throw new R;if(!Z(s,h(r.t)))throw new R;return O(o,a,i)}function ue(e,r,t=""){return JSON.parse(I(He(e,r,t)))}function b(e){let r=new Float64Array(16);if(e)for(let t=0;t<e.length;t+=1)r[t]=e[t];return r}var Ye=b([56129,1]);function D(e){let r=1;for(let t=0;t<16;t+=1){let o=e[t]+r+65535;r=Math.floor(o/65536),e[t]=o-r*65536}e[0]=e[0]+(r-1)+37*(r-1)}function W(e,r,t){let o=~(t-1);for(let n=0;n<16;n+=1){let a=o&(e[n]^r[n]);e[n]=e[n]^a,r[n]=r[n]^a}}function Je(e,r){let t=b(),o=b();for(let n=0;n<16;n+=1)o[n]=r[n];D(o),D(o),D(o);for(let n=0;n<2;n+=1){t[0]=o[0]-65517;for(let i=1;i<15;i+=1)t[i]=o[i]-65535-(t[i-1]>>16&1),t[i-1]=t[i-1]&65535;t[15]=o[15]-32767-(t[14]>>16&1);let a=t[15]>>16&1;t[14]=t[14]&65535,W(o,t,1-a)}for(let n=0;n<16;n+=1)e[2*n]=o[n]&255,e[2*n+1]=o[n]>>8}function Ve(e,r){for(let t=0;t<16;t+=1)e[t]=r[2*t]+(r[2*t+1]<<8);e[15]=e[15]&32767}function Q(e,r,t){for(let o=0;o<16;o+=1)e[o]=r[o]+t[o]}function ee(e,r,t){for(let o=0;o<16;o+=1)e[o]=r[o]-t[o]}var Ge=new Float64Array(31);function x(e,r,t){let o=Ge;for(let n=0;n<31;n+=1)o[n]=0;for(let n=0;n<16;n+=1){let a=r[n];for(let i=0;i<16;i+=1)o[n+i]=o[n+i]+a*t[i]}for(let n=0;n<15;n+=1)o[n]=o[n]+38*o[n+16];for(let n=0;n<16;n+=1)e[n]=o[n];D(e),D(e),o.fill(0)}function L(e,r){x(e,r,r)}function Xe(e,r){let t=b();for(let o=0;o<16;o+=1)t[o]=r[o];for(let o=253;o>=0;o-=1)L(t,t),o!==2&&o!==4&&x(t,t,r);for(let o=0;o<16;o+=1)e[o]=t[o]}function ve(e,r){if(e.length!==32)throw new Error("x25519: scalar must be 32 bytes");if(r.length!==32)throw new Error("x25519: point must be 32 bytes");let t=new Uint8Array(32);for(let u=0;u<31;u+=1)t[u]=e[u];t[31]=e[31]&127|64,t[0]=t[0]&248;let o=b();Ve(o,r);let n=b(),a=b(),i=b(),s=b(),c=b(),m=b();for(let u=0;u<16;u+=1)a[u]=o[u];n[0]=1,s[0]=1;for(let u=254;u>=0;u-=1){let g=t[u>>>3]>>>(u&7)&1;W(n,a,g),W(i,s,g),Q(c,n,i),ee(n,n,i),Q(i,a,s),ee(a,a,s),L(s,c),L(m,n),x(n,i,n),x(i,a,c),Q(c,n,i),ee(n,n,i),L(a,n),ee(i,s,m),x(n,i,Ye),Q(n,n,s),x(i,i,n),x(n,s,m),x(s,a,o),L(a,c),W(n,a,g),W(i,s,g)}Xe(i,i),x(n,n,i);let l=new Uint8Array(32);return Je(l,n),l}var ke=new Uint8Array(32);ke[0]=9;function Ze(e){return ve(e,ke)}function q(e){return Ze(e)}function Ue(e,r){return ve(e,r)}function Se(e){let r=0;for(let t=0;t<e.length;t+=1)r|=e[t];return r===0}var me=["able","about","above","absent","absorb","abstract","accent","accident","account","accuse","ache","achieve","acid","acorn","acquire","across","action","actor","actual","adapt","addict","address","adjust","admit","adopt","adult","advance","advice","affair","afford","afraid","after","again","agent","agree","ahead","aim","air","alarm","album","alert","alien","align","alike","alive","allow","almost","alone","alpha","already","also","alter","always","amateur","amazing","amber","ambush","among","amount","ample","amused","anchor","ancient","anger","angle","angry","animal","ankle","announce","annual","another","answer","antenna","antique","anxiety","any","apart","apology","appear","apple","april","arch","arctic","area","arena","argue","arise","armed","armor","army","around","arrange","arrest","arrive","arrow","art","artist","artwork","ashamed","aside","ask","aspect","asphalt","assault","asset","assist","assume","asthma","athlete","atlas","atom","attack","attend","attitude","attract","auction","audit","august","aunt","author","auto","autumn","average","avocado","avoid","awake","aware","away","awesome","awful","awkward","axis","baby","bachelor","bacon","badge","bag","balance","balcony","ball","bamboo","banana","banner","bar","barely","bargain","barrel","base","basic","basket","battle","beach","bean","beauty","because","become","beef","before","begin","behave","behind","believe","below","belt","bench","benefit","berry","best","betray","better","between","beyond","bicycle","bid","bike","bind","biology","birch","bird","birth","bitter","black","blade","blame","blanket","blast","bleak","bless","blind","blood","blossom","blouse","blue","blur","blush","board","boat","body","boil","bomb","bone","bonus","book","boost","border","boring","borrow","boss","bottom","bounce","box","boy","bracket","brain","brand","brass","brave","bread","breeze","brick","bridge","brief","bright","bring","brisk","broccoli","broken","bronze","broom","brother","brown","brush","bubble","buddy","budget","buffalo","build","bulb","bulk","bullet","bundle","bunker","burden","burger","burst","bus","business","busy","butter","buyer","buzz","cabbage","cabin","cable","cactus","cage","cake","call","calm","camera","camp","canal","cancel","candy","cannon","canoe","canvas","canyon","capable","capital","captain","carbon","card","cargo","carpet","carry","cart","case","cash","casino","castle","casual","cat","catalog","catch","cattle","caught","cause","caution","cave","cedar","ceiling","celery","cement","census","century","cereal","certain","chair","chalk","champion","change","chaos","chapter","charge","chase","chat","cheap","check","cheese","chef","cherry","chest","chicken","chief","child","chimney","choice","choose","chronic","chuckle","chunk","churn","cigar","cinnamon","circle","citizen","city","civil","claim","clap","clarify","claw","clay","clean","clerk","clever","click","client","cliff","climb","clinic","clip","clock","clog","close","cloth","cloud","clown","club","clump","cluster","clutch","coach","coast","coconut","code","coffee","coil","coin","collect","color","column","combine","come","comfort","comic","common","company","concert","conduct","confirm","congress","connect","consider","control","convince","cook","cool","copper","copy","coral","core","corn","correct","cost","cotton","couch","country","couple","course","cousin","cover","coyote","crack","cradle","craft","cram","crane","crash","crater","crawl","crazy","cream","credit","creek","crew","cricket","crime","crisp","critic","crop","cross","crouch","crowd","crucial","cruel","cruise","crumble","crunch","crush","cry","crystal","cube","culture","cup","curious","current","curtain","curve","cushion","custom","cute","cycle","dad","damage","damp","dance","danger","daring","dash","daughter","dawn","day","deal","debate","debris","decade","december","decide","decline","decorate","decrease","deer","defense","define","defy","degree","delay","deliver","demand","demise","denial","dentist","deny","depart","depend","deposit","depth","deputy","derive","describe","desert","design","desk","despair","destroy","detail","detect","develop","device","devote","diagram","dial","diamond","diary","dice","diesel","diet","differ","digital","dignity","dilemma","dinner","dinosaur","direct","dirt","disagree","discover","disease","dish","dismiss","disorder","display","distance","divert","divide","divorce","dizzy","doctor","document","dog","doll","dolphin","domain","donate","donkey","donor","door","dose","double","dove","draft","dragon","drama","drastic","draw","dream","dress","drift","drill","drink","drip","drive","drop","drum","dry","duck","dumb","dune","during","dust","dutch","duty","dwarf","dynamic","eager","eagle","early","earn","earth","easily","east","easy","echo","ecology","economy","edge","edit","educate","effort","egg","eight","either","elbow","elder","electric","elegant","element","elephant","elevator","elite","else","embark","embody","embrace","emerge","emotion","employ","empower","empty","enable","enact","end","endless","endorse","enemy","energy","enforce","engage","engine","enhance","enjoy","enlist","enough","enrich","enroll","ensure","enter","entire","entry","envelope","episode","equal","equip","era","erase","erode","erosion","error","erupt","escape","essay","essence","estate","eternal","ethics","evidence","evil","evoke","evolve","exact","example","excess","exchange","excite","exclude","excuse","execute","exercise","exhaust","exhibit","exile","exist","exit","exotic","expand","expect","expire","explain","expose","express","extend","extra","eye","eyebrow","fabric","face","faculty","fade","faint","faith","fall","false","fame","family","famous","fan","fancy","fantasy","farm","fashion","fat","fatal","father","fatigue","fault","favorite","feature","february","federal","fee","feed","feel","female","fence","fern","festival","fetch","fever","few","fiber","fiction","field","figure","file","film","filter","final","find","fine","finger","finish","fire","firm","first","fiscal","fish","fit","fitness","fix","flag","flame","flash","flat","flavor","flee","flight","flip","float","flock","floor","flower","fluid","flush","fly","foam","focus","fog","foil","fold","follow","food","foot","force","forest","forget","fork","fortune","forum","forward","fossil","foster","found","fox","fragile","frame","frequent","fresh","friend","fringe","frog","front","frost","frown","frozen","fruit","fuel","fun","funny","furnace","fury","future","gadget","gain","galaxy","gallery","game","gap","garage","garbage","garden","garlic","garment","gas","gasp","gate","gather","gauge","gaze","general","genius","genre","gentle","genuine","gesture","ghost","giant","gift","giggle","ginger","giraffe","girl","give","glad","glance","glare","glass","glide","glimpse","globe","gloom","glory","glove","glow","glue","goat","goddess","gold","good","goose","gorilla","gospel","gossip","govern","gown","grab","grace","grain","grant","grape","grass","gravity","great","green","grid","grief","grit","grocery","group","grow","grunt","guard","guess","guide","guilt","guitar","gun","gym","habit","hair","half","hammer","hamster","hand","happy","harbor","hard","harsh","harvest","hat","have","hawk","hazard","head","health","heart","heavy","hedgehog","height","hello","helmet","help","hen","hero","hidden","high","hill","hint","hip","hire","history","hobby","hockey","hold","hole","holiday","hollow","home","honey","hood","hope","horn","horror","horse","hospital","host","hotel","hour","hover","hub","huge","human","humble","humor","hundred","hungry","hunt","hurdle","hurry","hurt","husband","hybrid","ice","icon","idea","identify","idle","ignore","ill","illegal","illness","image","imitate","immense","immune","impact","impose","improve","impulse","inch","include","income","increase","index","indicate","indoor","industry","infant","inflict","inform","inhale","inherit","initial","inject","injury","inmate","inner","innocent","input","inquiry","insane","insect","inside","inspire","install","intact","interest","into","invest","invite","involve","iron","island","isolate","issue","item","ivory","ivy","jacket","jaguar","jar","jazz","jealous","jeans","jelly","jewel","job","join","joke","journey","joy","judge","juice","jump","jungle","junior","junk","just","kangaroo","keen","keep","ketchup","key","kick","kid","kidney","kind","kingdom","kiss","kit","kitchen","kite","kitten","kiwi","knee","knife","knock","know","lab","label","labor","ladder","lady","lake","lamp","language","laptop","large","later","latin","laugh","laundry","lava","law","lawn","lawsuit","layer","lazy","leader","leaf","learn","leave","lecture","left","leg","legal","legend","leisure","lemon","lend","length","lens","leopard","lesson","letter","level","liar","liberty","library","license","life","lift","light","like","limb","limit","link","lion","liquid","list","little","live","lizard","load","loan","lobster","local","lock","logic","lonely","long","loop","lottery","loud","lounge","love","loyal","lucky","luggage","lumber","lunar","lunch","luxury","lyrics","machine","mad","magic","magnet","maid","mail","main","major","make","mammal","man","manage","mandate","mango","mansion","manual","maple","marble","march","margin","marine","market","marriage","mask","mass","master","match","material","math","matrix","matter","maximum","maze","meadow","mean","measure","meat","mechanic","medal","media","melody","melt","member","memory","mention","menu","mercy","merge","merit","merry","mesh","message","metal","method","middle","midnight","milk","million","mimic","mind","minimum","minor","minute","miracle","mirror","misery","miss","mistake","mix","mixed","mixture","mobile","model","modify","mom","moment","monitor","monkey","monster","month","moon","moral","more","morning","mosquito","moss","mother","motion","motor","mountain","mouse","move","movie","much","muffin","mule","multiply","muscle","museum","mushroom","music","must","mutual","myself","mystery","myth","naive","name","napkin","narrow","nasty","nation","nature","near","neck","need","negative","neglect","neither","nephew","nerve","nest","net","network","neutral","never","news","next","nice","night","noble","noise","nominee","noodle","normal","north","nose","notable","note","nothing","notice","novel","now","nuclear","number","nurse","nut","oak","obey","object","oblige","obscure","observe","obtain","obvious","occur","ocean","october","odor","off","offer","office","often","oil","okay","old","olive","olympic","omit","once","one","onion","online","only","open","opera","opinion","oppose","option","orange","orbit","orchard","order","ordinary","organ","orient","original","orphan","ostrich","other","outdoor","outer","output","outside","oval","oven","over","own","owner","oxygen","oyster","ozone","pact","paddle","page","pair","palace","palm","panda","panel","panic","panther","paper","parade","parent","park","parrot","party","pass","patch","path","patient","patrol","pattern","pause","pave","payment","peace","peanut","pear","peasant","pelican","pen","penalty","pencil","people","pepper","perfect","permit","person","pet","phone","photo","phrase","physical","piano","picnic","picture","piece","pig","pigeon","pill","pilot","pink","pioneer","pipe","pistol","pitch","pizza","place","planet","plastic","plate","play","please","pledge","pluck","plug","plum","plunge","poem","poet","point","polar","pole","police","pond","pony","pool","popular","portion","position","possible","post","potato","pottery","poverty","powder","power","practice","praise","predict","prefer","prepare","present","pretty","prevent","price","pride","primary","print","priority","prison","private","prize","problem","process","produce","profit","program","project","promote","proof","property","prosper","protect","proud","provide","public","pudding","pull","pulp","pulse","pumpkin","punch","pupil","puppy","purchase","purity","purpose","purse","push","put","puzzle","pyramid","quality","quantum","quarter","question","quick","quiet","quit","quiz","quote","rabbit","raccoon","race","rack","radar","radio","rail","rain","raise","rally","ramp","ranch","random","range","rapid","rare","rate","rather","raven","raw","razor","ready","real","reason","rebel","rebuild","recall","receive","recipe","record","recycle","reduce","reflect","reform","refuse","region","regret","regular","reject","relax","release","relief","rely","remain","remember","remind","remove","render","renew","rent","reopen","repair","repeat","replace","report","require","rescue","resemble","resist","resource","response","result","retire","retreat","return","reunion","reveal","review","reward","rhythm","rib","ribbon","rice","rich","ride","ridge","rifle","right","rigid","ring","riot","ripple","risk","ritual","rival","river","road","roast","robot","robust","rocket","romance","roof","rookie","room","rose","rotate","rough","round","route","royal","rubber","rude","rug","rule","run","runway","rural","sad","saddle","sadness","safe","sail","salad","salmon","salon","salt","salute","same","sample","sand","satisfy","satoshi","sauce","sausage","save","say","scale","scan","scare","scatter","scene","scheme","school","science","scissors","scorpion","scout","scrap","screen","script","scrub","sea","search","season","seat","second","secret","section","security","seed","seek","segment","select","sell","seminar","senior","sense","sentence","series","service","session","settle","setup","seven","shadow","shaft","shallow","share","shed","shell","sheriff","shield","shift","shine","ship","shiver","shock","shoe","shoot","shop","short","shoulder","shove","shrimp","shrug","shuffle","shy","sibling","sick","side","siege","sight","sign","silent","silk","silly","silver","similar","simple","since","sing","siren","sister","situate","six","size","skate","sketch","ski","skill","skin","skirt","skull","slab","slam","sleep","slender","slice","slide","slight","slim","slogan","slot","slow","slush","small","smart","smile","smoke","smooth","snack","snake","snap","sniff","snow","soap","soccer","social","sock","soda","soft","solar","soldier","solid","solution","solve","someone","song","soon","sorry","sort","soul","sound","soup","source","south","space","spare","spatial","spawn","speak","special","speed","spell","spend","sphere","spice","spider","spike","spin","spirit","split","spoil","sponsor","spoon","sport","spot","spray","spread","spring","spy","square","squeeze","squirrel","stable","stadium","staff","stage","stairs","stamp","stand","start","state","stay","steak","steel","stem","step","stereo","stick","still","sting","stock","stomach","stone","stool","story","stove","strategy","street","strike","strong","struggle","student","stuff","stumble","style","subject","submit","subway","success","such","sudden","suffer","sugar","suggest","suit","summer","sun","sunny","sunset","super","supply","supreme","sure","surface","surge","surprise","surround","survey","suspect","sustain","swallow","swamp","swap","swarm","swear","sweet","swift","swim","swing","switch","sword","symbol","symptom","syrup","system","table","tackle","tag","tail","talent","talk","tank","tape","target","task","taste","tattoo","taxi","teach","team","tell","ten","tenant","tennis","tent","term","test","text","thank","that","theme","then","theory","there","they","thing","this","thought","three","thrive","throw","thumb","thunder","ticket","tide","tiger","tilt","timber","time","tiny","tip","tired","tissue","title","toast","tobacco","today","toddler","toe","together","toilet","token","tomato","tomorrow","tone","tongue","tonight","tool","tooth","top","topic","topple","torch","tornado","tortoise","toss","total","tourist","toward","tower","town","toy","track","trade","traffic","tragic","train","transfer","trap","trash","travel","tray","treat","tree","trend","trial","tribe","trick","trigger","trim","trip","trophy","trouble","truck","true","truly","trumpet","trust","truth","try","tube","tuition","tumble","tuna","tunnel","turkey","turn","turtle","twelve","twenty","twice","twin","twist","two","type","typical","ugly","umbrella","unable","unaware","uncle","uncover","under","undo","unfair","unfold","unhappy","uniform","unique","unit","universe","unknown","unlock","until","unusual","unveil","update","upgrade","uphold","upon","upper","upset","urban","urge","usage","use","used","useful","useless","usual","utility","vacant","vacuum","vague","valid","valley","valve","van","vanish","vapor","various","vast","vault","vehicle","velvet","vendor","venture","venue","verb","verify","version","very","vessel","veteran","viable","vibrant","vicious","victory","video","view","village","vintage","violin","virtual","virus","visa","visit","visual","vital","vivid","vocal","voice","void","volcano","volume","vote","voyage","wage","wagon","wait","walk","wall","walnut","want","warfare","warm","warrior","wash","wasp","waste","water","wave","way","wealth","weapon","wear","weasel","weather","web","wedding","weekend","weird","welcome","west","wet","whale","what","wheat","wheel","when","where","whip","whisper","wide","width","wife","wild","will","win","window","wine","wing","wink","winner","winter","wire","wisdom","wise","wish","witness","wolf","woman","wonder","wood","wool","word","work","world","worry","worth","wrap","wreck","wrestle","wrist","write","wrong","yard","year","yellow","you","young","youth","zebra","zero","zone","zoo"],rr=me.length,tr=new Map(me.map((e,r)=>[e,r]));var nr=128,it=nr/32;var A=class extends Error{constructor(r="This data could not be decrypted with the key provided."){super(r),this.name="OpenError"}};function re(...e){let r=0;for(let n of e)r+=n.length;let t=new Uint8Array(r),o=0;for(let n of e)t.set(n,o),o+=n.length;return t}function Ee(e){e.fill(0)}var or=new Uint8Array([47,101,110,99]),ar=new Uint8Array([47,109,97,99]),ir=new Uint8Array([109,97,105,108,99,121,99,108,101,47,118,49,47,115,101,97,108,45,116,111,45,112,117,98,108,105,99]);function sr(e,r,t){let o=re(ir,e,r,t),n=new Uint8Array(64);return n.set(U(e,re(o,or)),0),n.set(U(e,re(o,ar)),32),n}function Be(e,r,t){if(e.length!==32)throw new A("Private key must be 32 bytes.");if(r.ephemeralPublicKey.length!==32)throw new A;if(r.nonce.length!==12)throw new A;let o=Ue(e,r.ephemeralPublicKey);if(Se(o))throw new A;let n=sr(o,r.ephemeralPublicKey,q(e));try{let a=U(n.subarray(32,64),re(r.nonce,r.ciphertext,t));if(!Z(a,r.tag))throw new A;return O(n.subarray(0,32),r.nonce,r.ciphertext)}finally{Ee(o),Ee(n)}}function cr(e){return{ephemeralPublicKey:h(e.epk),nonce:h(e.n),ciphertext:h(e.c),tag:h(e.t)}}function Ce(e){return typeof e=="object"&&e!==null&&typeof e.epk=="string"}function _e(e,r,t=""){try{return Be(e,cr(r),v(t))}catch(o){throw o instanceof A?new R:o}}var Et=80;var ne=class{symmetric=new Map;sealing=new Map;senderName=null;load(r,t,o){let n=h(r);if(n.length!==64)throw new Error("The saved wrap secret is malformed. Run `mailcycle-mcp pair` again.");let a=ue(n,o,t);this.symmetric=new Map(Object.entries(a.keys).map(([i,s])=>[i,h(s)])),this.sealing=new Map(Object.entries(a.sealingKeys??{}).map(([i,s])=>[i,h(s)])),this.senderName=a.senderName?.trim()||null}has(r){return this.sealing.has(r)||this.symmetric.has(r)}open(r,t,o){if(Ce(o)){let a=this.sealing.get(r);if(!a)throw new $(r);return JSON.parse(I(_e(a,o,`${r}:${t}`)))}let n=this.symmetric.get(r);if(!n)throw new $(r);return ue(n,o,t)}},$=class extends Error{constructor(t){super("This agent has no key for that address yet. Open the agent in the Mailcycle app and add the address again.");this.inboxId=t;this.name="MissingKeyError"}};var y=e=>typeof e=="string"?e:"";function lr(e){return typeof e=="string"?e:e&&typeof e=="object"?y(e.address):""}function ur(e){return e.replace(/<(script|style)[^>]*>[\s\S]*?<\/\1>/gi,"").replace(/<br\s*\/?>/gi,`
|
|
4
4
|
`).replace(/<\/(p|div|tr|li|h[1-6])>/gi,`
|
|
5
5
|
`).replace(/<[^>]+>/g,"").replace(/ /g," ").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/\n{3,}/g,`
|
|
6
6
|
|
|
@@ -18,5 +18,5 @@ Add it to your MCP client, for example:
|
|
|
18
18
|
`),console.log(` claude mcp add mailcycle -- npx -y mailcycle-mcp
|
|
19
19
|
`);return}await xr(wr)}}import{McpServer as vr}from"@modelcontextprotocol/sdk/server/mcp.js";import{StdioServerTransport as kr}from"@modelcontextprotocol/sdk/server/stdio.js";import{z as p}from"zod";var Ur={off:"Sending is off. This agent can only read.",reply:"Reply only: this agent can answer whoever wrote a message it received, and no one else. Use the reply tool.",full:"This agent can send to any address, up to 20 messages an hour."},Sr=e=>({content:[{type:"text",text:e}]}),Tr="This agent was removed from Mailcycle, so its key has been deleted from this machine. Run `npx -y mailcycle-mcp pair` to connect it again.";function Er(e){return r=>async t=>{try{return Sr(await r(t))}catch(o){let n=o instanceof S?`${o.message} (${o.code})`:o.message;return _(o)&&(await M(e).catch(()=>!1),n=Tr),{content:[{type:"text",text:n}],isError:!0}}}}function Br(e){let r=e.trim();if(!(!r||/[\s<>]/.test(r.replace(/^<|>$/g,""))))return r.startsWith("<")?r:`<${r}>`}function Cr(e){let r=new B(e),t=Er(e.credential),o=new vr({name:"mailcycle",version:"0.2.1"});return o.registerTool("list_addresses",{title:"List email addresses",description:"This agent's email addresses, and what it is allowed to send.",inputSchema:{},annotations:{readOnlyHint:!0}},t(async()=>{let{worker:n,inboxes:a}=await r.self(!0),i=await r.senderName();return["Addresses:",...a.length?a.map(c=>`- ${c.emailAddress}${c.pausedAt?" (paused: the account has a missed payment)":""}`):["(none yet: give this agent an address in the Mailcycle app, under AI agents)"],"",Ur[n.sendMode]??"",i?`Mail is sent as "${i}".`:"Mail is sent as the address alone. A sender name can be set in the app."].join(`
|
|
20
20
|
`)})),o.registerTool("list_messages",{title:"List messages",description:"The newest messages, newest first, with a short preview of each. Use read_message for the full text.",inputSchema:{address:p.string().optional().describe("Only this address. Leave out for all of them."),limit:p.number().int().min(1).max(100).default(20)},annotations:{readOnlyHint:!0}},t(async({address:n,limit:a})=>{let i=n?(await r.inbox(n)).id:void 0,{messages:s}=await r.api.messages({limit:a,...i?{inboxId:i}:{}});return s.length===0?"No messages.":(await r.decrypt(s)).map($e).join(`
|
|
21
|
-
`)})),o.registerTool("read_message",{title:"Read a message",description:"One message in full.",inputSchema:{message_id:p.string().describe("The id from list_messages or wait_for_message, like msg_\u2026")},annotations:{readOnlyHint:!0}},t(async({message_id:n})=>fe(await Pe(r,n)))),o.registerTool("wait_for_message",{title:"Wait for a message",description:"Waits for a new message to arrive and returns it in full. Use it right after signing up somewhere to catch a verification code or link. Only mail that arrives after the call starts counts, unless after_message_id is given.",inputSchema:{address:p.string().optional().describe("Only mail to this address."),from_contains:p.string().optional().describe('Only mail whose sender contains this, like "github.com".'),subject_contains:p.string().optional().describe("Only mail whose subject contains this."),timeout_seconds:p.number().int().min(5).max(600).default(120),after_message_id:p.string().optional().describe("Count mail after this message instead of from now.")},annotations:{readOnlyHint:!0}},t(async n=>{let a=n.address?(await r.inbox(n.address)).id:void 0,i=a?{inboxId:a}:{},s=l=>(!n.from_contains||`${l.fromName} ${l.from} ${l.replyTo}`.toLowerCase().includes(n.from_contains.toLowerCase()))&&(!n.subject_contains||l.subject.toLowerCase().includes(n.subject_contains.toLowerCase())),c;if(n.after_message_id)c={after:n.after_message_id};else{let{messages:l}=await r.api.messages({limit:1,...i});c=l[0]?{after:l[0].id}:{since:"1970-01-01T00:00:00.000Z"}}let m=Date.now()+n.timeout_seconds*1e3;for(;Date.now()<m;){let l=Math.max(1,Math.min(25,Math.floor((m-Date.now())/1e3))),u=await r.api.messages({...c,...i,wait:l,limit:50});u.nextCursor&&(c={after:u.nextCursor});let g=(await r.decrypt(u.messages)).find(s);if(g)return fe(g)}return`Nothing matching arrived in ${n.timeout_seconds} seconds.`})),o.registerTool("reply",{title:"Reply to a message",description:"Replies to the sender of a message, from the address it was sent to, threaded under it. Works in reply-only mode.",inputSchema:{message_id:p.string(),text:p.string().min(1).describe("The reply, as plain text."),html:p.string().optional().describe("An HTML version, if wanted. The plain text is always sent too.")},annotations:{destructiveHint:!1,openWorldHint:!0}},t(async({message_id:n,text:a,html:i})=>{let s=await Pe(r,n);if(!s.replyTo)throw new Error("That message has no address to reply to.");let c=Br(s.messageId),m=await r.senderName();return await r.api.send({from:s.to,to:s.replyTo,subject:/^re:/i.test(s.subject)?s.subject:`Re: ${s.subject}`,text:a,...i?{html:i}:{},inReplyTo:s.id,...c?{inReplyToHeader:c}:{},...m?{fromName:m}:{}}),`Sent to ${s.replyTo} from ${s.to}.`})),o.registerTool("send_message",{title:"Send a message",description:"Sends a new message. Needs the agent to be allowed to send to anyone; in reply-only mode use reply instead.",inputSchema:{to:p.string().email(),subject:p.string().min(1).max(998),text:p.string().min(1),html:p.string().optional(),from:p.string().optional().describe("One of this agent's addresses. Can be left out if it has only one.")},annotations:{destructiveHint:!1,openWorldHint:!0}},t(async n=>{let a=(await r.inbox(n.from)).emailAddress,i=await r.senderName();return await r.api.send({from:a,...i?{fromName:i}:{},to:n.to,subject:n.subject,text:n.text,...n.html?{html:n.html}:{}}),`Sent to ${n.to} from ${a}.`})),o}async function Pe(e,r){let{messages:t}=await e.api.messages({id:r,limit:1});if(!t[0])throw new Error(`No message ${r} on this agent's addresses.`);let[o]=await e.decrypt(t);return o}async function Ie(e){let r=Cr(e),t=new B(e),o=
|
|
22
|
-
`):" No addresses yet."),console.log(`Key file: ${C()}`);return}e&&e!=="serve"&&(console.error(`Unknown command ${e}. Use pair, status, or nothing to run the server.`),process.exit(2)),await Ie(t)}
|
|
21
|
+
`)})),o.registerTool("read_message",{title:"Read a message",description:"One message in full.",inputSchema:{message_id:p.string().describe("The id from list_messages or wait_for_message, like msg_\u2026")},annotations:{readOnlyHint:!0}},t(async({message_id:n})=>fe(await Pe(r,n)))),o.registerTool("wait_for_message",{title:"Wait for a message",description:"Waits for a new message to arrive and returns it in full. Use it right after signing up somewhere to catch a verification code or link. Only mail that arrives after the call starts counts, unless after_message_id is given.",inputSchema:{address:p.string().optional().describe("Only mail to this address."),from_contains:p.string().optional().describe('Only mail whose sender contains this, like "github.com".'),subject_contains:p.string().optional().describe("Only mail whose subject contains this."),timeout_seconds:p.number().int().min(5).max(600).default(120),after_message_id:p.string().optional().describe("Count mail after this message instead of from now.")},annotations:{readOnlyHint:!0}},t(async n=>{let a=n.address?(await r.inbox(n.address)).id:void 0,i=a?{inboxId:a}:{},s=l=>(!n.from_contains||`${l.fromName} ${l.from} ${l.replyTo}`.toLowerCase().includes(n.from_contains.toLowerCase()))&&(!n.subject_contains||l.subject.toLowerCase().includes(n.subject_contains.toLowerCase())),c;if(n.after_message_id)c={after:n.after_message_id};else{let{messages:l}=await r.api.messages({limit:1,...i});c=l[0]?{after:l[0].id}:{since:"1970-01-01T00:00:00.000Z"}}let m=Date.now()+n.timeout_seconds*1e3;for(;Date.now()<m;){let l=Math.max(1,Math.min(25,Math.floor((m-Date.now())/1e3))),u=await r.api.messages({...c,...i,wait:l,limit:50});u.nextCursor&&(c={after:u.nextCursor});let g=(await r.decrypt(u.messages)).find(s);if(g)return fe(g)}return`Nothing matching arrived in ${n.timeout_seconds} seconds.`})),o.registerTool("reply",{title:"Reply to a message",description:"Replies to the sender of a message, from the address it was sent to, threaded under it. Works in reply-only mode.",inputSchema:{message_id:p.string(),text:p.string().min(1).describe("The reply, as plain text."),html:p.string().optional().describe("An HTML version, if wanted. The plain text is always sent too.")},annotations:{destructiveHint:!1,openWorldHint:!0}},t(async({message_id:n,text:a,html:i})=>{let s=await Pe(r,n);if(!s.replyTo)throw new Error("That message has no address to reply to.");let c=Br(s.messageId),m=await r.senderName();return await r.api.send({from:s.to,to:s.replyTo,subject:/^re:/i.test(s.subject)?s.subject:`Re: ${s.subject}`,text:a,...i?{html:i}:{},inReplyTo:s.id,...c?{inReplyToHeader:c}:{},...m?{fromName:m}:{}}),`Sent to ${s.replyTo} from ${s.to}.`})),o.registerTool("send_message",{title:"Send a message",description:"Sends a new message. Needs the agent to be allowed to send to anyone; in reply-only mode use reply instead.",inputSchema:{to:p.string().email(),subject:p.string().min(1).max(998),text:p.string().min(1),html:p.string().optional(),from:p.string().optional().describe("One of this agent's addresses. Can be left out if it has only one.")},annotations:{destructiveHint:!1,openWorldHint:!0}},t(async n=>{let a=(await r.inbox(n.from)).emailAddress,i=await r.senderName();return await r.api.send({from:a,...i?{fromName:i}:{},to:n.to,subject:n.subject,text:n.text,...n.html?{html:n.html}:{}}),`Sent to ${n.to} from ${a}.`})),o}async function Pe(e,r){let{messages:t}=await e.api.messages({id:r,limit:1});if(!t[0])throw new Error(`No message ${r} on this agent's addresses.`);let[o]=await e.decrypt(t);return o}var _r=5*6e4;async function Ie(e){let r=Cr(e),t=new B(e),o=()=>void t.api.heartbeat().catch(()=>{});o(),setInterval(o,_r).unref(),await r.connect(new kr)}function Rr(e,r){let t=e.indexOf(r);return t>=0?e[t+1]:void 0}async function $r(){let[e,...r]=process.argv.slice(2);if(e==="pair"){let o=Rr(r,"--name");await je({...o?{name:o}:{},force:r.includes("--force")});return}let t=await Y();if(!t?.credential)throw new H;if(e==="status"){let o=await new B(t).self(!0).catch(async i=>{throw _(i)?(await M(t.credential),new Error("This agent was removed from Mailcycle, so its key has been deleted. Run `npx -y mailcycle-mcp pair` to connect again.")):i}),{worker:n,inboxes:a}=o;console.log(`Agent ${n.id}, ${n.status}, send mode ${n.sendMode}.`),console.log(a.length?a.map(i=>` ${i.emailAddress}`).join(`
|
|
22
|
+
`):" No addresses yet."),console.log(`Key file: ${C()}`);return}e&&e!=="serve"&&(console.error(`Unknown command ${e}. Use pair, status, or nothing to run the server.`),process.exit(2)),await Ie(t)}$r().catch(e=>{console.error(e.message),process.exit(1)});
|
package/package.json
CHANGED