@sleep2agi/agent-network 2.3.0-preview.8 → 2.3.0-preview.9

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.
@@ -1 +1 @@
1
- function a0_0x1a4b(_0x5ed33c,_0x30db5b){_0x5ed33c=_0x5ed33c-0x1af;const _0x540cb8=a0_0x540c();let _0x1a4b8b=_0x540cb8[_0x5ed33c];return _0x1a4b8b;}function a0_0x540c(){const _0x3398ef=['token','application/json,\x20text/event-stream','url','3914220FIWCCn','send','/mcp','reply','normal','startsWith','sleep','11863380WleNBg','call','disconnected','task','autoConnect','content','heartbeatTimer','reconnectDelay','1545160KwkaFo','155352EoYLMU','resumeId','registered','slice','6095826qgqwrY','now','completed','toString','getReader','1593675CrzaxG','SSE\x20connected','Authorization','running','sseAbort','log','356WNFEnM','match','name','/events/','heartbeatInterval','processInbox','send_reply','abort','pop','message','offline','connect','AbortError','new_message','4924LlUXBE','text','2.0','emit','report_status','broadcast','sdk','type','status','min','error','get_all_status','Bearer\x20','cwd','sdk-','read','idle','connected','catch','agent','connectSSE','4lWDeOd','alias','parse','new_task','231oYXYZH','application/json','SSE\x20reconnecting\x20in\x20','text/event-stream','result','signal','stringify'];a0_0x540c=function(){return _0x3398ef;};return a0_0x540c();}const a0_0x999825=a0_0x1a4b;(function(_0x4c66d1,_0x418324){const _0x1d1d05=a0_0x1a4b,_0xd91cc0=_0x4c66d1();while(!![]){try{const _0x1f6b79=-parseInt(_0x1d1d05(0x1db))/0x1*(parseInt(_0x1d1d05(0x1cd))/0x2)+parseInt(_0x1d1d05(0x1c7))/0x3+-parseInt(_0x1d1d05(0x1f0))/0x4*(-parseInt(_0x1d1d05(0x1bd))/0x5)+parseInt(_0x1d1d05(0x1fe))/0x6+parseInt(_0x1d1d05(0x1f4))/0x7*(-parseInt(_0x1d1d05(0x1be))/0x8)+-parseInt(_0x1d1d05(0x1c2))/0x9+parseInt(_0x1d1d05(0x1b5))/0xa;if(_0x1f6b79===_0x418324)break;else _0xd91cc0['push'](_0xd91cc0['shift']());}catch(_0x32d0bb){_0xd91cc0['push'](_0xd91cc0['shift']());}}}(a0_0x540c,0x76400));import{EventEmitter as a0_0x5183e4}from'events';import{hostname as a0_0x40be42}from'os';class T extends a0_0x5183e4{[a0_0x999825(0x1fd)];[a0_0x999825(0x1f1)];['token'];[a0_0x999825(0x1ee)];[a0_0x999825(0x1bf)];[a0_0x999825(0x1d1)];[a0_0x999825(0x1bc)];[a0_0x999825(0x1bb)];[a0_0x999825(0x1cb)];[a0_0x999825(0x1ca)]=!0x1;constructor(_0x4f27da){const _0xac7ce3=a0_0x999825;super();if(this[_0xac7ce3(0x1fd)]=_0x4f27da[_0xac7ce3(0x1fd)]['replace'](/\/$/,''),this[_0xac7ce3(0x1f1)]=_0x4f27da['alias'],this['token']=_0x4f27da[_0xac7ce3(0x1fb)],this[_0xac7ce3(0x1ee)]=_0x4f27da[_0xac7ce3(0x1ee)]||_0xac7ce3(0x1e1),this[_0xac7ce3(0x1bf)]=_0xac7ce3(0x1e9)+_0x4f27da['alias']+'-'+Date[_0xac7ce3(0x1c3)]()[_0xac7ce3(0x1c5)](0x24),this[_0xac7ce3(0x1d1)]=_0x4f27da[_0xac7ce3(0x1d1)]??0x2bf20,this[_0xac7ce3(0x1bc)]=_0x4f27da[_0xac7ce3(0x1bc)]??0xbb8,_0x4f27da[_0xac7ce3(0x1b9)]!==!0x1)this[_0xac7ce3(0x1d8)]();}[a0_0x999825(0x1cc)](_0x9d2f4){const _0x25f00c=a0_0x999825;console[_0x25f00c(0x1cc)]('['+new Date()['toTimeString']()[_0x25f00c(0x1c1)](0x0,0x8)+']\x20[commhub:'+this[_0x25f00c(0x1f1)]+']\x20'+_0x9d2f4);}async[a0_0x999825(0x1b6)](_0x2d02b7,_0x5e23f1){const _0x582642=a0_0x999825;let _0x1f8b3d={'Content-Type':_0x582642(0x1f5),'Accept':_0x582642(0x1fc)};if(this[_0x582642(0x1fb)])_0x1f8b3d[_0x582642(0x1c9)]=_0x582642(0x1e7)+this[_0x582642(0x1fb)];let _0x13e135=await(await fetch(this[_0x582642(0x1fd)]+_0x582642(0x1b0),{'method':'POST','headers':_0x1f8b3d,'body':JSON[_0x582642(0x1fa)]({'jsonrpc':_0x582642(0x1dd),'id':Date[_0x582642(0x1c3)](),'method':'tools/call','params':{'name':_0x2d02b7,'arguments':_0x5e23f1}})}))[_0x582642(0x1dc)](),_0x38ecf4=_0x13e135[_0x582642(0x1ce)](/data: (.+)/),_0x23767f=_0x38ecf4?JSON[_0x582642(0x1f2)](_0x38ecf4[0x1]):JSON[_0x582642(0x1f2)](_0x13e135),_0x56f3dc=_0x23767f?.[_0x582642(0x1f8)]?.[_0x582642(0x1ba)]?.[0x0]?.['text'];return _0x56f3dc?JSON[_0x582642(0x1f2)](_0x56f3dc):_0x23767f;}async[a0_0x999825(0x1d8)](){const _0x183084=a0_0x999825;if(this[_0x183084(0x1ca)])return;this[_0x183084(0x1ca)]=!0x0,await this[_0x183084(0x1e3)](_0x183084(0x1eb)),this['log'](_0x183084(0x1c0)),this['heartbeatTimer']=setInterval(()=>{const _0x153a01=_0x183084;this[_0x153a01(0x1e3)](_0x153a01(0x1eb))['catch'](_0xf3a729=>this[_0x153a01(0x1cc)]('heartbeat\x20failed:\x20'+_0xf3a729[_0x153a01(0x1d6)]));},this[_0x183084(0x1d1)]),this[_0x183084(0x1ef)]();}async['disconnect'](){const _0x3cdf0b=a0_0x999825;if(this['running']=!0x1,this[_0x3cdf0b(0x1cb)]?.[_0x3cdf0b(0x1d4)](),this[_0x3cdf0b(0x1bb)])clearInterval(this[_0x3cdf0b(0x1bb)]);await this['status'](_0x3cdf0b(0x1d7))[_0x3cdf0b(0x1ed)](()=>{}),this['log'](_0x3cdf0b(0x1b7));}async[a0_0x999825(0x1af)](_0x3f7ba0,_0x566f3b,_0x3da99c=a0_0x999825(0x1b2)){const _0x241cdf=a0_0x999825;return this[_0x241cdf(0x1b6)]('send_task',{'alias':_0x3f7ba0,'task':_0x566f3b,'priority':_0x3da99c,'from_session':this[_0x241cdf(0x1f1)]});}async['message'](_0x13f328,_0x254f4e){const _0x1d713b=a0_0x999825;return this[_0x1d713b(0x1b6)]('send_message',{'alias':_0x13f328,'message':_0x254f4e,'from_session':this[_0x1d713b(0x1f1)]});}async[a0_0x999825(0x1b1)](_0xe7466a,_0x478922,_0x2f203e=a0_0x999825(0x1c4)){const _0x21f4a5=a0_0x999825;return this[_0x21f4a5(0x1b6)](_0x21f4a5(0x1d3),{'in_reply_to':_0xe7466a,'text':_0x478922,'status':_0x2f203e});}async['status'](_0x5c6444,_0x5095b1){const _0x449cc6=a0_0x999825;return this[_0x449cc6(0x1b6)](_0x449cc6(0x1df),{'resume_id':this[_0x449cc6(0x1bf)],'alias':this[_0x449cc6(0x1f1)],'status':_0x5c6444,'server':a0_0x40be42(),'hostname':a0_0x40be42(),'agent':this[_0x449cc6(0x1ee)],'project_dir':process[_0x449cc6(0x1e8)](),..._0x5095b1});}async['getAllStatus'](){const _0x1f1762=a0_0x999825;return this[_0x1f1762(0x1b6)](_0x1f1762(0x1e6),{});}async[a0_0x999825(0x1e0)](_0x581001,_0x5c146d){const _0x229538=a0_0x999825;return this['call'](_0x229538(0x1e0),{'message':_0x581001,'filter_server':_0x5c146d?.['server'],'filter_status':_0x5c146d?.[_0x229538(0x1e3)]});}async[a0_0x999825(0x1ef)](){const _0x468c96=a0_0x999825;let _0x243ca8=encodeURIComponent(this['alias']),_0x13ba31=this[_0x468c96(0x1fd)]+_0x468c96(0x1d0)+_0x243ca8,_0x320db5=this[_0x468c96(0x1bc)];while(this[_0x468c96(0x1ca)]){try{this['sseAbort']=new AbortController();let _0x5c46cb={'Accept':_0x468c96(0x1f7)};if(this['token'])_0x5c46cb[_0x468c96(0x1c9)]=_0x468c96(0x1e7)+this[_0x468c96(0x1fb)];let _0x2a4087=await fetch(_0x13ba31,{'headers':_0x5c46cb,'signal':this[_0x468c96(0x1cb)][_0x468c96(0x1f9)]});if(!_0x2a4087['ok']||!_0x2a4087['body']){this['log']('SSE\x20failed:\x20'+_0x2a4087[_0x468c96(0x1e3)]),await this[_0x468c96(0x1b4)](_0x320db5),_0x320db5=Math[_0x468c96(0x1e4)](_0x320db5*1.5,0xea60);continue;}_0x320db5=this[_0x468c96(0x1bc)];let _0x24dc80=_0x2a4087['body'][_0x468c96(0x1c6)](),_0x2e483c=new TextDecoder(),_0x1c1ce3='';while(this[_0x468c96(0x1ca)]){let {done:_0x20fc68,value:_0x1314c0}=await _0x24dc80[_0x468c96(0x1ea)]();if(_0x20fc68)break;_0x1c1ce3+=_0x2e483c['decode'](_0x1314c0,{'stream':!0x0});let _0x45d15e=_0x1c1ce3['split']('\x0a');_0x1c1ce3=_0x45d15e[_0x468c96(0x1d5)]()||'';for(let _0x234929 of _0x45d15e){if(!_0x234929[_0x468c96(0x1b3)]('data:\x20'))continue;try{let _0x37ea62=JSON[_0x468c96(0x1f2)](_0x234929[_0x468c96(0x1c1)](0x6));if(_0x37ea62[_0x468c96(0x1e2)]===_0x468c96(0x1ec)){this['log'](_0x468c96(0x1c8)),this[_0x468c96(0x1de)](_0x468c96(0x1ec));continue;}if(_0x37ea62['type']===_0x468c96(0x1f3)||_0x37ea62[_0x468c96(0x1e2)]===_0x468c96(0x1da)||_0x37ea62[_0x468c96(0x1e2)]==='broadcast')await this[_0x468c96(0x1d2)]();}catch{}}}}catch(_0x26936b){if(_0x26936b[_0x468c96(0x1cf)]===_0x468c96(0x1d9))break;this[_0x468c96(0x1de)](_0x468c96(0x1e5),_0x26936b),this[_0x468c96(0x1cc)]('SSE\x20error:\x20'+_0x26936b[_0x468c96(0x1d6)]);}if(this[_0x468c96(0x1ca)])this[_0x468c96(0x1de)](_0x468c96(0x1b7)),this[_0x468c96(0x1cc)](_0x468c96(0x1f6)+_0x320db5/0x3e8+'s...'),await this['sleep'](_0x320db5),_0x320db5=Math[_0x468c96(0x1e4)](_0x320db5*1.5,0xea60);}}async[a0_0x999825(0x1d2)](){const _0x578893=a0_0x999825;try{let _0x2392a8=(await this['call']('get_inbox',{'alias':this['alias'],'limit':0xa}))?.['messages']||[];for(let _0x4474fc of _0x2392a8)await this[_0x578893(0x1b6)]('ack_inbox',{'alias':this[_0x578893(0x1f1)],'message_id':_0x4474fc['id']}),this[_0x578893(0x1cc)]('←\x20'+_0x4474fc['from_session']+':\x20'+_0x4474fc[_0x578893(0x1ba)]['slice'](0x0,0x3c)),this[_0x578893(0x1de)](_0x578893(0x1b8),_0x4474fc),this['emit'](_0x578893(0x1d6),_0x4474fc);}catch(_0x1c4649){this[_0x578893(0x1cc)]('inbox\x20error:\x20'+_0x1c4649['message']);}}['sleep'](_0x5b8686){return new Promise(_0x304075=>setTimeout(_0x304075,_0x5b8686));}}var $=T;export{$ as default,T as CommHub};
1
+ const a0_0x5920d3=a0_0x16ff;(function(_0x2ba291,_0x1e2095){const _0x4ffd6f=a0_0x16ff,_0x24cf74=_0x2ba291();while(!![]){try{const _0x494620=parseInt(_0x4ffd6f(0x210))/0x1*(parseInt(_0x4ffd6f(0x206))/0x2)+-parseInt(_0x4ffd6f(0x22d))/0x3+parseInt(_0x4ffd6f(0x1e6))/0x4*(-parseInt(_0x4ffd6f(0x21e))/0x5)+parseInt(_0x4ffd6f(0x220))/0x6*(parseInt(_0x4ffd6f(0x22c))/0x7)+-parseInt(_0x4ffd6f(0x215))/0x8*(-parseInt(_0x4ffd6f(0x1d8))/0x9)+-parseInt(_0x4ffd6f(0x20f))/0xa*(-parseInt(_0x4ffd6f(0x20b))/0xb)+-parseInt(_0x4ffd6f(0x20e))/0xc;if(_0x494620===_0x1e2095)break;else _0x24cf74['push'](_0x24cf74['shift']());}catch(_0x1fb59b){_0x24cf74['push'](_0x24cf74['shift']());}}}(a0_0x1d84,0x5cc6a));function a0_0x16ff(_0x2bd2c0,_0x1bf401){_0x2bd2c0=_0x2bd2c0-0x1d8;const _0x1d84fe=a0_0x1d84();let _0x16ff51=_0x1d84fe[_0x2bd2c0];return _0x16ff51;}import{EventEmitter as a0_0x302ef1}from'events';function a0_0x1d84(){const _0x4a5a59=['application/json,\x20text/event-stream','alias','705krKHwc','get_all_status','351228KPOtwm','s...','match','token','broadcast','url','call','SSE\x20reconnecting\x20in\x20','POST','tools/call','text/event-stream','signal','28SICtSD','140412SGeGSj','disconnected','send_task','connected','read','531JsuzXG','disconnect','toTimeString','heartbeatInterval','report_status','inbox\x20error:\x20','data:\x20','/mcp','stringify','slice','sdk','processInbox','now','normal','10936cbUyUZ','offline','min','getReader','cwd','parse','catch','Bearer\x20','registered','message','SSE\x20error:\x20','status','toString','resumeId','content','connect','new_task','from_session','log','new_message','send_reply','getAllStatus','messages','AbortError','autoConnect','sseAbort','connectSSE','text','sleep','type','startsWith','/events/','8anUVCl','emit','agent','completed','send_message','11YGRDNc','Authorization','reconnectDelay','8968332JGzJBc','4836790IREQic','184529cLDiAv','split','heartbeatTimer','name','send','14064aPspDd','body','running','2.0','idle','decode','sdk-'];a0_0x1d84=function(){return _0x4a5a59;};return a0_0x1d84();}import{hostname as a0_0x2755ad}from'os';class T extends a0_0x302ef1{['url'];[a0_0x5920d3(0x21d)];['token'];[a0_0x5920d3(0x208)];[a0_0x5920d3(0x1f3)];['heartbeatInterval'];[a0_0x5920d3(0x20d)];[a0_0x5920d3(0x212)];[a0_0x5920d3(0x1ff)];['running']=!0x1;constructor(_0x5f2f64){const _0x12a96f=a0_0x5920d3;super();if(this[_0x12a96f(0x225)]=_0x5f2f64[_0x12a96f(0x225)]['replace'](/\/$/,''),this[_0x12a96f(0x21d)]=_0x5f2f64[_0x12a96f(0x21d)],this[_0x12a96f(0x223)]=_0x5f2f64[_0x12a96f(0x223)],this[_0x12a96f(0x208)]=_0x5f2f64['agent']||_0x12a96f(0x1e2),this[_0x12a96f(0x1f3)]=_0x12a96f(0x21b)+_0x5f2f64[_0x12a96f(0x21d)]+'-'+Date[_0x12a96f(0x1e4)]()[_0x12a96f(0x1f2)](0x24),this[_0x12a96f(0x1db)]=_0x5f2f64['heartbeatInterval']??0x2bf20,this[_0x12a96f(0x20d)]=_0x5f2f64[_0x12a96f(0x20d)]??0xbb8,_0x5f2f64[_0x12a96f(0x1fe)]!==!0x1)this['connect']();}[a0_0x5920d3(0x1f8)](_0x1c820b){const _0x51a463=a0_0x5920d3;console[_0x51a463(0x1f8)]('['+new Date()[_0x51a463(0x1da)]()[_0x51a463(0x1e1)](0x0,0x8)+']\x20[commhub:'+this['alias']+']\x20'+_0x1c820b);}async[a0_0x5920d3(0x226)](_0x510e92,_0x16eb96){const _0xde81c6=a0_0x5920d3;let _0x29b431={'Content-Type':'application/json','Accept':_0xde81c6(0x21c)};if(this[_0xde81c6(0x223)])_0x29b431[_0xde81c6(0x20c)]=_0xde81c6(0x1ed)+this[_0xde81c6(0x223)];let _0x362ba8=await(await fetch(this[_0xde81c6(0x225)]+_0xde81c6(0x1df),{'method':_0xde81c6(0x228),'headers':_0x29b431,'body':JSON[_0xde81c6(0x1e0)]({'jsonrpc':_0xde81c6(0x218),'id':Date[_0xde81c6(0x1e4)](),'method':_0xde81c6(0x229),'params':{'name':_0x510e92,'arguments':_0x16eb96}})}))[_0xde81c6(0x201)](),_0x2e5516=_0x362ba8[_0xde81c6(0x222)](/data: (.+)/),_0x3d67c1=_0x2e5516?JSON[_0xde81c6(0x1eb)](_0x2e5516[0x1]):JSON['parse'](_0x362ba8),_0x2607c=_0x3d67c1?.['result']?.[_0xde81c6(0x1f4)]?.[0x0]?.[_0xde81c6(0x201)];return _0x2607c?JSON[_0xde81c6(0x1eb)](_0x2607c):_0x3d67c1;}async[a0_0x5920d3(0x1f5)](){const _0x3747bf=a0_0x5920d3;if(this[_0x3747bf(0x217)])return;this[_0x3747bf(0x217)]=!0x0,await this['status'](_0x3747bf(0x219)),this[_0x3747bf(0x1f8)](_0x3747bf(0x1ee)),this['heartbeatTimer']=setInterval(()=>{const _0xd4119b=_0x3747bf;this[_0xd4119b(0x1f1)](_0xd4119b(0x219))[_0xd4119b(0x1ec)](_0x19410a=>this[_0xd4119b(0x1f8)]('heartbeat\x20failed:\x20'+_0x19410a[_0xd4119b(0x1ef)]));},this[_0x3747bf(0x1db)]),this['connectSSE']();}async[a0_0x5920d3(0x1d9)](){const _0x3b0abc=a0_0x5920d3;if(this[_0x3b0abc(0x217)]=!0x1,this[_0x3b0abc(0x1ff)]?.['abort'](),this[_0x3b0abc(0x212)])clearInterval(this[_0x3b0abc(0x212)]);await this[_0x3b0abc(0x1f1)](_0x3b0abc(0x1e7))[_0x3b0abc(0x1ec)](()=>{}),this[_0x3b0abc(0x1f8)](_0x3b0abc(0x22e));}async[a0_0x5920d3(0x214)](_0x172e8d,_0x4ee915,_0x520465=a0_0x5920d3(0x1e5)){const _0x496136=a0_0x5920d3;return this[_0x496136(0x226)](_0x496136(0x22f),{'alias':_0x172e8d,'task':_0x4ee915,'priority':_0x520465,'from_session':this[_0x496136(0x21d)]});}async[a0_0x5920d3(0x1ef)](_0x5dd07a,_0x1d1ce3){const _0x5f1bab=a0_0x5920d3;return this[_0x5f1bab(0x226)](_0x5f1bab(0x20a),{'alias':_0x5dd07a,'message':_0x1d1ce3,'from_session':this['alias']});}async['reply'](_0x12a01c,_0x87fda4,_0x466014=a0_0x5920d3(0x209)){const _0x2d5f9a=a0_0x5920d3;return this[_0x2d5f9a(0x226)](_0x2d5f9a(0x1fa),{'in_reply_to':_0x12a01c,'text':_0x87fda4,'status':_0x466014});}async[a0_0x5920d3(0x1f1)](_0x26fef4,_0xd4c06c){const _0x120180=a0_0x5920d3;return this[_0x120180(0x226)](_0x120180(0x1dc),{'resume_id':this[_0x120180(0x1f3)],'alias':this[_0x120180(0x21d)],'status':_0x26fef4,'server':a0_0x2755ad(),'hostname':a0_0x2755ad(),'agent':this[_0x120180(0x208)],'project_dir':process[_0x120180(0x1ea)](),..._0xd4c06c});}async[a0_0x5920d3(0x1fb)](){const _0x1d9c4e=a0_0x5920d3;return this[_0x1d9c4e(0x226)](_0x1d9c4e(0x21f),{});}async[a0_0x5920d3(0x224)](_0x58200f,_0x22c77d){const _0x50a4ec=a0_0x5920d3;return this[_0x50a4ec(0x226)](_0x50a4ec(0x224),{'message':_0x58200f,'filter_server':_0x22c77d?.['server'],'filter_status':_0x22c77d?.[_0x50a4ec(0x1f1)]});}async[a0_0x5920d3(0x200)](){const _0x47cb57=a0_0x5920d3;let _0x560cc2=encodeURIComponent(this['alias']),_0x4841a1=this[_0x47cb57(0x225)]+_0x47cb57(0x205)+_0x560cc2,_0x12cd58=this[_0x47cb57(0x20d)];while(this[_0x47cb57(0x217)]){try{this[_0x47cb57(0x1ff)]=new AbortController();let _0x35d2c6={'Accept':_0x47cb57(0x22a)};if(this[_0x47cb57(0x223)])_0x35d2c6['Authorization']=_0x47cb57(0x1ed)+this[_0x47cb57(0x223)];let _0x34a2cc=await fetch(_0x4841a1,{'headers':_0x35d2c6,'signal':this[_0x47cb57(0x1ff)][_0x47cb57(0x22b)]});if(!_0x34a2cc['ok']||!_0x34a2cc[_0x47cb57(0x216)]){this['log']('SSE\x20failed:\x20'+_0x34a2cc['status']),await this[_0x47cb57(0x202)](_0x12cd58),_0x12cd58=Math['min'](_0x12cd58*1.5,0xea60);continue;}_0x12cd58=this[_0x47cb57(0x20d)];let _0x54d9bc=_0x34a2cc['body'][_0x47cb57(0x1e9)](),_0x44e986=new TextDecoder(),_0x214d83='';while(this[_0x47cb57(0x217)]){let {done:_0x3256bd,value:_0x33943a}=await _0x54d9bc[_0x47cb57(0x231)]();if(_0x3256bd)break;_0x214d83+=_0x44e986[_0x47cb57(0x21a)](_0x33943a,{'stream':!0x0});let _0x5eac3f=_0x214d83[_0x47cb57(0x211)]('\x0a');_0x214d83=_0x5eac3f['pop']()||'';for(let _0x1dc067 of _0x5eac3f){if(!_0x1dc067[_0x47cb57(0x204)](_0x47cb57(0x1de)))continue;try{let _0x8c8d76=JSON[_0x47cb57(0x1eb)](_0x1dc067[_0x47cb57(0x1e1)](0x6));if(_0x8c8d76[_0x47cb57(0x203)]==='connected'){this[_0x47cb57(0x1f8)]('SSE\x20connected'),this[_0x47cb57(0x207)](_0x47cb57(0x230));continue;}if(_0x8c8d76[_0x47cb57(0x203)]===_0x47cb57(0x1f6)||_0x8c8d76[_0x47cb57(0x203)]===_0x47cb57(0x1f9)||_0x8c8d76[_0x47cb57(0x203)]===_0x47cb57(0x224))await this[_0x47cb57(0x1e3)]();}catch{}}}}catch(_0x169a25){if(_0x169a25[_0x47cb57(0x213)]===_0x47cb57(0x1fd))break;this[_0x47cb57(0x207)]('error',_0x169a25),this[_0x47cb57(0x1f8)](_0x47cb57(0x1f0)+_0x169a25[_0x47cb57(0x1ef)]);}if(this[_0x47cb57(0x217)])this[_0x47cb57(0x207)](_0x47cb57(0x22e)),this[_0x47cb57(0x1f8)](_0x47cb57(0x227)+_0x12cd58/0x3e8+_0x47cb57(0x221)),await this['sleep'](_0x12cd58),_0x12cd58=Math[_0x47cb57(0x1e8)](_0x12cd58*1.5,0xea60);}}async['processInbox'](){const _0x60277b=a0_0x5920d3;try{let _0x30d1eb=(await this[_0x60277b(0x226)]('get_inbox',{'alias':this[_0x60277b(0x21d)],'limit':0xa}))?.[_0x60277b(0x1fc)]||[];for(let _0x8a5294 of _0x30d1eb)await this[_0x60277b(0x226)]('ack_inbox',{'alias':this[_0x60277b(0x21d)],'message_id':_0x8a5294['id']}),this[_0x60277b(0x1f8)]('←\x20'+_0x8a5294[_0x60277b(0x1f7)]+':\x20'+_0x8a5294[_0x60277b(0x1f4)][_0x60277b(0x1e1)](0x0,0x3c)),this[_0x60277b(0x207)]('task',_0x8a5294),this[_0x60277b(0x207)](_0x60277b(0x1ef),_0x8a5294);}catch(_0x1597fe){this[_0x60277b(0x1f8)](_0x60277b(0x1dd)+_0x1597fe['message']);}}[a0_0x5920d3(0x202)](_0x11d201){return new Promise(_0x3186f5=>setTimeout(_0x3186f5,_0x11d201));}}var $=T;export{$ as default,T as CommHub};
@@ -4,7 +4,7 @@ export declare class FeishuAdapter implements IMAdapter {
4
4
  readonly platform = "feishu";
5
5
  readonly ingressMode: IMIngressMode;
6
6
  private feishuConfig;
7
- private connectionName;
7
+ private connectionName_;
8
8
  private client;
9
9
  private wsClient;
10
10
  /**
@@ -28,6 +28,12 @@ export declare class FeishuAdapter implements IMAdapter {
28
28
  * the public-channel shape and still needs flood protection.
29
29
  */
30
30
  getAllowFrom(): readonly string[];
31
+ /**
32
+ * Read-only accessor used by bridge to resolve per-connection paths
33
+ * (RFC-020 §15 outbound-marker validation needs the connection name
34
+ * to build the allowed per-conversation directory prefix).
35
+ */
36
+ get connectionName(): string;
31
37
  init(config: IMChannelConfig): Promise<void>;
32
38
  start(onEvent: OnEventHandler): Promise<void>;
33
39
  stop(): Promise<void>;
@@ -0,0 +1,135 @@
1
+ /**
2
+ * RFC-020 §15 — agent→bridge outbound file protocol.
3
+ *
4
+ * 2026-06-29 Vincent UAT: agent generated a PDF via reportlab + wrote it
5
+ * to `/work/feishu-attachments/<conv>/x.pdf`, then in text asked Vincent
6
+ * "I'm not sure if the system will auto-attach this — try another way?"
7
+ * The bridge has `adapter.send({files})` since #329, but no protocol
8
+ * told the agent how to signal "dispatch this file to the user".
9
+ *
10
+ * Convention: in its final reply, the agent emits one
11
+ *
12
+ * [[send-file:/abs/path]]
13
+ *
14
+ * marker per file (one per line, end of reply). The bridge:
15
+ *
16
+ * 1. extracts every `[[send-file:...]]` token,
17
+ * 2. strips them from the user-visible text,
18
+ * 3. validates each path against an allowed-outbound-root whitelist
19
+ * (`/work/feishu-attachments/<conn>/<chat>/` — same per-conversation
20
+ * directory the LLM has Write access to under Layer B),
21
+ * 4. checks the file exists, is non-empty, and ≤ 30 MB (Feishu file_v1
22
+ * upper bound),
23
+ * 5. magic-byte sniffs to choose `image_key` vs `file_key` upload route,
24
+ * 6. dispatches each file via `adapter.send({files:[...]})`,
25
+ * 7. emits a friendly fallback if validation fails — never the raw error.
26
+ *
27
+ * Pure module — no I/O, no IM SDK calls. The parser returns the cleaned
28
+ * text + a structured list of file requests; bridge.ts is responsible
29
+ * for filesystem checks and dispatching.
30
+ */
31
+ /**
32
+ * One outbound-file request parsed from an agent reply.
33
+ *
34
+ * - `raw`: the bytes between `[[send-file:` and `]]`, before any
35
+ * normalization. Kept for stderr forensic.
36
+ * - `normalized`: lexical-normalized absolute path (quote-strip, `..`
37
+ * collapse, `//` collapse, `./` resolution against cwd). The
38
+ * `validatedAbsolute` field is set later by the bridge after the
39
+ * realpath / whitelist / exists check.
40
+ */
41
+ export interface OutboundFileRequest {
42
+ raw: string;
43
+ normalized: string;
44
+ }
45
+ export interface MarkerParseResult {
46
+ /** Reply text with all `[[send-file:...]]` markers removed + adjacent
47
+ * whitespace collapsed. May be empty (file-only reply). */
48
+ cleanedText: string;
49
+ /** Files in source order. Caller-side validation happens after. */
50
+ files: OutboundFileRequest[];
51
+ }
52
+ /**
53
+ * Lexically normalize a path token from the marker. NOT a full
54
+ * symlink/realpath resolver — bridge does that after this returns.
55
+ *
56
+ * - Trim leading / trailing whitespace.
57
+ * - Strip one layer of matching quotes (`"/x"` / `'/x'` → `/x`).
58
+ * - `.` and `..` segments collapse via `path.posix.normalize`.
59
+ * - Repeated `/` collapse.
60
+ *
61
+ * Returns an absolute path or the empty string if the input cannot be
62
+ * interpreted as an absolute path token (caller drops empties).
63
+ */
64
+ export declare function normalizeMarkerPath(raw: string): string;
65
+ /**
66
+ * Parse an agent reply into cleaned text + outbound-file requests.
67
+ *
68
+ * Empty / null input returns `{cleanedText: "", files: []}` so callers
69
+ * can safely pipe through without defensive checks.
70
+ *
71
+ * Marker-only reply (no surrounding text) returns `cleanedText: ""` —
72
+ * caller should NOT send an empty text message in that case; they only
73
+ * dispatch the files.
74
+ *
75
+ * Multiple markers on one reply are all captured. Adjacent whitespace
76
+ * around stripped markers is collapsed (no double blank lines).
77
+ */
78
+ export declare function parseOutboundMarkers(reply: string | null | undefined): MarkerParseResult;
79
+ /**
80
+ * The single allowed outbound root for files the agent wants to send.
81
+ * Each conversation gets its own subdirectory under this root; the
82
+ * agent's Write permission on this tree is granted by Layer B (config
83
+ * paths like `access.json` / `config.json` are denied, attachments
84
+ * dir is allowed).
85
+ *
86
+ * `<conv>` is the open_chat_id (group) or open_id (DM). Bridge fills
87
+ * the placeholder per-event when validating.
88
+ */
89
+ export declare const OUTBOUND_ROOT = "/work/feishu-attachments";
90
+ /**
91
+ * Validate a normalized absolute path against the per-conversation
92
+ * whitelist + size + existence checks. Returns null on success or a
93
+ * Chinese user-friendly reason on failure (the same string can be
94
+ * surfaced as a fallback text reply when ALL files fail validation).
95
+ *
96
+ * Filesystem-touching — bridge calls this AFTER `parseOutboundMarkers`.
97
+ *
98
+ * Params:
99
+ * - p: normalized absolute path candidate
100
+ * - convKey: per-conversation directory name (open_chat_id / open_id)
101
+ * - statFn: optional override for tests (defaults to fs.statSync)
102
+ * - realpathFn: optional override for tests (defaults to fs.realpathSync)
103
+ *
104
+ * Note: `convKey` may include characters Feishu accepts but are unusual
105
+ * for file paths (open_id starts with `ou_`, open_chat_id with `oc_`).
106
+ * The whitelist check uses the literal substring + path.posix.dirname
107
+ * walk so symlink redirects don't bypass it — the realpath form must
108
+ * also fall under `OUTBOUND_ROOT/<connection>/<convKey>/`.
109
+ */
110
+ export interface ValidateOpts {
111
+ p: string;
112
+ convKey: string;
113
+ connectionName: string;
114
+ statFn?: (p: string) => {
115
+ size: number;
116
+ };
117
+ realpathFn?: (p: string) => string;
118
+ }
119
+ export declare function validateOutboundPath(opts: ValidateOpts): string | null;
120
+ /**
121
+ * Magic-byte sniffer — picks `image` vs `file` upload route. Reads the
122
+ * first 16 bytes only; safe to call before commitment. Returns:
123
+ *
124
+ * - "image" when the bytes are a PNG / JPG / GIF / WebP / BMP signature
125
+ * (Feishu image_v1 supports these natively, with chat inline render).
126
+ * - "file" otherwise (PDF, TXT, audio, video, archive, …).
127
+ *
128
+ * Caller supplies a Buffer (bridge reads via fs.openSync + readSync).
129
+ */
130
+ export declare function sniffFileKind(buf: Buffer): "image" | "file";
131
+ /**
132
+ * User-facing fallback message when ALL marker validations fail and the
133
+ * stripped text is empty (would leave the user with no reply at all).
134
+ */
135
+ export declare const ALL_FILES_FAILED_FALLBACK = "[\u6587\u4EF6\u9644\u4EF6\u53D1\u9001\u5931\u8D25] \u6211\u51C6\u5907\u597D\u4E86\u6587\u4EF6\u4F46\u5206\u53D1\u65F6\u51FA\u4E86\u95EE\u9898\u2014\u2014\u7A0D\u540E\u518D\u8BD5\u6216\u6362\u79CD\u65B9\u5F0F\u3002";