@sleep2agi/agent-network 2.3.0-preview.15 → 2.3.0-preview.16

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
- const a0_0x57f1ff=a0_0x101e;function a0_0x101e(_0x54fed8,_0x2dad15){_0x54fed8=_0x54fed8-0x1f2;const _0x748cb4=a0_0x748c();let _0x101e72=_0x748cb4[_0x54fed8];return _0x101e72;}(function(_0x3d6ecb,_0x4654e8){const _0x2f9768=a0_0x101e,_0x565f3a=_0x3d6ecb();while(!![]){try{const _0x5d10f4=-parseInt(_0x2f9768(0x236))/0x1+parseInt(_0x2f9768(0x212))/0x2+-parseInt(_0x2f9768(0x221))/0x3+parseInt(_0x2f9768(0x1f8))/0x4+parseInt(_0x2f9768(0x203))/0x5+parseInt(_0x2f9768(0x219))/0x6+parseInt(_0x2f9768(0x237))/0x7;if(_0x5d10f4===_0x4654e8)break;else _0x565f3a['push'](_0x565f3a['shift']());}catch(_0x17c87d){_0x565f3a['push'](_0x565f3a['shift']());}}}(a0_0x748c,0xe5fe4));import{EventEmitter as a0_0x364783}from'events';import{hostname as a0_0x257b58}from'os';class T extends a0_0x364783{[a0_0x57f1ff(0x22e)];[a0_0x57f1ff(0x201)];[a0_0x57f1ff(0x20d)];['agent'];[a0_0x57f1ff(0x21b)];[a0_0x57f1ff(0x213)];[a0_0x57f1ff(0x231)];[a0_0x57f1ff(0x1f9)];[a0_0x57f1ff(0x1fa)];[a0_0x57f1ff(0x20b)]=!0x1;constructor(_0x7e9fc6){const _0xd27749=a0_0x57f1ff;super();if(this['url']=_0x7e9fc6['url'][_0xd27749(0x244)](/\/$/,''),this[_0xd27749(0x201)]=_0x7e9fc6[_0xd27749(0x201)],this[_0xd27749(0x20d)]=_0x7e9fc6['token'],this['agent']=_0x7e9fc6[_0xd27749(0x21d)]||_0xd27749(0x248),this[_0xd27749(0x21b)]=_0xd27749(0x1fc)+_0x7e9fc6[_0xd27749(0x201)]+'-'+Date['now']()[_0xd27749(0x218)](0x24),this['heartbeatInterval']=_0x7e9fc6[_0xd27749(0x213)]??0x2bf20,this[_0xd27749(0x231)]=_0x7e9fc6[_0xd27749(0x231)]??0xbb8,_0x7e9fc6[_0xd27749(0x23b)]!==!0x1)this['connect']();}['log'](_0x4b3a02){const _0x82dcbb=a0_0x57f1ff;console[_0x82dcbb(0x22f)]('['+new Date()[_0x82dcbb(0x20f)]()[_0x82dcbb(0x1f6)](0x0,0x8)+']\x20[commhub:'+this['alias']+']\x20'+_0x4b3a02);}async['call'](_0x317f8b,_0x4ea8d6){const _0x3d188e=a0_0x57f1ff;let _0x5a1afd={'Content-Type':'application/json','Accept':'application/json,\x20text/event-stream'};if(this['token'])_0x5a1afd['Authorization']='Bearer\x20'+this[_0x3d188e(0x20d)];let _0x153bee=await(await fetch(this[_0x3d188e(0x22e)]+_0x3d188e(0x1f5),{'method':_0x3d188e(0x228),'headers':_0x5a1afd,'body':JSON[_0x3d188e(0x22b)]({'jsonrpc':_0x3d188e(0x210),'id':Date[_0x3d188e(0x245)](),'method':'tools/call','params':{'name':_0x317f8b,'arguments':_0x4ea8d6}})}))[_0x3d188e(0x239)](),_0x30b6ca=_0x153bee[_0x3d188e(0x247)](/data: (.+)/),_0xf47e6f=_0x30b6ca?JSON['parse'](_0x30b6ca[0x1]):JSON[_0x3d188e(0x214)](_0x153bee),_0x362790=_0xf47e6f?.[_0x3d188e(0x21a)]?.[_0x3d188e(0x216)]?.[0x0]?.[_0x3d188e(0x239)];return _0x362790?JSON[_0x3d188e(0x214)](_0x362790):_0xf47e6f;}async[a0_0x57f1ff(0x232)](){const _0x2b9a59=a0_0x57f1ff;if(this[_0x2b9a59(0x20b)])return;this['running']=!0x0,await this['status'](_0x2b9a59(0x21f)),this['log'](_0x2b9a59(0x22a)),this[_0x2b9a59(0x1f9)]=setInterval(()=>{const _0x3fdc0b=_0x2b9a59;this[_0x3fdc0b(0x23c)](_0x3fdc0b(0x21f))[_0x3fdc0b(0x211)](_0x399825=>this[_0x3fdc0b(0x22f)]('heartbeat\x20failed:\x20'+_0x399825[_0x3fdc0b(0x200)]));},this['heartbeatInterval']),this[_0x2b9a59(0x1fd)]();}async['disconnect'](){const _0x44a6d0=a0_0x57f1ff;if(this[_0x44a6d0(0x20b)]=!0x1,this[_0x44a6d0(0x1fa)]?.[_0x44a6d0(0x204)](),this[_0x44a6d0(0x1f9)])clearInterval(this[_0x44a6d0(0x1f9)]);await this[_0x44a6d0(0x23c)](_0x44a6d0(0x1f7))['catch'](()=>{}),this[_0x44a6d0(0x22f)](_0x44a6d0(0x206));}async[a0_0x57f1ff(0x22d)](_0x3858c9,_0x4ed4d8,_0x294b99=a0_0x57f1ff(0x233)){const _0x589252=a0_0x57f1ff;return this[_0x589252(0x23f)]('send_task',{'alias':_0x3858c9,'task':_0x4ed4d8,'priority':_0x294b99,'from_session':this[_0x589252(0x201)]});}async[a0_0x57f1ff(0x200)](_0x539fd7,_0x176a28){const _0x88635=a0_0x57f1ff;return this[_0x88635(0x23f)](_0x88635(0x20e),{'alias':_0x539fd7,'message':_0x176a28,'from_session':this[_0x88635(0x201)]});}async[a0_0x57f1ff(0x217)](_0x2d9386,_0x415560,_0x425cd6=a0_0x57f1ff(0x220)){const _0x3132ee=a0_0x57f1ff;return this[_0x3132ee(0x23f)](_0x3132ee(0x1ff),{'in_reply_to':_0x2d9386,'text':_0x415560,'status':_0x425cd6});}async[a0_0x57f1ff(0x23c)](_0x28243d,_0x7e6cf2){const _0x443c45=a0_0x57f1ff;return this[_0x443c45(0x23f)](_0x443c45(0x240),{'resume_id':this['resumeId'],'alias':this['alias'],'status':_0x28243d,'server':a0_0x257b58(),'hostname':a0_0x257b58(),'agent':this[_0x443c45(0x21d)],'project_dir':process['cwd'](),..._0x7e6cf2});}async['getAllStatus'](){const _0x20a559=a0_0x57f1ff;return this[_0x20a559(0x23f)]('get_all_status',{});}async[a0_0x57f1ff(0x225)](_0x307972,_0x21c6ce){const _0x3f35ec=a0_0x57f1ff;return this[_0x3f35ec(0x23f)](_0x3f35ec(0x225),{'message':_0x307972,'filter_server':_0x21c6ce?.[_0x3f35ec(0x208)],'filter_status':_0x21c6ce?.[_0x3f35ec(0x23c)]});}async[a0_0x57f1ff(0x1fd)](){const _0x2536bc=a0_0x57f1ff;let _0x2901c9=encodeURIComponent(this[_0x2536bc(0x201)]),_0x1cad20=this[_0x2536bc(0x22e)]+'/events/'+_0x2901c9,_0x3c4ca0=this[_0x2536bc(0x231)];while(this['running']){try{this[_0x2536bc(0x1fa)]=new AbortController();let _0x5f0c75={'Accept':_0x2536bc(0x23e)};if(this[_0x2536bc(0x20d)])_0x5f0c75['Authorization']=_0x2536bc(0x202)+this['token'];let _0xa6ae1f=await fetch(_0x1cad20,{'headers':_0x5f0c75,'signal':this[_0x2536bc(0x1fa)][_0x2536bc(0x241)]});if(!_0xa6ae1f['ok']||!_0xa6ae1f[_0x2536bc(0x227)]){this[_0x2536bc(0x22f)](_0x2536bc(0x1fb)+_0xa6ae1f[_0x2536bc(0x23c)]),await this['sleep'](_0x3c4ca0),_0x3c4ca0=Math[_0x2536bc(0x23a)](_0x3c4ca0*1.5,0xea60);continue;}_0x3c4ca0=this[_0x2536bc(0x231)];let _0x15d782=_0xa6ae1f['body'][_0x2536bc(0x205)](),_0x3b2994=new TextDecoder(),_0x5719cd='';while(this[_0x2536bc(0x20b)]){let {done:_0x61e56a,value:_0x46bff0}=await _0x15d782['read']();if(_0x61e56a)break;_0x5719cd+=_0x3b2994[_0x2536bc(0x230)](_0x46bff0,{'stream':!0x0});let _0xef2cec=_0x5719cd[_0x2536bc(0x226)]('\x0a');_0x5719cd=_0xef2cec[_0x2536bc(0x1fe)]()||'';for(let _0x3b7359 of _0xef2cec){if(!_0x3b7359[_0x2536bc(0x224)](_0x2536bc(0x222)))continue;try{let _0x165e54=JSON[_0x2536bc(0x214)](_0x3b7359[_0x2536bc(0x1f6)](0x6));if(_0x165e54[_0x2536bc(0x234)]===_0x2536bc(0x22c)){this[_0x2536bc(0x22f)](_0x2536bc(0x1f3)),this[_0x2536bc(0x1f4)]('connected');continue;}if(_0x165e54['type']===_0x2536bc(0x235)||_0x165e54[_0x2536bc(0x234)]===_0x2536bc(0x20c)||_0x165e54[_0x2536bc(0x234)]===_0x2536bc(0x225))await this[_0x2536bc(0x207)]();}catch{}}}}catch(_0x269680){if(_0x269680[_0x2536bc(0x229)]===_0x2536bc(0x215))break;this[_0x2536bc(0x1f4)](_0x2536bc(0x23d),_0x269680),this[_0x2536bc(0x22f)](_0x2536bc(0x238)+_0x269680[_0x2536bc(0x200)]);}if(this[_0x2536bc(0x20b)])this['emit'](_0x2536bc(0x206)),this['log'](_0x2536bc(0x21c)+_0x3c4ca0/0x3e8+_0x2536bc(0x209)),await this['sleep'](_0x3c4ca0),_0x3c4ca0=Math[_0x2536bc(0x23a)](_0x3c4ca0*1.5,0xea60);}}async[a0_0x57f1ff(0x207)](){const _0x248cc7=a0_0x57f1ff;try{let _0x12827d=(await this['call'](_0x248cc7(0x20a),{'alias':this[_0x248cc7(0x201)],'limit':0xa}))?.[_0x248cc7(0x242)]||[];for(let _0x2cc4c9 of _0x12827d)await this[_0x248cc7(0x23f)](_0x248cc7(0x243),{'alias':this[_0x248cc7(0x201)],'message_id':_0x2cc4c9['id']}),this[_0x248cc7(0x22f)]('←\x20'+_0x2cc4c9[_0x248cc7(0x1f2)]+':\x20'+_0x2cc4c9[_0x248cc7(0x216)][_0x248cc7(0x1f6)](0x0,0x3c)),this[_0x248cc7(0x1f4)](_0x248cc7(0x21e),_0x2cc4c9),this[_0x248cc7(0x1f4)](_0x248cc7(0x200),_0x2cc4c9);}catch(_0x2d0577){this[_0x248cc7(0x22f)](_0x248cc7(0x246)+_0x2d0577['message']);}}[a0_0x57f1ff(0x223)](_0x1f3f87){return new Promise(_0xf1fa84=>setTimeout(_0xf1fa84,_0x1f3f87));}}var $=T;function a0_0x748c(){const _0xe4972d=['autoConnect','status','error','text/event-stream','call','report_status','signal','messages','ack_inbox','replace','now','inbox\x20error:\x20','match','sdk','from_session','SSE\x20connected','emit','/mcp','slice','offline','5667020RNCYmH','heartbeatTimer','sseAbort','SSE\x20failed:\x20','sdk-','connectSSE','pop','send_reply','message','alias','Bearer\x20','1455210fYJmFf','abort','getReader','disconnected','processInbox','server','s...','get_inbox','running','new_message','token','send_message','toTimeString','2.0','catch','749774OjJRIK','heartbeatInterval','parse','AbortError','content','reply','toString','1412286bwWKGN','result','resumeId','SSE\x20reconnecting\x20in\x20','agent','task','idle','completed','4672041vjJjbT','data:\x20','sleep','startsWith','broadcast','split','body','POST','name','registered','stringify','connected','send','url','log','decode','reconnectDelay','connect','normal','type','new_task','358874HzVAkD','3781456xzcCLB','SSE\x20error:\x20','text','min'];a0_0x748c=function(){return _0xe4972d;};return a0_0x748c();}export{$ as default,T as CommHub};
1
+ function a0_0x3a8a(_0xbf97b2,_0x1b0d8b){_0xbf97b2=_0xbf97b2-0xcc;const _0x1ead6b=a0_0x1ead();let _0x3a8a84=_0x1ead6b[_0xbf97b2];return _0x3a8a84;}const a0_0x5aa207=a0_0x3a8a;(function(_0xd6e14f,_0x212c4a){const _0x2d861c=a0_0x3a8a,_0x33513c=_0xd6e14f();while(!![]){try{const _0x25926b=-parseInt(_0x2d861c(0xfe))/0x1*(-parseInt(_0x2d861c(0x10c))/0x2)+parseInt(_0x2d861c(0xcc))/0x3+-parseInt(_0x2d861c(0xd2))/0x4+parseInt(_0x2d861c(0xf1))/0x5+-parseInt(_0x2d861c(0x101))/0x6+parseInt(_0x2d861c(0xd7))/0x7+parseInt(_0x2d861c(0xf8))/0x8*(-parseInt(_0x2d861c(0x11b))/0x9);if(_0x25926b===_0x212c4a)break;else _0x33513c['push'](_0x33513c['shift']());}catch(_0x177805){_0x33513c['push'](_0x33513c['shift']());}}}(a0_0x1ead,0xc6cad));function a0_0x1ead(){const _0x2627eb=['now','send_reply','inbox\x20error:\x20','token','error','data:\x20','application/json','task','read','body','reply','type','getReader','completed','sseAbort','disconnected','sdk-','toString','text','7438645HSevlt','match','status','/events/','log','application/json,\x20text/event-stream','message','8JSJtRn','Authorization','reconnectDelay','heartbeat\x20failed:\x20','heartbeatTimer','Bearer\x20','221077ssreUs','idle','sdk','1867512LPzeik','sleep','tools/call','new_message','connect','replace','url','alias','resumeId','content','messages','14GwWeVF','call','parse','SSE\x20error:\x20','autoConnect','result','min','getAllStatus','stringify','split','connectSSE','disconnect','broadcast','catch','POST','37381941xaArGT','name','decode','running','abort','3374694yHCTbU','connected','emit',']\x20[commhub:','2.0','startsWith','1593356MtueIW','send_task','new_task','get_all_status','text/event-stream','10620589IiTBss','heartbeatInterval','agent','from_session','registered','send','processInbox'];a0_0x1ead=function(){return _0x2627eb;};return a0_0x1ead();}import{EventEmitter as a0_0x91c43c}from'events';import{hostname as a0_0x6b38b3}from'os';class T extends a0_0x91c43c{[a0_0x5aa207(0x107)];['alias'];['token'];[a0_0x5aa207(0xd9)];[a0_0x5aa207(0x109)];[a0_0x5aa207(0xd8)];[a0_0x5aa207(0xfa)];['heartbeatTimer'];[a0_0x5aa207(0xec)];[a0_0x5aa207(0x11e)]=!0x1;constructor(_0x47ad2f){const _0x5595b9=a0_0x5aa207;super();if(this[_0x5595b9(0x107)]=_0x47ad2f[_0x5595b9(0x107)][_0x5595b9(0x106)](/\/$/,''),this['alias']=_0x47ad2f[_0x5595b9(0x108)],this['token']=_0x47ad2f['token'],this[_0x5595b9(0xd9)]=_0x47ad2f[_0x5595b9(0xd9)]||_0x5595b9(0x100),this[_0x5595b9(0x109)]=_0x5595b9(0xee)+_0x47ad2f[_0x5595b9(0x108)]+'-'+Date['now']()[_0x5595b9(0xef)](0x24),this[_0x5595b9(0xd8)]=_0x47ad2f[_0x5595b9(0xd8)]??0x2bf20,this[_0x5595b9(0xfa)]=_0x47ad2f[_0x5595b9(0xfa)]??0xbb8,_0x47ad2f[_0x5595b9(0x110)]!==!0x1)this[_0x5595b9(0x105)]();}[a0_0x5aa207(0xf5)](_0x5fdeb3){const _0x2d8ca9=a0_0x5aa207;console[_0x2d8ca9(0xf5)]('['+new Date()['toTimeString']()['slice'](0x0,0x8)+_0x2d8ca9(0xcf)+this[_0x2d8ca9(0x108)]+']\x20'+_0x5fdeb3);}async[a0_0x5aa207(0x10d)](_0x45979e,_0x67f4c2){const _0x16d5cf=a0_0x5aa207;let _0x374bc2={'Content-Type':_0x16d5cf(0xe4),'Accept':_0x16d5cf(0xf6)};if(this[_0x16d5cf(0xe1)])_0x374bc2[_0x16d5cf(0xf9)]=_0x16d5cf(0xfd)+this[_0x16d5cf(0xe1)];let _0x22adec=await(await fetch(this['url']+'/mcp',{'method':_0x16d5cf(0x11a),'headers':_0x374bc2,'body':JSON[_0x16d5cf(0x114)]({'jsonrpc':_0x16d5cf(0xd0),'id':Date[_0x16d5cf(0xde)](),'method':_0x16d5cf(0x103),'params':{'name':_0x45979e,'arguments':_0x67f4c2}})}))[_0x16d5cf(0xf0)](),_0x3347e1=_0x22adec[_0x16d5cf(0xf2)](/data: (.+)/),_0xdefda1=_0x3347e1?JSON[_0x16d5cf(0x10e)](_0x3347e1[0x1]):JSON[_0x16d5cf(0x10e)](_0x22adec),_0x3a1676=_0xdefda1?.[_0x16d5cf(0x111)]?.[_0x16d5cf(0x10a)]?.[0x0]?.[_0x16d5cf(0xf0)];return _0x3a1676?JSON['parse'](_0x3a1676):_0xdefda1;}async[a0_0x5aa207(0x105)](){const _0x5f85e5=a0_0x5aa207;if(this[_0x5f85e5(0x11e)])return;this[_0x5f85e5(0x11e)]=!0x0,await this[_0x5f85e5(0xf3)]('idle'),this[_0x5f85e5(0xf5)](_0x5f85e5(0xdb)),this[_0x5f85e5(0xfc)]=setInterval(()=>{const _0x5eb5ea=_0x5f85e5;this[_0x5eb5ea(0xf3)](_0x5eb5ea(0xff))[_0x5eb5ea(0x119)](_0x13203a=>this['log'](_0x5eb5ea(0xfb)+_0x13203a[_0x5eb5ea(0xf7)]));},this[_0x5f85e5(0xd8)]),this[_0x5f85e5(0x116)]();}async[a0_0x5aa207(0x117)](){const _0x49f25e=a0_0x5aa207;if(this[_0x49f25e(0x11e)]=!0x1,this[_0x49f25e(0xec)]?.[_0x49f25e(0x11f)](),this[_0x49f25e(0xfc)])clearInterval(this['heartbeatTimer']);await this[_0x49f25e(0xf3)]('offline')[_0x49f25e(0x119)](()=>{}),this['log'](_0x49f25e(0xed));}async[a0_0x5aa207(0xdc)](_0x4d1e04,_0x422be9,_0x33f24d='normal'){const _0x58ff90=a0_0x5aa207;return this[_0x58ff90(0x10d)](_0x58ff90(0xd3),{'alias':_0x4d1e04,'task':_0x422be9,'priority':_0x33f24d,'from_session':this[_0x58ff90(0x108)]});}async[a0_0x5aa207(0xf7)](_0x2de477,_0x3fd06a){const _0x5cc294=a0_0x5aa207;return this[_0x5cc294(0x10d)]('send_message',{'alias':_0x2de477,'message':_0x3fd06a,'from_session':this[_0x5cc294(0x108)]});}async[a0_0x5aa207(0xe8)](_0x3b3fed,_0x184d4b,_0x4848ea=a0_0x5aa207(0xeb)){const _0x14bcfc=a0_0x5aa207;return this[_0x14bcfc(0x10d)](_0x14bcfc(0xdf),{'in_reply_to':_0x3b3fed,'text':_0x184d4b,'status':_0x4848ea});}async[a0_0x5aa207(0xf3)](_0x930c31,_0x51a838){const _0x519971=a0_0x5aa207;return this['call']('report_status',{'resume_id':this[_0x519971(0x109)],'alias':this[_0x519971(0x108)],'status':_0x930c31,'server':a0_0x6b38b3(),'hostname':a0_0x6b38b3(),'agent':this[_0x519971(0xd9)],'project_dir':process['cwd'](),..._0x51a838});}async[a0_0x5aa207(0x113)](){const _0x68d16f=a0_0x5aa207;return this[_0x68d16f(0x10d)](_0x68d16f(0xd5),{});}async[a0_0x5aa207(0x118)](_0xe805e0,_0x2e4b2e){const _0x1911cc=a0_0x5aa207;return this[_0x1911cc(0x10d)](_0x1911cc(0x118),{'message':_0xe805e0,'filter_server':_0x2e4b2e?.['server'],'filter_status':_0x2e4b2e?.[_0x1911cc(0xf3)]});}async[a0_0x5aa207(0x116)](){const _0x34f5e5=a0_0x5aa207;let _0x44fca8=encodeURIComponent(this['alias']),_0x376b8f=this[_0x34f5e5(0x107)]+_0x34f5e5(0xf4)+_0x44fca8,_0x15a433=this[_0x34f5e5(0xfa)];while(this[_0x34f5e5(0x11e)]){try{this[_0x34f5e5(0xec)]=new AbortController();let _0x8d52a9={'Accept':_0x34f5e5(0xd6)};if(this[_0x34f5e5(0xe1)])_0x8d52a9['Authorization']=_0x34f5e5(0xfd)+this[_0x34f5e5(0xe1)];let _0xf1718=await fetch(_0x376b8f,{'headers':_0x8d52a9,'signal':this[_0x34f5e5(0xec)]['signal']});if(!_0xf1718['ok']||!_0xf1718[_0x34f5e5(0xe7)]){this[_0x34f5e5(0xf5)]('SSE\x20failed:\x20'+_0xf1718[_0x34f5e5(0xf3)]),await this[_0x34f5e5(0x102)](_0x15a433),_0x15a433=Math[_0x34f5e5(0x112)](_0x15a433*1.5,0xea60);continue;}_0x15a433=this[_0x34f5e5(0xfa)];let _0x2fc049=_0xf1718[_0x34f5e5(0xe7)][_0x34f5e5(0xea)](),_0x3d6c41=new TextDecoder(),_0x3d7d38='';while(this[_0x34f5e5(0x11e)]){let {done:_0x4c9277,value:_0x1cf8ca}=await _0x2fc049[_0x34f5e5(0xe6)]();if(_0x4c9277)break;_0x3d7d38+=_0x3d6c41[_0x34f5e5(0x11d)](_0x1cf8ca,{'stream':!0x0});let _0x1b850d=_0x3d7d38[_0x34f5e5(0x115)]('\x0a');_0x3d7d38=_0x1b850d['pop']()||'';for(let _0x25a619 of _0x1b850d){if(!_0x25a619[_0x34f5e5(0xd1)](_0x34f5e5(0xe3)))continue;try{let _0x3ba9fb=JSON[_0x34f5e5(0x10e)](_0x25a619['slice'](0x6));if(_0x3ba9fb[_0x34f5e5(0xe9)]===_0x34f5e5(0xcd)){this['log']('SSE\x20connected'),this[_0x34f5e5(0xce)](_0x34f5e5(0xcd));continue;}if(_0x3ba9fb[_0x34f5e5(0xe9)]===_0x34f5e5(0xd4)||_0x3ba9fb[_0x34f5e5(0xe9)]===_0x34f5e5(0x104)||_0x3ba9fb[_0x34f5e5(0xe9)]===_0x34f5e5(0x118))await this[_0x34f5e5(0xdd)]();}catch{}}}}catch(_0x198ae9){if(_0x198ae9[_0x34f5e5(0x11c)]==='AbortError')break;this[_0x34f5e5(0xce)](_0x34f5e5(0xe2),_0x198ae9),this[_0x34f5e5(0xf5)](_0x34f5e5(0x10f)+_0x198ae9['message']);}if(this[_0x34f5e5(0x11e)])this[_0x34f5e5(0xce)](_0x34f5e5(0xed)),this[_0x34f5e5(0xf5)]('SSE\x20reconnecting\x20in\x20'+_0x15a433/0x3e8+'s...'),await this[_0x34f5e5(0x102)](_0x15a433),_0x15a433=Math[_0x34f5e5(0x112)](_0x15a433*1.5,0xea60);}}async[a0_0x5aa207(0xdd)](){const _0x3d456e=a0_0x5aa207;try{let _0x12d9d9=(await this['call']('get_inbox',{'alias':this[_0x3d456e(0x108)],'limit':0xa}))?.[_0x3d456e(0x10b)]||[];for(let _0x297550 of _0x12d9d9)await this[_0x3d456e(0x10d)]('ack_inbox',{'alias':this[_0x3d456e(0x108)],'message_id':_0x297550['id']}),this['log']('←\x20'+_0x297550[_0x3d456e(0xda)]+':\x20'+_0x297550[_0x3d456e(0x10a)]['slice'](0x0,0x3c)),this['emit'](_0x3d456e(0xe5),_0x297550),this['emit']('message',_0x297550);}catch(_0x4476fa){this[_0x3d456e(0xf5)](_0x3d456e(0xe0)+_0x4476fa['message']);}}[a0_0x5aa207(0x102)](_0x3443b1){return new Promise(_0x5e965d=>setTimeout(_0x5e965d,_0x3443b1));}}var $=T;export{$ as default,T as CommHub};
@@ -0,0 +1,88 @@
1
+ /**
2
+ * RFC-020 §17 — feishu inbound bridge → hub `/api/upload` integration.
3
+ *
4
+ * Vincent 2026-06-30: cross-machine agents (e.g. TM门户运维@toodadev2)
5
+ * delegated by the feishu-local bot can't read inbound attachments
6
+ * because the only thing they get is a host-local path that doesn't
7
+ * exist on the receiver's filesystem. #351 already wired agent-node's
8
+ * receiver to prefer `file_id` and pull via `GET /api/files/<id>` when
9
+ * present. This module is the SENDER half: the feishu bridge uploads
10
+ * each downloaded inbound file to the hub via `POST /api/upload`,
11
+ * gets back a `file_id`, and propagates it alongside the local path.
12
+ *
13
+ * Failure mode (load-bearing): every failure path returns `null` and
14
+ * the caller falls back to path-only. The bridge MUST NOT crash because
15
+ * the hub is down / overloaded / refused a 12 MiB cap. Single-host
16
+ * `agent-node` Read still works on the local path; only cross-host
17
+ * delegation degrades, no regression vs the pre-fix baseline.
18
+ *
19
+ * Concurrency cap: a single feishu message can carry many images; bursts
20
+ * to /api/upload would hammer the hub rate limit (60/hour per token).
21
+ * `uploadFilesToHubConcurrent` caps in-flight requests at `concurrency`
22
+ * (default 4) so a 20-image message takes 5 sequential rounds instead
23
+ * of 20 simultaneous open sockets + a likely rate-limit denial.
24
+ */
25
+ /**
26
+ * Hub upload limit, mirrors `server/src/uploads.ts:MAX_UPLOAD_BYTES`.
27
+ * Anything bigger is skipped at the bridge — the hub would 413 anyway.
28
+ */
29
+ export declare const HUB_UPLOAD_LIMIT_BYTES: number;
30
+ /** Default in-flight cap for `uploadFilesToHubConcurrent`. */
31
+ export declare const DEFAULT_UPLOAD_CONCURRENCY = 4;
32
+ /**
33
+ * One file uploaded to the hub. `mime` and `size` are from the local
34
+ * filesystem read; `file_id` and `path` come from the hub's response.
35
+ *
36
+ * `file_id` is the canonical cross-machine handle — receiving agent
37
+ * resolves to bytes via `GET /api/files/<file_id>`. `path` is the
38
+ * hub-machine-local absolute path the hub stored to; on the sender
39
+ * side it's purely informational (we already have the source file).
40
+ */
41
+ export interface HubUploadResult {
42
+ file_id: string;
43
+ path?: string;
44
+ mime?: string;
45
+ size?: number;
46
+ name?: string;
47
+ }
48
+ export interface HubUploadOpts {
49
+ /** Hub base URL, no trailing slash. Defaults to env. */
50
+ hubUrl: string;
51
+ /** Bearer token (ntok_ / utok_ / atok_). Defaults to env. */
52
+ authToken: string;
53
+ /** Optional MIME hint; sniffed by filename ext otherwise. */
54
+ mime?: string;
55
+ /** Optional override filename (defaults to basename(path)). */
56
+ name?: string;
57
+ /** Injectable for tests. Defaults to global fetch. */
58
+ fetch?: typeof fetch;
59
+ }
60
+ /**
61
+ * Upload one local file to `${hubUrl}/api/upload`. Returns the file
62
+ * descriptor on success, or `null` on any failure (caller falls back
63
+ * to path-only).
64
+ *
65
+ * - File must exist + be ≤ 12 MiB. Larger → skipped silently with
66
+ * a stderr warn; caller gets `null` and ships path-only.
67
+ * - Auth via `Authorization: Bearer <token>`.
68
+ * - `Content-Length` header is set by `fetch` when given a Blob body;
69
+ * the hub validates it before consuming bytes.
70
+ * - Multipart body with a single `file` field. The hub server
71
+ * reads `form.get("file")` and stores under a new file_id.
72
+ * - Any network error / non-2xx / malformed JSON response → null.
73
+ */
74
+ export declare function uploadToHub(filePath: string, opts: HubUploadOpts): Promise<HubUploadResult | null>;
75
+ /**
76
+ * Upload many files to the hub with a bounded concurrency window.
77
+ * Returns one result per input path, preserving order. A failed
78
+ * upload appears as `null` at that slot — caller composes path-only
79
+ * descriptors for those.
80
+ *
81
+ * Why this matters: one feishu post can carry an arbitrary number of
82
+ * images. Naive `Promise.all(paths.map(uploadToHub))` would open N
83
+ * simultaneous HTTPS sockets to the hub AND blow past the 60/hour
84
+ * per-token rate limit on a single message with >60 images. A
85
+ * concurrency cap of 4 means N/4 sequential rounds, predictable
86
+ * load, no head-of-line blocking on the agent's reply.
87
+ */
88
+ export declare function uploadFilesToHubConcurrent(filePaths: string[], opts: HubUploadOpts, concurrency?: number): Promise<(HubUploadResult | null)[]>;