@sleep2agi/agent-network 2.3.0-preview.207 → 2.3.0-preview.208

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_0x1e1d45=a0_0x2a3c;(function(_0x9ce942,_0x4d2a27){const _0xab0a6a=a0_0x2a3c,_0x7340c4=_0x9ce942();while(!![]){try{const _0x2c8b35=parseInt(_0xab0a6a(0x1f2))/0x1*(-parseInt(_0xab0a6a(0x206))/0x2)+-parseInt(_0xab0a6a(0x1dc))/0x3+parseInt(_0xab0a6a(0x207))/0x4+-parseInt(_0xab0a6a(0x222))/0x5+parseInt(_0xab0a6a(0x1f5))/0x6+parseInt(_0xab0a6a(0x1eb))/0x7+parseInt(_0xab0a6a(0x240))/0x8;if(_0x2c8b35===_0x4d2a27)break;else _0x7340c4['push'](_0x7340c4['shift']());}catch(_0xcf62ba){_0x7340c4['push'](_0x7340c4['shift']());}}}(a0_0x59ac,0x82aca));import{EventEmitter as a0_0x300e63}from'events';import{hostname as a0_0x1bf6d8}from'os';var K=/(?:atok|ntok|utok|ghp|github_pat)_[A-Za-z0-9_-]+|Bearer\s+\S+/gi,L=(_0x320d12,_0x34205b)=>(_0x320d12??_0x34205b)[a0_0x1e1d45(0x234)](/[\r\n\x00-\x1f\x7f]/g,'\x20')[a0_0x1e1d45(0x23c)](0x0,0xf0);function N(_0x44a7c3){const _0x4975c7=a0_0x1e1d45;return(_0x44a7c3 instanceof Error?_0x44a7c3['message']:String(_0x44a7c3??_0x4975c7(0x252)))['replace'](K,_0x4975c7(0x210))[_0x4975c7(0x234)](/[\r\n\x00-\x1f\x7f]/g,'\x20')[_0x4975c7(0x23c)](0x0,0xf0);}function a0_0x59ac(){const _0xd48ed9=['heartbeatTimer','send_message','completed','content','Bearer\x20','connect','inbox\x20error:\x20','get_all_status','pop','4638300IFhVNN','sleep','SSE\x20reconnecting\x20in\x20','parentTaskId','body','connected','parent_task_id','reply','heartbeat\x20failed:\x20','network_id','not_tracked','text/event-stream','send_rejected','heartbeatInterval','getAllStatus','sseAbort','registered','error_code','replace','\x20lifecycle=','error','abort','get_inbox','ack_inbox','failed','disconnected','slice','task.ack','lifecycle_tracking','send_task','8169864UHxXfO','string','sdk','fromAlias','Authorization','task.started','toAlias','[commhub:task]\x20','running','parse','url','data:\x20','cwd','status','\x20transport=','AbortError','CommHub\x20response\x20omitted\x20task_id','new_message','unknown\x20error','send','alias','normal','/mcp','\x20duration_ms=','decode','read','text','task.send.start','autoConnect','2496984sIsDAk','CommHub\x20rejected\x20task','s...','log','SSE\x20error:\x20','\x20from=','message_id','<unknown>','sdk-','call','signal','toString','/events/','networkId','broadcast','3490025YPWgDs','token','task.send.delivered','\x20network_id=','2.0','to_alias','send_reply','5613thWZRX','json','catch','4824150kTMPzs','new_task','<missing>','agent','idle','error_message','resumeId','messages','result','from_session','task','message','now',']\x20[commhub:','lifecycleTracking','processInbox','task.send.failed','306AmLNLR','3320744zYloPT','offline','\x20parent_task_id=','mcp_http','connectSSE','SSE\x20connected','emit','split','server','[REDACTED]','transport','name','POST','report_status','reconnectDelay','task_id','send_failed','type'];a0_0x59ac=function(){return _0xd48ed9;};return a0_0x59ac();}function O(_0x1affab,_0x4e2a02=process.env.ANET_TASK_TRACE_FORMAT===a0_0x1e1d45(0x1f3)){const _0x106835=a0_0x1e1d45;if(_0x4e2a02)return JSON['stringify'](_0x1affab);let _0x5ce38e=L(_0x1affab[_0x106835(0x228)],_0x106835(0x1f7)),_0x756df1=L(_0x1affab[_0x106835(0x216)],'<pending>'),_0x5356e9=_0x1affab[_0x106835(0x233)]?'\x20error='+_0x1affab['error_code']+':'+(_0x1affab[_0x106835(0x1fa)]??''):'';return _0x106835(0x247)+_0x1affab['status']+_0x106835(0x1e1)+L(_0x1affab['from_alias'],_0x106835(0x1e3))+'\x20to='+L(_0x1affab[_0x106835(0x1f0)],_0x106835(0x1e3))+'\x20task_id='+_0x756df1+_0x106835(0x209)+_0x5ce38e+_0x106835(0x1ee)+L(_0x1affab[_0x106835(0x22b)],_0x106835(0x1e3))+_0x106835(0x24e)+_0x1affab['transport']+_0x106835(0x1d6)+_0x1affab['duration_ms']+_0x106835(0x235)+_0x1affab[_0x106835(0x23e)]+_0x5356e9;}function U(_0x576aea){const _0x501b72=a0_0x1e1d45;return{'event':{'sending':_0x501b72(0x1da),'delivered':_0x501b72(0x1ed),'failed':_0x501b72(0x205),'acked':_0x501b72(0x23d),'started':_0x501b72(0x245),'replied':'task.replied','expired':'task.expired'}[_0x576aea[_0x501b72(0x24d)]],..._0x576aea};}function j(_0x4bc681){const _0x204f01=a0_0x1e1d45;let _0x135ca8=_0x4bc681?.[_0x204f01(0x216)]||_0x4bc681?.['message_id']||_0x4bc681?.['id'];if(_0x135ca8)return String(_0x135ca8);let _0xb52479=_0x4bc681?.['content']?.[0x0]?.['text'];if(typeof _0xb52479!==_0x204f01(0x241))return null;try{let _0x454547=JSON[_0x204f01(0x249)](_0xb52479);return _0x454547?.['task_id']||_0x454547?.[_0x204f01(0x1e2)]||_0x454547?.['id']||null;}catch{return null;}}async function X(_0x4c86da,_0x4da0e6){const _0x16b461=a0_0x1e1d45;let _0x531983=_0x4da0e6['now']??Date[_0x16b461(0x201)],_0x96ede7=_0x531983(),_0x2a332f=(_0x545578,_0x2169f2,_0x27335a,_0x38eb22)=>{const _0x1ebe0e=_0x16b461;_0x4da0e6[_0x1ebe0e(0x1df)](O(U({'from_alias':_0x4c86da['fromAlias'],'to_alias':_0x4c86da[_0x1ebe0e(0x246)],'task_id':_0x2169f2,'parent_task_id':_0x4c86da[_0x1ebe0e(0x225)],'network_id':_0x4c86da['networkId'],'transport':_0x4c86da[_0x1ebe0e(0x211)],'status':_0x545578,'duration_ms':_0x531983()-_0x96ede7,'lifecycle_tracking':_0x4c86da[_0x1ebe0e(0x203)],..._0x27335a!==void 0x0?{'error_code':_0x38eb22||_0x1ebe0e(0x217),'error_message':N(_0x27335a)}:{}})));};_0x2a332f('sending',null);try{let _0x108dec=await _0x4da0e6[_0x16b461(0x253)](),_0x2cdd87=j(_0x108dec);if(_0x2cdd87)_0x2a332f('delivered',_0x2cdd87);else{if(_0x108dec?.['ok']===!0x1||_0x108dec?.[_0x16b461(0x236)])_0x2a332f('failed',_0x2cdd87,_0x108dec?.[_0x16b461(0x236)]||_0x16b461(0x1dd),_0x16b461(0x22e));else _0x2a332f(_0x16b461(0x23a),null,_0x16b461(0x250),'missing_task_id');}return _0x108dec;}catch(_0x592175){throw _0x2a332f(_0x16b461(0x23a),null,_0x592175,_0x16b461(0x217)),_0x592175;}}async function Y(_0x5095c4,_0x30ddf4){const _0x3e9dd6=a0_0x1e1d45;return X({'fromAlias':_0x5095c4[_0x3e9dd6(0x243)],'toAlias':_0x5095c4['alias'],'parentTaskId':_0x5095c4[_0x3e9dd6(0x225)]||null,'networkId':_0x5095c4[_0x3e9dd6(0x1e9)]||null,'transport':_0x3e9dd6(0x20a),'lifecycleTracking':_0x3e9dd6(0x22c)},_0x30ddf4);}class $ extends a0_0x300e63{[a0_0x1e1d45(0x24a)];['alias'];[a0_0x1e1d45(0x1ec)];[a0_0x1e1d45(0x1f8)];[a0_0x1e1d45(0x1fb)];[a0_0x1e1d45(0x22f)];[a0_0x1e1d45(0x215)];[a0_0x1e1d45(0x219)];[a0_0x1e1d45(0x231)];[a0_0x1e1d45(0x248)]=!0x1;constructor(_0x5d6153){const _0x374d1a=a0_0x1e1d45;super();if(this[_0x374d1a(0x24a)]=_0x5d6153[_0x374d1a(0x24a)]['replace'](/\/$/,''),this['alias']=_0x5d6153[_0x374d1a(0x254)],this[_0x374d1a(0x1ec)]=_0x5d6153[_0x374d1a(0x1ec)],this[_0x374d1a(0x1f8)]=_0x5d6153[_0x374d1a(0x1f8)]||_0x374d1a(0x242),this[_0x374d1a(0x1fb)]=_0x374d1a(0x1e4)+_0x5d6153[_0x374d1a(0x254)]+'-'+Date[_0x374d1a(0x201)]()[_0x374d1a(0x1e7)](0x24),this[_0x374d1a(0x22f)]=_0x5d6153[_0x374d1a(0x22f)]??0x2bf20,this[_0x374d1a(0x215)]=_0x5d6153[_0x374d1a(0x215)]??0xbb8,_0x5d6153[_0x374d1a(0x1db)]!==!0x1)this[_0x374d1a(0x21e)]();}['log'](_0x15b37b){const _0x37d6e7=a0_0x1e1d45;console[_0x37d6e7(0x1df)]('['+new Date()['toTimeString']()[_0x37d6e7(0x23c)](0x0,0x8)+_0x37d6e7(0x202)+this['alias']+']\x20'+_0x15b37b);}async[a0_0x1e1d45(0x1e5)](_0x45d31d,_0x2d689e){const _0x5e34ca=a0_0x1e1d45;let _0x3d677e={'Content-Type':'application/json','Accept':'application/json,\x20text/event-stream'};if(this[_0x5e34ca(0x1ec)])_0x3d677e[_0x5e34ca(0x244)]=_0x5e34ca(0x21d)+this[_0x5e34ca(0x1ec)];let _0x434847=await(await fetch(this[_0x5e34ca(0x24a)]+_0x5e34ca(0x1d5),{'method':_0x5e34ca(0x213),'headers':_0x3d677e,'body':JSON['stringify']({'jsonrpc':_0x5e34ca(0x1ef),'id':Date[_0x5e34ca(0x201)](),'method':'tools/call','params':{'name':_0x45d31d,'arguments':_0x2d689e}})}))[_0x5e34ca(0x1d9)](),_0x14fa12=_0x434847['match'](/data: (.+)/),_0x28aef5=_0x14fa12?JSON[_0x5e34ca(0x249)](_0x14fa12[0x1]):JSON['parse'](_0x434847),_0x46e593=_0x28aef5?.[_0x5e34ca(0x1fd)]?.[_0x5e34ca(0x21c)]?.[0x0]?.[_0x5e34ca(0x1d9)];return _0x46e593?JSON[_0x5e34ca(0x249)](_0x46e593):_0x28aef5;}async[a0_0x1e1d45(0x21e)](){const _0x43be0=a0_0x1e1d45;if(this[_0x43be0(0x248)])return;this[_0x43be0(0x248)]=!0x0,await this[_0x43be0(0x24d)]('idle'),this['log'](_0x43be0(0x232)),this['heartbeatTimer']=setInterval(()=>{const _0x3c98b5=_0x43be0;this[_0x3c98b5(0x24d)](_0x3c98b5(0x1f9))[_0x3c98b5(0x1f4)](_0x40cf89=>this[_0x3c98b5(0x1df)](_0x3c98b5(0x22a)+_0x40cf89[_0x3c98b5(0x200)]));},this[_0x43be0(0x22f)]),this[_0x43be0(0x20b)]();}async['disconnect'](){const _0xbdc152=a0_0x1e1d45;if(this[_0xbdc152(0x248)]=!0x1,this[_0xbdc152(0x231)]?.[_0xbdc152(0x237)](),this[_0xbdc152(0x219)])clearInterval(this[_0xbdc152(0x219)]);await this['status'](_0xbdc152(0x208))[_0xbdc152(0x1f4)](()=>{}),this[_0xbdc152(0x1df)](_0xbdc152(0x23b));}async[a0_0x1e1d45(0x253)](_0x16aa9e,_0x4a2e0d,_0x56c139=a0_0x1e1d45(0x255)){const _0x5ac850=a0_0x1e1d45;return Y({'alias':_0x16aa9e,'fromAlias':this[_0x5ac850(0x254)]},{'log':_0x237964=>console['log'](_0x237964),'send':()=>this[_0x5ac850(0x1e5)](_0x5ac850(0x23f),{'alias':_0x16aa9e,'task':_0x4a2e0d,'priority':_0x56c139,'from_session':this[_0x5ac850(0x254)]})});}async[a0_0x1e1d45(0x200)](_0x2c56d6,_0x30e276){const _0x3093d2=a0_0x1e1d45;return this['call'](_0x3093d2(0x21a),{'alias':_0x2c56d6,'message':_0x30e276,'from_session':this[_0x3093d2(0x254)]});}async[a0_0x1e1d45(0x229)](_0x3d1cbb,_0x53b4d7,_0x76cd11=a0_0x1e1d45(0x21b)){const _0x12ad5a=a0_0x1e1d45;return this[_0x12ad5a(0x1e5)](_0x12ad5a(0x1f1),{'in_reply_to':_0x3d1cbb,'text':_0x53b4d7,'status':_0x76cd11});}async[a0_0x1e1d45(0x24d)](_0x341b62,_0x367b81){const _0xe19e95=a0_0x1e1d45;return this['call'](_0xe19e95(0x214),{'resume_id':this[_0xe19e95(0x1fb)],'alias':this[_0xe19e95(0x254)],'status':_0x341b62,'server':a0_0x1bf6d8(),'hostname':a0_0x1bf6d8(),'agent':this[_0xe19e95(0x1f8)],'project_dir':process[_0xe19e95(0x24c)](),..._0x367b81});}async[a0_0x1e1d45(0x230)](){const _0x4c7d07=a0_0x1e1d45;return this[_0x4c7d07(0x1e5)](_0x4c7d07(0x220),{});}async[a0_0x1e1d45(0x1ea)](_0x1b189a,_0x58a79b){const _0x5b53aa=a0_0x1e1d45;return this[_0x5b53aa(0x1e5)](_0x5b53aa(0x1ea),{'message':_0x1b189a,'filter_server':_0x58a79b?.[_0x5b53aa(0x20f)],'filter_status':_0x58a79b?.[_0x5b53aa(0x24d)]});}async[a0_0x1e1d45(0x20b)](){const _0x2fe75b=a0_0x1e1d45;let _0x1f9336=encodeURIComponent(this[_0x2fe75b(0x254)]),_0x23253e=this[_0x2fe75b(0x24a)]+_0x2fe75b(0x1e8)+_0x1f9336,_0x1dd58a=this[_0x2fe75b(0x215)];while(this[_0x2fe75b(0x248)]){try{this['sseAbort']=new AbortController();let _0x5a8e68={'Accept':_0x2fe75b(0x22d)};if(this['token'])_0x5a8e68[_0x2fe75b(0x244)]=_0x2fe75b(0x21d)+this[_0x2fe75b(0x1ec)];let _0x5b798f=await fetch(_0x23253e,{'headers':_0x5a8e68,'signal':this[_0x2fe75b(0x231)][_0x2fe75b(0x1e6)]});if(!_0x5b798f['ok']||!_0x5b798f[_0x2fe75b(0x226)]){this[_0x2fe75b(0x1df)]('SSE\x20failed:\x20'+_0x5b798f[_0x2fe75b(0x24d)]),await this[_0x2fe75b(0x223)](_0x1dd58a),_0x1dd58a=Math['min'](_0x1dd58a*1.5,0xea60);continue;}_0x1dd58a=this[_0x2fe75b(0x215)];let _0xbf155=_0x5b798f[_0x2fe75b(0x226)]['getReader'](),_0x344451=new TextDecoder(),_0x283780='';while(this['running']){let {done:_0x3db989,value:_0x414f1e}=await _0xbf155[_0x2fe75b(0x1d8)]();if(_0x3db989)break;_0x283780+=_0x344451[_0x2fe75b(0x1d7)](_0x414f1e,{'stream':!0x0});let _0x38886e=_0x283780[_0x2fe75b(0x20e)]('\x0a');_0x283780=_0x38886e[_0x2fe75b(0x221)]()||'';for(let _0x3ae8e2 of _0x38886e){if(!_0x3ae8e2['startsWith'](_0x2fe75b(0x24b)))continue;try{let _0x35d15e=JSON[_0x2fe75b(0x249)](_0x3ae8e2[_0x2fe75b(0x23c)](0x6));if(_0x35d15e[_0x2fe75b(0x218)]===_0x2fe75b(0x227)){this[_0x2fe75b(0x1df)](_0x2fe75b(0x20c)),this[_0x2fe75b(0x20d)](_0x2fe75b(0x227));continue;}if(_0x35d15e[_0x2fe75b(0x218)]===_0x2fe75b(0x1f6)||_0x35d15e[_0x2fe75b(0x218)]===_0x2fe75b(0x251)||_0x35d15e[_0x2fe75b(0x218)]===_0x2fe75b(0x1ea))await this[_0x2fe75b(0x204)]();}catch{}}}}catch(_0x292832){if(_0x292832[_0x2fe75b(0x212)]===_0x2fe75b(0x24f))break;this['emit']('error',_0x292832),this[_0x2fe75b(0x1df)](_0x2fe75b(0x1e0)+_0x292832[_0x2fe75b(0x200)]);}if(this[_0x2fe75b(0x248)])this[_0x2fe75b(0x20d)](_0x2fe75b(0x23b)),this[_0x2fe75b(0x1df)](_0x2fe75b(0x224)+_0x1dd58a/0x3e8+_0x2fe75b(0x1de)),await this[_0x2fe75b(0x223)](_0x1dd58a),_0x1dd58a=Math['min'](_0x1dd58a*1.5,0xea60);}}async[a0_0x1e1d45(0x204)](){const _0x1a0e34=a0_0x1e1d45;try{let _0x379f9c=(await this[_0x1a0e34(0x1e5)](_0x1a0e34(0x238),{'alias':this[_0x1a0e34(0x254)],'limit':0xa}))?.[_0x1a0e34(0x1fc)]||[];for(let _0x12b483 of _0x379f9c)await this[_0x1a0e34(0x1e5)](_0x1a0e34(0x239),{'alias':this[_0x1a0e34(0x254)],'message_id':_0x12b483['id']}),this[_0x1a0e34(0x1df)]('←\x20'+_0x12b483[_0x1a0e34(0x1fe)]+':\x20'+_0x12b483[_0x1a0e34(0x21c)]['slice'](0x0,0x3c)),this[_0x1a0e34(0x20d)](_0x1a0e34(0x1ff),_0x12b483),this['emit']('message',_0x12b483);}catch(_0x3cc51a){this['log'](_0x1a0e34(0x21f)+_0x3cc51a[_0x1a0e34(0x200)]);}}['sleep'](_0x1b6f7d){return new Promise(_0x1287bc=>setTimeout(_0x1287bc,_0x1b6f7d));}}function a0_0x2a3c(_0x542321,_0x4820bf){_0x542321=_0x542321-0x1d5;const _0x59ac0b=a0_0x59ac();let _0x2a3c3c=_0x59ac0b[_0x542321];return _0x2a3c3c;}var F=$;export{F as default,$ as CommHub};
1
+ function a0_0x4ae5(_0x52b20f,_0x530752){_0x52b20f=_0x52b20f-0x1d0;const _0x596ab6=a0_0x596a();let _0x4ae560=_0x596ab6[_0x52b20f];return _0x4ae560;}const a0_0x96fcb5=a0_0x4ae5;(function(_0x2e6fbe,_0x15e532){const _0x54a8eb=a0_0x4ae5,_0x30edcb=_0x2e6fbe();while(!![]){try{const _0x9d0974=-parseInt(_0x54a8eb(0x24c))/0x1+-parseInt(_0x54a8eb(0x21f))/0x2*(-parseInt(_0x54a8eb(0x212))/0x3)+-parseInt(_0x54a8eb(0x207))/0x4+-parseInt(_0x54a8eb(0x1fc))/0x5*(parseInt(_0x54a8eb(0x243))/0x6)+-parseInt(_0x54a8eb(0x20e))/0x7+parseInt(_0x54a8eb(0x24e))/0x8*(parseInt(_0x54a8eb(0x22a))/0x9)+parseInt(_0x54a8eb(0x251))/0xa;if(_0x9d0974===_0x15e532)break;else _0x30edcb['push'](_0x30edcb['shift']());}catch(_0x189f4a){_0x30edcb['push'](_0x30edcb['shift']());}}}(a0_0x596a,0x9fbf9));import{EventEmitter as a0_0x524a26}from'events';import{hostname as a0_0x46a5df}from'os';var K=/(?:atok|ntok|utok|ghp|github_pat)_[A-Za-z0-9_-]+|Bearer\s+\S+/gi,L=(_0x44c14a,_0x2dedb5)=>(_0x44c14a??_0x2dedb5)[a0_0x96fcb5(0x1d9)](/[\r\n\x00-\x1f\x7f]/g,'\x20')['slice'](0x0,0xf0);function N(_0x2fc5b3){const _0x5270b1=a0_0x96fcb5;return(_0x2fc5b3 instanceof Error?_0x2fc5b3['message']:String(_0x2fc5b3??'unknown\x20error'))[_0x5270b1(0x1d9)](K,_0x5270b1(0x23f))[_0x5270b1(0x1d9)](/[\r\n\x00-\x1f\x7f]/g,'\x20')[_0x5270b1(0x221)](0x0,0xf0);}function a0_0x596a(){const _0x2a1913=['application/json,\x20text/event-stream','new_message','task.ack','error','min','completed','getAllStatus','decode','delivered','name','toString','stringify','2182LDzprE','abort','slice','POST','send','2.0','processInbox','body','heartbeatInterval','send_failed','failed','18gbItNq','from_alias','task.send.failed','sleep','/mcp','from_session','task.send.start','connected','s...','Bearer\x20','\x20duration_ms=','\x20from=',']\x20[commhub:','sending','content','\x20network_id=','url','inbox\x20error:\x20','networkId','send_message','text','[REDACTED]','resumeId','alias','startsWith','1191066wffCWq','lifecycleTracking','broadcast','running','\x20task_id=','task.expired','send_task','type','status','1227520ZxcLQX','token','87064wUEhfH','lifecycle_tracking','json','40344720MzvMen','parse','error_message','catch','connect','application/json','match','error_code','tools/call','message_id','replace','send_rejected','disconnected','SSE\x20reconnecting\x20in\x20','\x20transport=','\x20parent_task_id=','missing_task_id','CommHub\x20response\x20omitted\x20task_id','<missing>','autoConnect','now','task.replied','reply','fromAlias','transport','SSE\x20failed:\x20','reconnectDelay','read','idle','toAlias','disconnect','CommHub\x20rejected\x20task','connectSSE','\x20error=','agent','emit','sdk','message','task.send.delivered','Authorization','SSE\x20error:\x20','/events/','registered','<unknown>','normal','25cuotXm','split','sdk-','toTimeString','parentTaskId','heartbeat\x20failed:\x20','ack_inbox','call','log','offline','\x20to=','4885028EkPtGH','signal','duration_ms','task_id','mcp_http','text/event-stream','sseAbort','6543880kekFnt','SSE\x20connected','heartbeatTimer','\x20lifecycle=','2679xQHKwM'];a0_0x596a=function(){return _0x2a1913;};return a0_0x596a();}function O(_0x223d9a,_0x134a1a=process.env.ANET_TASK_TRACE_FORMAT===a0_0x96fcb5(0x250)){const _0x4f4766=a0_0x96fcb5;if(_0x134a1a)return JSON[_0x4f4766(0x21e)](_0x223d9a);let _0x223f3b=L(_0x223d9a['parent_task_id'],_0x4f4766(0x1e1)),_0x462886=L(_0x223d9a[_0x4f4766(0x20a)],'<pending>'),_0x2fe9fd=_0x223d9a[_0x4f4766(0x1d6)]?_0x4f4766(0x1f0)+_0x223d9a[_0x4f4766(0x1d6)]+':'+(_0x223d9a[_0x4f4766(0x1d1)]??''):'';return'[commhub:task]\x20'+_0x223d9a[_0x4f4766(0x24b)]+_0x4f4766(0x235)+L(_0x223d9a[_0x4f4766(0x22b)],_0x4f4766(0x1fa))+_0x4f4766(0x206)+L(_0x223d9a['to_alias'],'<unknown>')+_0x4f4766(0x247)+_0x462886+_0x4f4766(0x1de)+_0x223f3b+_0x4f4766(0x239)+L(_0x223d9a['network_id'],_0x4f4766(0x1fa))+_0x4f4766(0x1dd)+_0x223d9a['transport']+_0x4f4766(0x234)+_0x223d9a[_0x4f4766(0x209)]+_0x4f4766(0x211)+_0x223d9a[_0x4f4766(0x24f)]+_0x2fe9fd;}function U(_0x3c8710){const _0x543b24=a0_0x96fcb5;return{'event':{'sending':_0x543b24(0x230),'delivered':_0x543b24(0x1f5),'failed':_0x543b24(0x22c),'acked':_0x543b24(0x215),'started':'task.started','replied':_0x543b24(0x1e4),'expired':_0x543b24(0x248)}[_0x3c8710[_0x543b24(0x24b)]],..._0x3c8710};}function j(_0x374314){const _0x3185f0=a0_0x96fcb5;let _0x1cc365=_0x374314?.[_0x3185f0(0x20a)]||_0x374314?.[_0x3185f0(0x1d8)]||_0x374314?.['id'];if(_0x1cc365)return String(_0x1cc365);let _0x12b304=_0x374314?.[_0x3185f0(0x238)]?.[0x0]?.[_0x3185f0(0x23e)];if(typeof _0x12b304!=='string')return null;try{let _0x481f58=JSON[_0x3185f0(0x1d0)](_0x12b304);return _0x481f58?.[_0x3185f0(0x20a)]||_0x481f58?.[_0x3185f0(0x1d8)]||_0x481f58?.['id']||null;}catch{return null;}}async function X(_0x143317,_0x5ccb4e){const _0x1d4d3e=a0_0x96fcb5;let _0x5ed52c=_0x5ccb4e['now']??Date['now'],_0x331bae=_0x5ed52c(),_0x3ddd3f=(_0x3c4255,_0x4252f4,_0x3602e9,_0x1b72d1)=>{const _0x57fe9f=a0_0x4ae5;_0x5ccb4e[_0x57fe9f(0x204)](O(U({'from_alias':_0x143317['fromAlias'],'to_alias':_0x143317[_0x57fe9f(0x1ec)],'task_id':_0x4252f4,'parent_task_id':_0x143317[_0x57fe9f(0x200)],'network_id':_0x143317[_0x57fe9f(0x23c)],'transport':_0x143317[_0x57fe9f(0x1e7)],'status':_0x3c4255,'duration_ms':_0x5ed52c()-_0x331bae,'lifecycle_tracking':_0x143317[_0x57fe9f(0x244)],..._0x3602e9!==void 0x0?{'error_code':_0x1b72d1||_0x57fe9f(0x228),'error_message':N(_0x3602e9)}:{}})));};_0x3ddd3f(_0x1d4d3e(0x237),null);try{let _0x44bcf1=await _0x5ccb4e[_0x1d4d3e(0x223)](),_0x2c349e=j(_0x44bcf1);if(_0x2c349e)_0x3ddd3f(_0x1d4d3e(0x21b),_0x2c349e);else{if(_0x44bcf1?.['ok']===!0x1||_0x44bcf1?.[_0x1d4d3e(0x216)])_0x3ddd3f(_0x1d4d3e(0x229),_0x2c349e,_0x44bcf1?.[_0x1d4d3e(0x216)]||_0x1d4d3e(0x1ee),_0x1d4d3e(0x1da));else _0x3ddd3f(_0x1d4d3e(0x229),null,_0x1d4d3e(0x1e0),_0x1d4d3e(0x1df));}return _0x44bcf1;}catch(_0x302d5a){throw _0x3ddd3f('failed',null,_0x302d5a,'send_failed'),_0x302d5a;}}async function Y(_0x18d20b,_0x27bb2e){const _0x255720=a0_0x96fcb5;return X({'fromAlias':_0x18d20b[_0x255720(0x1e6)],'toAlias':_0x18d20b[_0x255720(0x241)],'parentTaskId':_0x18d20b['parentTaskId']||null,'networkId':_0x18d20b[_0x255720(0x23c)]||null,'transport':_0x255720(0x20b),'lifecycleTracking':'not_tracked'},_0x27bb2e);}class $ extends a0_0x524a26{[a0_0x96fcb5(0x23a)];[a0_0x96fcb5(0x241)];[a0_0x96fcb5(0x24d)];[a0_0x96fcb5(0x1f1)];['resumeId'];[a0_0x96fcb5(0x227)];['reconnectDelay'];[a0_0x96fcb5(0x210)];[a0_0x96fcb5(0x20d)];['running']=!0x1;constructor(_0x42df8c){const _0x19132b=a0_0x96fcb5;super();if(this[_0x19132b(0x23a)]=_0x42df8c[_0x19132b(0x23a)]['replace'](/\/$/,''),this['alias']=_0x42df8c[_0x19132b(0x241)],this[_0x19132b(0x24d)]=_0x42df8c[_0x19132b(0x24d)],this[_0x19132b(0x1f1)]=_0x42df8c['agent']||_0x19132b(0x1f3),this[_0x19132b(0x240)]=_0x19132b(0x1fe)+_0x42df8c['alias']+'-'+Date[_0x19132b(0x1e3)]()[_0x19132b(0x21d)](0x24),this[_0x19132b(0x227)]=_0x42df8c['heartbeatInterval']??0x2bf20,this[_0x19132b(0x1e9)]=_0x42df8c[_0x19132b(0x1e9)]??0xbb8,_0x42df8c[_0x19132b(0x1e2)]!==!0x1)this[_0x19132b(0x1d3)]();}[a0_0x96fcb5(0x204)](_0x21796f){const _0x398d0f=a0_0x96fcb5;console[_0x398d0f(0x204)]('['+new Date()[_0x398d0f(0x1ff)]()[_0x398d0f(0x221)](0x0,0x8)+_0x398d0f(0x236)+this[_0x398d0f(0x241)]+']\x20'+_0x21796f);}async[a0_0x96fcb5(0x203)](_0x2a58b1,_0x310039){const _0x281549=a0_0x96fcb5;let _0x36fca1={'Content-Type':_0x281549(0x1d4),'Accept':_0x281549(0x213)};if(this[_0x281549(0x24d)])_0x36fca1[_0x281549(0x1f6)]=_0x281549(0x233)+this['token'];let _0x30c531=await(await fetch(this[_0x281549(0x23a)]+_0x281549(0x22e),{'method':_0x281549(0x222),'headers':_0x36fca1,'body':JSON[_0x281549(0x21e)]({'jsonrpc':_0x281549(0x224),'id':Date[_0x281549(0x1e3)](),'method':_0x281549(0x1d7),'params':{'name':_0x2a58b1,'arguments':_0x310039}})}))[_0x281549(0x23e)](),_0x45f9fc=_0x30c531[_0x281549(0x1d5)](/data: (.+)/),_0x108866=_0x45f9fc?JSON[_0x281549(0x1d0)](_0x45f9fc[0x1]):JSON[_0x281549(0x1d0)](_0x30c531),_0x12e731=_0x108866?.['result']?.['content']?.[0x0]?.['text'];return _0x12e731?JSON['parse'](_0x12e731):_0x108866;}async[a0_0x96fcb5(0x1d3)](){const _0x4f04a1=a0_0x96fcb5;if(this[_0x4f04a1(0x246)])return;this[_0x4f04a1(0x246)]=!0x0,await this[_0x4f04a1(0x24b)](_0x4f04a1(0x1eb)),this['log'](_0x4f04a1(0x1f9)),this[_0x4f04a1(0x210)]=setInterval(()=>{const _0x1e1212=_0x4f04a1;this[_0x1e1212(0x24b)](_0x1e1212(0x1eb))[_0x1e1212(0x1d2)](_0x2dac78=>this[_0x1e1212(0x204)](_0x1e1212(0x201)+_0x2dac78[_0x1e1212(0x1f4)]));},this[_0x4f04a1(0x227)]),this[_0x4f04a1(0x1ef)]();}async[a0_0x96fcb5(0x1ed)](){const _0x28c8b8=a0_0x96fcb5;if(this[_0x28c8b8(0x246)]=!0x1,this[_0x28c8b8(0x20d)]?.[_0x28c8b8(0x220)](),this[_0x28c8b8(0x210)])clearInterval(this[_0x28c8b8(0x210)]);await this[_0x28c8b8(0x24b)](_0x28c8b8(0x205))[_0x28c8b8(0x1d2)](()=>{}),this[_0x28c8b8(0x204)](_0x28c8b8(0x1db));}async[a0_0x96fcb5(0x223)](_0x3dcbe1,_0x42f92b,_0x1aba5f=a0_0x96fcb5(0x1fb)){const _0x279dff=a0_0x96fcb5;return Y({'alias':_0x3dcbe1,'fromAlias':this['alias']},{'log':_0x324596=>console['log'](_0x324596),'send':()=>this[_0x279dff(0x203)](_0x279dff(0x249),{'alias':_0x3dcbe1,'task':_0x42f92b,'priority':_0x1aba5f,'from_session':this[_0x279dff(0x241)]})});}async[a0_0x96fcb5(0x1f4)](_0x357a87,_0x5c3b35){const _0x134146=a0_0x96fcb5;return this[_0x134146(0x203)](_0x134146(0x23d),{'alias':_0x357a87,'message':_0x5c3b35,'from_session':this['alias']});}async[a0_0x96fcb5(0x1e5)](_0x34fbea,_0x1f6caf,_0x15f6b0=a0_0x96fcb5(0x218)){return this['call']('send_reply',{'in_reply_to':_0x34fbea,'text':_0x1f6caf,'status':_0x15f6b0});}async['status'](_0x57c75e,_0x43e379){const _0x39b12b=a0_0x96fcb5;return this[_0x39b12b(0x203)]('report_status',{'resume_id':this['resumeId'],'alias':this[_0x39b12b(0x241)],'status':_0x57c75e,'server':a0_0x46a5df(),'hostname':a0_0x46a5df(),'agent':this[_0x39b12b(0x1f1)],'project_dir':process['cwd'](),..._0x43e379});}async[a0_0x96fcb5(0x219)](){const _0x5d99f1=a0_0x96fcb5;return this[_0x5d99f1(0x203)]('get_all_status',{});}async[a0_0x96fcb5(0x245)](_0x25c454,_0x16e4f5){const _0x3856bd=a0_0x96fcb5;return this[_0x3856bd(0x203)](_0x3856bd(0x245),{'message':_0x25c454,'filter_server':_0x16e4f5?.['server'],'filter_status':_0x16e4f5?.[_0x3856bd(0x24b)]});}async[a0_0x96fcb5(0x1ef)](){const _0x3368c4=a0_0x96fcb5;let _0x57605d=encodeURIComponent(this[_0x3368c4(0x241)]),_0x40785d=this['url']+_0x3368c4(0x1f8)+_0x57605d,_0x3f74e8=this['reconnectDelay'];while(this[_0x3368c4(0x246)]){try{this['sseAbort']=new AbortController();let _0x159c1f={'Accept':_0x3368c4(0x20c)};if(this[_0x3368c4(0x24d)])_0x159c1f[_0x3368c4(0x1f6)]=_0x3368c4(0x233)+this[_0x3368c4(0x24d)];let _0x546358=await fetch(_0x40785d,{'headers':_0x159c1f,'signal':this[_0x3368c4(0x20d)][_0x3368c4(0x208)]});if(!_0x546358['ok']||!_0x546358[_0x3368c4(0x226)]){this['log'](_0x3368c4(0x1e8)+_0x546358[_0x3368c4(0x24b)]),await this[_0x3368c4(0x22d)](_0x3f74e8),_0x3f74e8=Math['min'](_0x3f74e8*1.5,0xea60);continue;}_0x3f74e8=this[_0x3368c4(0x1e9)];let _0x57c108=_0x546358[_0x3368c4(0x226)]['getReader'](),_0x2b6ed7=new TextDecoder(),_0x3c7534='';while(this[_0x3368c4(0x246)]){let {done:_0xddfcfc,value:_0x4511a8}=await _0x57c108[_0x3368c4(0x1ea)]();if(_0xddfcfc)break;_0x3c7534+=_0x2b6ed7[_0x3368c4(0x21a)](_0x4511a8,{'stream':!0x0});let _0x2decfd=_0x3c7534[_0x3368c4(0x1fd)]('\x0a');_0x3c7534=_0x2decfd['pop']()||'';for(let _0x35484f of _0x2decfd){if(!_0x35484f[_0x3368c4(0x242)]('data:\x20'))continue;try{let _0xb53737=JSON[_0x3368c4(0x1d0)](_0x35484f[_0x3368c4(0x221)](0x6));if(_0xb53737[_0x3368c4(0x24a)]===_0x3368c4(0x231)){this[_0x3368c4(0x204)](_0x3368c4(0x20f)),this[_0x3368c4(0x1f2)](_0x3368c4(0x231));continue;}if(_0xb53737[_0x3368c4(0x24a)]==='new_task'||_0xb53737['type']===_0x3368c4(0x214)||_0xb53737['type']===_0x3368c4(0x245))await this[_0x3368c4(0x225)]();}catch{}}}}catch(_0x56fb19){if(_0x56fb19[_0x3368c4(0x21c)]==='AbortError')break;this[_0x3368c4(0x1f2)](_0x3368c4(0x216),_0x56fb19),this[_0x3368c4(0x204)](_0x3368c4(0x1f7)+_0x56fb19[_0x3368c4(0x1f4)]);}if(this['running'])this[_0x3368c4(0x1f2)](_0x3368c4(0x1db)),this[_0x3368c4(0x204)](_0x3368c4(0x1dc)+_0x3f74e8/0x3e8+_0x3368c4(0x232)),await this['sleep'](_0x3f74e8),_0x3f74e8=Math[_0x3368c4(0x217)](_0x3f74e8*1.5,0xea60);}}async[a0_0x96fcb5(0x225)](){const _0x1e4a8a=a0_0x96fcb5;try{let _0x48be0d=(await this[_0x1e4a8a(0x203)]('get_inbox',{'alias':this[_0x1e4a8a(0x241)],'limit':0xa}))?.['messages']||[];for(let _0x6555f9 of _0x48be0d)await this[_0x1e4a8a(0x203)](_0x1e4a8a(0x202),{'alias':this['alias'],'message_id':_0x6555f9['id']}),this[_0x1e4a8a(0x204)]('←\x20'+_0x6555f9[_0x1e4a8a(0x22f)]+':\x20'+_0x6555f9['content']['slice'](0x0,0x3c)),this[_0x1e4a8a(0x1f2)]('task',_0x6555f9),this[_0x1e4a8a(0x1f2)]('message',_0x6555f9);}catch(_0xba01da){this['log'](_0x1e4a8a(0x23b)+_0xba01da[_0x1e4a8a(0x1f4)]);}}[a0_0x96fcb5(0x22d)](_0xaaae45){return new Promise(_0x3b64e9=>setTimeout(_0x3b64e9,_0xaaae45));}}var F=$;export{F as default,$ as CommHub};
@@ -14,6 +14,7 @@
14
14
  * M5: image upload / download (`im.image.create` / `im.messageResource.get`)
15
15
  * + group @bot detection refined to match the bot's own open_id.
16
16
  */
17
+ import type { FeishuHistoryItem } from "./chat-context";
17
18
  import * as lark from "@larksuiteoapi/node-sdk";
18
19
  import type { IMAdapter, IMAdapterHealth, IMChannelConfig, IMConversationRef, IMIngressMode, NormalizedIMEvent, NormalizedIMMessage } from "../types.js";
19
20
  type OnEventHandler = (event: NormalizedIMEvent) => Promise<void>;
@@ -75,6 +76,9 @@ export declare class FeishuAdapter implements IMAdapter {
75
76
  init(config: IMChannelConfig): Promise<void>;
76
77
  start(onEvent: OnEventHandler): Promise<void>;
77
78
  stop(): Promise<void>;
79
+ /** #3682 —— 拉这个会话最近的消息,做聊天上下文。放在 adapter 是因为只有它有已鉴权的 client。
80
+ * 失败一律返回 []:上下文是增益不是链路的一部分,绝不因为读历史失败而丢消息。 */
81
+ fetchRecentContext(chatId: string, limit?: number): Promise<FeishuHistoryItem[]>;
78
82
  send(message: NormalizedIMMessage): Promise<{
79
83
  messageId: string;
80
84
  }>;
@@ -6,26 +6,17 @@
6
6
  *
7
7
  * 🔴 There are TWO outbound paths, and which one runs is decided at line ~445:
8
8
  *
9
- * const client = commhubClient ?? createEnvCommHubClient();
10
- * if (client) return createCommHubEventHandler(...); // (A)
11
- * if (typeof process.send === "function") ... // (B)
9
+ * 选路由是**显式**的(resolveFeishuBridgeMode):默认 direct,只有
10
+ * ANET_FEISHU_BRIDGE_MODE=commhub 才走 Hub。非法值启动即抛,不静默取默认。
12
11
  *
13
- * (A) CommHub task dispatch — **the default on any real node.**
14
- * `createEnvCommHubClient()` returns null only when neither COMMHUB_URL
15
- * nor ANET_HUB_URL is set, and every provisioned node has one. Replies
16
- * carry `in_reply_to`, and the correlation store tracks task status.
17
- * (B) parent IPC → agent-node's `think()` — the fallback when there is no
18
- * hub URL in env (standalone / test harness).
12
+ * (A) direct(默认)—— 消息直接进本机节点的 think()(IPC)。
13
+ * 桥必须和节点同机;少一跳,失败只在一层。
14
+ * (B) commhub —— 消息变成一条 **CommHub task** 派给目标 alias,再轮询自己的
15
+ * inbox 取 reply。桥可以在任何机器;多一层(派发/执行/回读),
16
+ * 多节点还需要一层"@谁发给谁"的路由(尚未实现)。
19
17
  *
20
- * Both paths end at adapter.send() back to the originating conversation.
21
- *
22
- * 🔴 This block used to say the opposite —— verbatim:
23
- * "IM messages do NOT pass through commhub task dispatch."
24
- * That was true of the 2026-06-24 first cut, and stayed in the file after
25
- * the commhub path landed (#1252, merged 2026-08-27). It is the first thing
26
- * anyone reads in this file, so it mis-answered the question "does Feishu go
27
- * through CommHub" for at least one reader before being caught. If you change
28
- * which path is default, change these lines in the same commit.
18
+ * ⚠️ 这段曾经写成「CommHub dispatch 是任何真实节点的默认」,而代码里默认是 direct ——
19
+ * 谁按注释选模式就会以为自己走 Hub。改默认值时,同一提交里改这段。
29
20
  *
30
21
  * Still true of both paths (unchanged from the first cut):
31
22
  * - No separate gateway ntok_ / dedicated commhub alias.
@@ -101,6 +92,9 @@ export interface BridgeIncomingEnvelope {
101
92
  * bridge from `event.conversation.conversationId` + `adapter
102
93
  * .connectionName`. Trailing slash included. */
103
94
  outboundDir?: string;
95
+ /** #3682 —— 已归一化/裁剪/写明"不是新指令"的上下文块(跨包共享不了 mapper,
96
+ * 所以归一化留在有 mapper 的这一侧,node 侧只做拼接)。 */
97
+ contextBlock?: string;
104
98
  }
105
99
  /** Parent → bridge: agent reply text for a previously-forwarded event. */
106
100
  export interface BridgeReplyEnvelope {
@@ -0,0 +1,44 @@
1
+ export interface FeishuHistoryItem {
2
+ message_id?: string;
3
+ create_time?: string;
4
+ msg_type?: string;
5
+ body?: {
6
+ content?: string;
7
+ };
8
+ sender?: {
9
+ id?: string;
10
+ sender_type?: string;
11
+ };
12
+ }
13
+ export interface ChatContextLine {
14
+ /** 发送者 open_id(拿不到就是 null,不编)。 */
15
+ senderId: string | null;
16
+ /** 是否机器人自己说的(sender_type === "app")。 */
17
+ fromBot: boolean;
18
+ /** 已裁剪的纯文本;空消息不会出现在结果里。 */
19
+ text: string;
20
+ }
21
+ export interface ChatContextLimits {
22
+ /** 最多几条(默认 8)。历史越长越容易掺进无关内容。 */
23
+ limit?: number;
24
+ /** 单条最多多少字符(默认 500)。 */
25
+ maxCharsPerMessage?: number;
26
+ /** 总字符预算(默认 2000);超了从**最旧**的开始丢。 */
27
+ maxTotalChars?: number;
28
+ }
29
+ /**
30
+ * 飞书 history items → 上下文行。
31
+ *
32
+ * 输入顺序按飞书返回的"新→旧"(ByCreateTimeDesc)。**输出反转成"旧→新"**:
33
+ * 读起来像对话,且模型不会把最旧的那句当成最后说的话。
34
+ */
35
+ export declare function mapHistoryToContext(items: readonly FeishuHistoryItem[] | undefined, limits?: ChatContextLimits): ChatContextLine[];
36
+ /**
37
+ * 上下文 → 注入 prompt 的块。
38
+ *
39
+ * 三条写在文案里、必须一眼可见的约束:
40
+ * · 这是**历史数据**,不是新指令(防"历史里的句子被执行")
41
+ * · 可能被截断(防模型以为看到了全部)
42
+ * · 发送者用 open_id 的短前缀,不展开身份(拿不到就不编)
43
+ */
44
+ export declare function renderContextBlock(lines: readonly ChatContextLine[]): string;
@@ -7,6 +7,12 @@ export interface FeishuAccessList {
7
7
  allowFrom: string[];
8
8
  /** Feishu chat_ids the bot is permitted to listen in. */
9
9
  allowChats: string[];
10
+ /** #3682 —— open_id → 角色。只对已准入的人生效。 */
11
+ users?: Record<string, {
12
+ role?: string;
13
+ } | undefined>;
14
+ /** #3682 —— 未登记角色的人的默认档(缺省 member,与接入前一致)。 */
15
+ defaultRole?: string;
10
16
  }
11
17
  /**
12
18
  * Outbound text-reply rendering mode (RFC-020 §16). Controls how
@@ -62,4 +68,11 @@ export interface FeishuChannelConfig {
62
68
  * Load Feishu channel config from a node's channels/feishu directory.
63
69
  * Throws if required secrets are missing.
64
70
  */
65
- export declare function loadFeishuChannelConfig(channelDir: string): FeishuChannelConfig;
71
+ export declare function loadFeishuChannelConfig(channelDir: string,
72
+ /**
73
+ * 进程环境(可选)。存在的理由:跨机节点拿不到"把 .env 拷过去"这件事 ——
74
+ * 密钥只能通过 Hub 保险库推到 <nodeDir>/node-secrets.json,agent-node 启动时
75
+ * 把它灌进 process.env(activation: next_start)。所以读取顺序是 .env > process.env;
76
+ * 反过来会让一个陈旧的 .env 悄悄盖掉刚推下来的值。
77
+ */
78
+ processEnv?: Record<string, string | undefined>): FeishuChannelConfig;
@@ -0,0 +1,2 @@
1
+ /** 前面还有 ahead 条时的那句话;ahead ≤ 0 返回空串(不发)。 */
2
+ export declare function queueNoticeText(ahead: number): string;