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

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
+ const a0_0x28c511=a0_0x34fc;(function(_0x3d7e46,_0x1c8370){const _0x185e69=a0_0x34fc,_0x4459f7=_0x3d7e46();while(!![]){try{const _0x3bb8bd=-parseInt(_0x185e69(0x14e))/0x1*(parseInt(_0x185e69(0x118))/0x2)+-parseInt(_0x185e69(0x175))/0x3*(parseInt(_0x185e69(0x16e))/0x4)+parseInt(_0x185e69(0x10f))/0x5+parseInt(_0x185e69(0x156))/0x6+-parseInt(_0x185e69(0x177))/0x7*(-parseInt(_0x185e69(0x164))/0x8)+-parseInt(_0x185e69(0x182))/0x9*(-parseInt(_0x185e69(0x139))/0xa)+parseInt(_0x185e69(0x17f))/0xb*(-parseInt(_0x185e69(0x18d))/0xc);if(_0x3bb8bd===_0x1c8370)break;else _0x4459f7['push'](_0x4459f7['shift']());}catch(_0x3ffcdb){_0x4459f7['push'](_0x4459f7['shift']());}}}(a0_0x285a,0x27c72));import{EventEmitter as a0_0x2943b2}from'events';import{hostname as a0_0x5e652b}from'os';function a0_0x34fc(_0xd5d15b,_0x2fb6c1){_0xd5d15b=_0xd5d15b-0x107;const _0x285a4e=a0_0x285a();let _0x34fc72=_0x285a4e[_0xd5d15b];return _0x34fc72;}var K=/(?:atok|ntok|utok|ghp|github_pat)_[A-Za-z0-9_-]+|Bearer\s+\S+/gi,L=(_0x1a26d4,_0xa25bd6)=>(_0x1a26d4??_0xa25bd6)[a0_0x28c511(0x183)](/[\r\n\x00-\x1f\x7f]/g,'\x20')['slice'](0x0,0xf0);function N(_0xd7f151){const _0x2d8588=a0_0x28c511;return(_0xd7f151 instanceof Error?_0xd7f151['message']:String(_0xd7f151??_0x2d8588(0x130)))[_0x2d8588(0x183)](K,_0x2d8588(0x15f))[_0x2d8588(0x183)](/[\r\n\x00-\x1f\x7f]/g,'\x20')[_0x2d8588(0x155)](0x0,0xf0);}function O(_0x11f32a,_0x204ef9=process.env.ANET_TASK_TRACE_FORMAT===a0_0x28c511(0x122)){const _0x1075de=a0_0x28c511;if(_0x204ef9)return JSON['stringify'](_0x11f32a);let _0x4f0c38=L(_0x11f32a[_0x1075de(0x129)],_0x1075de(0x16f)),_0x5a3da3=L(_0x11f32a[_0x1075de(0x17c)],_0x1075de(0x113)),_0x28e92a=_0x11f32a[_0x1075de(0x134)]?'\x20error='+_0x11f32a['error_code']+':'+(_0x11f32a[_0x1075de(0x185)]??''):'';return'[commhub:task]\x20'+_0x11f32a['status']+_0x1075de(0x18b)+L(_0x11f32a[_0x1075de(0x12d)],_0x1075de(0x167))+'\x20to='+L(_0x11f32a['to_alias'],_0x1075de(0x167))+'\x20task_id='+_0x5a3da3+_0x1075de(0x10e)+_0x4f0c38+'\x20network_id='+L(_0x11f32a['network_id'],_0x1075de(0x167))+_0x1075de(0x18a)+_0x11f32a[_0x1075de(0x17a)]+_0x1075de(0x12b)+_0x11f32a[_0x1075de(0x16d)]+_0x1075de(0x126)+_0x11f32a[_0x1075de(0x109)]+_0x28e92a;}function a0_0x285a(){const _0x2df214=['get_inbox','text','agent','lifecycle_tracking','sdk-','SSE\x20reconnecting\x20in\x20','toAlias','running','\x20parent_task_id=','516450BIZuYP','offline','sdk','task.send.delivered','<pending>','decode','tools/call','send_message','connected','4pvipkJ','new_message','text/event-stream','emit','send_task','application/json,\x20text/event-stream','connect','connectSSE','now','get_all_status','json','min','completed','normal','\x20lifecycle=','content','Bearer\x20','parent_task_id','resumeId','\x20duration_ms=','POST','from_alias','messages','CommHub\x20response\x20omitted\x20task_id','unknown\x20error','idle','missing_task_id','status','error_code','cwd','fromAlias','CommHub\x20rejected\x20task','task.send.failed','130YBulmJ','url',']\x20[commhub:','parse','send_failed','/mcp','getReader','log','failed','SSE\x20failed:\x20','signal','sending','task.expired','disconnect','catch','toString','string','task.send.start','heartbeat\x20failed:\x20','processInbox','read','29494JTjIif','send','type','delivered','networkId','error','reply','slice','387378EFPapW','2.0','SSE\x20connected','task.replied','call','from_session','sleep','message','split','[REDACTED]','disconnected','lifecycleTracking','autoConnect','Authorization','8SJjieR','task.ack','reconnectDelay','<unknown>','new_task','getAllStatus','mcp_http','alias','pop','duration_ms','4HYmCPo','<missing>','sseAbort','/events/','AbortError','broadcast','body','761361NDkivT','send_reply','1987398BdqKiF','registered','stringify','transport','heartbeatInterval','task_id','message_id','heartbeatTimer','2281367loFQBc','report_status','toTimeString','160155Kcpzla','replace','token','error_message','result','parentTaskId','task','task.started','\x20transport=','\x20from=','send_rejected','12NBUnWg'];a0_0x285a=function(){return _0x2df214;};return a0_0x285a();}function U(_0xacff05){const _0x559cd2=a0_0x28c511;return{'event':{'sending':_0x559cd2(0x14a),'delivered':_0x559cd2(0x112),'failed':_0x559cd2(0x138),'acked':_0x559cd2(0x165),'started':_0x559cd2(0x189),'replied':_0x559cd2(0x159),'expired':_0x559cd2(0x145)}[_0xacff05[_0x559cd2(0x133)]],..._0xacff05};}function j(_0x1eecdf){const _0x32a01e=a0_0x28c511;let _0x15c998=_0x1eecdf?.[_0x32a01e(0x17c)]||_0x1eecdf?.[_0x32a01e(0x17d)]||_0x1eecdf?.['id'];if(_0x15c998)return String(_0x15c998);let _0x2cfaab=_0x1eecdf?.[_0x32a01e(0x127)]?.[0x0]?.[_0x32a01e(0x107)];if(typeof _0x2cfaab!==_0x32a01e(0x149))return null;try{let _0x6f4934=JSON[_0x32a01e(0x13c)](_0x2cfaab);return _0x6f4934?.['task_id']||_0x6f4934?.['message_id']||_0x6f4934?.['id']||null;}catch{return null;}}async function X(_0x34a722,_0x2f5e2c){const _0x3a0a88=a0_0x28c511;let _0x1de216=_0x2f5e2c[_0x3a0a88(0x120)]??Date[_0x3a0a88(0x120)],_0x2ddaa4=_0x1de216(),_0x5696d0=(_0xa580a2,_0xfbf85c,_0x1ed01c,_0x19d711)=>{const _0x182cfa=_0x3a0a88;_0x2f5e2c[_0x182cfa(0x140)](O(U({'from_alias':_0x34a722[_0x182cfa(0x136)],'to_alias':_0x34a722[_0x182cfa(0x10c)],'task_id':_0xfbf85c,'parent_task_id':_0x34a722[_0x182cfa(0x187)],'network_id':_0x34a722[_0x182cfa(0x152)],'transport':_0x34a722[_0x182cfa(0x17a)],'status':_0xa580a2,'duration_ms':_0x1de216()-_0x2ddaa4,'lifecycle_tracking':_0x34a722[_0x182cfa(0x161)],..._0x1ed01c!==void 0x0?{'error_code':_0x19d711||_0x182cfa(0x13d),'error_message':N(_0x1ed01c)}:{}})));};_0x5696d0(_0x3a0a88(0x144),null);try{let _0x3a3bd9=await _0x2f5e2c['send'](),_0x49122d=j(_0x3a3bd9);if(_0x49122d)_0x5696d0(_0x3a0a88(0x151),_0x49122d);else{if(_0x3a3bd9?.['ok']===!0x1||_0x3a3bd9?.['error'])_0x5696d0(_0x3a0a88(0x141),_0x49122d,_0x3a3bd9?.[_0x3a0a88(0x153)]||_0x3a0a88(0x137),_0x3a0a88(0x18c));else _0x5696d0(_0x3a0a88(0x141),null,_0x3a0a88(0x12f),_0x3a0a88(0x132));}return _0x3a3bd9;}catch(_0x1cca9b){throw _0x5696d0(_0x3a0a88(0x141),null,_0x1cca9b,_0x3a0a88(0x13d)),_0x1cca9b;}}async function Y(_0x304481,_0x663be1){const _0x52a247=a0_0x28c511;return X({'fromAlias':_0x304481['fromAlias'],'toAlias':_0x304481[_0x52a247(0x16b)],'parentTaskId':_0x304481[_0x52a247(0x187)]||null,'networkId':_0x304481[_0x52a247(0x152)]||null,'transport':_0x52a247(0x16a),'lifecycleTracking':'not_tracked'},_0x663be1);}class $ extends a0_0x2943b2{[a0_0x28c511(0x13a)];[a0_0x28c511(0x16b)];[a0_0x28c511(0x184)];[a0_0x28c511(0x108)];[a0_0x28c511(0x12a)];[a0_0x28c511(0x17b)];['reconnectDelay'];[a0_0x28c511(0x17e)];[a0_0x28c511(0x170)];[a0_0x28c511(0x10d)]=!0x1;constructor(_0x51ce56){const _0xb17e8c=a0_0x28c511;super();if(this[_0xb17e8c(0x13a)]=_0x51ce56[_0xb17e8c(0x13a)][_0xb17e8c(0x183)](/\/$/,''),this[_0xb17e8c(0x16b)]=_0x51ce56[_0xb17e8c(0x16b)],this['token']=_0x51ce56[_0xb17e8c(0x184)],this['agent']=_0x51ce56[_0xb17e8c(0x108)]||_0xb17e8c(0x111),this[_0xb17e8c(0x12a)]=_0xb17e8c(0x10a)+_0x51ce56[_0xb17e8c(0x16b)]+'-'+Date[_0xb17e8c(0x120)]()[_0xb17e8c(0x148)](0x24),this[_0xb17e8c(0x17b)]=_0x51ce56['heartbeatInterval']??0x2bf20,this['reconnectDelay']=_0x51ce56[_0xb17e8c(0x166)]??0xbb8,_0x51ce56[_0xb17e8c(0x162)]!==!0x1)this[_0xb17e8c(0x11e)]();}[a0_0x28c511(0x140)](_0x187f2e){const _0x4f647e=a0_0x28c511;console[_0x4f647e(0x140)]('['+new Date()[_0x4f647e(0x181)]()[_0x4f647e(0x155)](0x0,0x8)+_0x4f647e(0x13b)+this[_0x4f647e(0x16b)]+']\x20'+_0x187f2e);}async[a0_0x28c511(0x15a)](_0xa3b5cc,_0x1debd7){const _0x4ebe78=a0_0x28c511;let _0x2e22b4={'Content-Type':'application/json','Accept':_0x4ebe78(0x11d)};if(this[_0x4ebe78(0x184)])_0x2e22b4['Authorization']='Bearer\x20'+this[_0x4ebe78(0x184)];let _0x59685a=await(await fetch(this[_0x4ebe78(0x13a)]+_0x4ebe78(0x13e),{'method':_0x4ebe78(0x12c),'headers':_0x2e22b4,'body':JSON[_0x4ebe78(0x179)]({'jsonrpc':_0x4ebe78(0x157),'id':Date['now'](),'method':_0x4ebe78(0x115),'params':{'name':_0xa3b5cc,'arguments':_0x1debd7}})}))[_0x4ebe78(0x107)](),_0x393432=_0x59685a['match'](/data: (.+)/),_0x14af7a=_0x393432?JSON['parse'](_0x393432[0x1]):JSON[_0x4ebe78(0x13c)](_0x59685a),_0x596eda=_0x14af7a?.[_0x4ebe78(0x186)]?.['content']?.[0x0]?.['text'];return _0x596eda?JSON[_0x4ebe78(0x13c)](_0x596eda):_0x14af7a;}async[a0_0x28c511(0x11e)](){const _0x18e5d3=a0_0x28c511;if(this[_0x18e5d3(0x10d)])return;this[_0x18e5d3(0x10d)]=!0x0,await this[_0x18e5d3(0x133)](_0x18e5d3(0x131)),this[_0x18e5d3(0x140)](_0x18e5d3(0x178)),this['heartbeatTimer']=setInterval(()=>{const _0x4a70a5=_0x18e5d3;this[_0x4a70a5(0x133)](_0x4a70a5(0x131))[_0x4a70a5(0x147)](_0x34434a=>this['log'](_0x4a70a5(0x14b)+_0x34434a[_0x4a70a5(0x15d)]));},this['heartbeatInterval']),this[_0x18e5d3(0x11f)]();}async[a0_0x28c511(0x146)](){const _0x5b271b=a0_0x28c511;if(this[_0x5b271b(0x10d)]=!0x1,this[_0x5b271b(0x170)]?.['abort'](),this['heartbeatTimer'])clearInterval(this[_0x5b271b(0x17e)]);await this['status'](_0x5b271b(0x110))[_0x5b271b(0x147)](()=>{}),this[_0x5b271b(0x140)](_0x5b271b(0x160));}async[a0_0x28c511(0x14f)](_0x3b8b06,_0x58753c,_0x2e7c3c=a0_0x28c511(0x125)){const _0x34ebb9=a0_0x28c511;return Y({'alias':_0x3b8b06,'fromAlias':this['alias']},{'log':_0xdb9da5=>console[_0x34ebb9(0x140)](_0xdb9da5),'send':()=>this[_0x34ebb9(0x15a)](_0x34ebb9(0x11c),{'alias':_0x3b8b06,'task':_0x58753c,'priority':_0x2e7c3c,'from_session':this[_0x34ebb9(0x16b)]})});}async['message'](_0x454897,_0x4c76aa){const _0x5c278d=a0_0x28c511;return this[_0x5c278d(0x15a)](_0x5c278d(0x116),{'alias':_0x454897,'message':_0x4c76aa,'from_session':this[_0x5c278d(0x16b)]});}async[a0_0x28c511(0x154)](_0x4b711e,_0x3adc68,_0x5d76d7=a0_0x28c511(0x124)){const _0x58ddd2=a0_0x28c511;return this[_0x58ddd2(0x15a)](_0x58ddd2(0x176),{'in_reply_to':_0x4b711e,'text':_0x3adc68,'status':_0x5d76d7});}async[a0_0x28c511(0x133)](_0x778395,_0x138a4e){const _0x423d9b=a0_0x28c511;return this['call'](_0x423d9b(0x180),{'resume_id':this['resumeId'],'alias':this[_0x423d9b(0x16b)],'status':_0x778395,'server':a0_0x5e652b(),'hostname':a0_0x5e652b(),'agent':this[_0x423d9b(0x108)],'project_dir':process[_0x423d9b(0x135)](),..._0x138a4e});}async[a0_0x28c511(0x169)](){const _0x129ba3=a0_0x28c511;return this[_0x129ba3(0x15a)](_0x129ba3(0x121),{});}async[a0_0x28c511(0x173)](_0x37262b,_0x3bd4a7){const _0x58f870=a0_0x28c511;return this[_0x58f870(0x15a)]('broadcast',{'message':_0x37262b,'filter_server':_0x3bd4a7?.['server'],'filter_status':_0x3bd4a7?.['status']});}async[a0_0x28c511(0x11f)](){const _0x558a99=a0_0x28c511;let _0x20a9ff=encodeURIComponent(this[_0x558a99(0x16b)]),_0xecb907=this[_0x558a99(0x13a)]+_0x558a99(0x171)+_0x20a9ff,_0x47ec6a=this[_0x558a99(0x166)];while(this['running']){try{this['sseAbort']=new AbortController();let _0x57c34d={'Accept':_0x558a99(0x11a)};if(this[_0x558a99(0x184)])_0x57c34d[_0x558a99(0x163)]=_0x558a99(0x128)+this[_0x558a99(0x184)];let _0x137206=await fetch(_0xecb907,{'headers':_0x57c34d,'signal':this[_0x558a99(0x170)][_0x558a99(0x143)]});if(!_0x137206['ok']||!_0x137206[_0x558a99(0x174)]){this[_0x558a99(0x140)](_0x558a99(0x142)+_0x137206['status']),await this[_0x558a99(0x15c)](_0x47ec6a),_0x47ec6a=Math[_0x558a99(0x123)](_0x47ec6a*1.5,0xea60);continue;}_0x47ec6a=this[_0x558a99(0x166)];let _0x433f02=_0x137206[_0x558a99(0x174)][_0x558a99(0x13f)](),_0x3ac52f=new TextDecoder(),_0x2e485f='';while(this[_0x558a99(0x10d)]){let {done:_0x1329d0,value:_0x20018c}=await _0x433f02[_0x558a99(0x14d)]();if(_0x1329d0)break;_0x2e485f+=_0x3ac52f[_0x558a99(0x114)](_0x20018c,{'stream':!0x0});let _0x26a4f8=_0x2e485f[_0x558a99(0x15e)]('\x0a');_0x2e485f=_0x26a4f8[_0x558a99(0x16c)]()||'';for(let _0x896487 of _0x26a4f8){if(!_0x896487['startsWith']('data:\x20'))continue;try{let _0xbdd4f0=JSON[_0x558a99(0x13c)](_0x896487['slice'](0x6));if(_0xbdd4f0[_0x558a99(0x150)]===_0x558a99(0x117)){this[_0x558a99(0x140)](_0x558a99(0x158)),this[_0x558a99(0x11b)](_0x558a99(0x117));continue;}if(_0xbdd4f0[_0x558a99(0x150)]===_0x558a99(0x168)||_0xbdd4f0['type']===_0x558a99(0x119)||_0xbdd4f0[_0x558a99(0x150)]==='broadcast')await this[_0x558a99(0x14c)]();}catch{}}}}catch(_0x1aa62f){if(_0x1aa62f['name']===_0x558a99(0x172))break;this[_0x558a99(0x11b)]('error',_0x1aa62f),this['log']('SSE\x20error:\x20'+_0x1aa62f[_0x558a99(0x15d)]);}if(this['running'])this[_0x558a99(0x11b)](_0x558a99(0x160)),this[_0x558a99(0x140)](_0x558a99(0x10b)+_0x47ec6a/0x3e8+'s...'),await this[_0x558a99(0x15c)](_0x47ec6a),_0x47ec6a=Math[_0x558a99(0x123)](_0x47ec6a*1.5,0xea60);}}async[a0_0x28c511(0x14c)](){const _0x337f79=a0_0x28c511;try{let _0x24ccd5=(await this['call'](_0x337f79(0x18e),{'alias':this['alias'],'limit':0xa}))?.[_0x337f79(0x12e)]||[];for(let _0x316e96 of _0x24ccd5)await this[_0x337f79(0x15a)]('ack_inbox',{'alias':this['alias'],'message_id':_0x316e96['id']}),this['log']('←\x20'+_0x316e96[_0x337f79(0x15b)]+':\x20'+_0x316e96[_0x337f79(0x127)]['slice'](0x0,0x3c)),this[_0x337f79(0x11b)](_0x337f79(0x188),_0x316e96),this[_0x337f79(0x11b)](_0x337f79(0x15d),_0x316e96);}catch(_0x5319a2){this['log']('inbox\x20error:\x20'+_0x5319a2[_0x337f79(0x15d)]);}}[a0_0x28c511(0x15c)](_0x3dfbc9){return new Promise(_0x12da72=>setTimeout(_0x12da72,_0x3dfbc9));}}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;