@sleep2agi/agent-network 2.3.0-preview.47 → 2.3.0-preview.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/src/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const a0_0x240860=a0_0xfa02;(function(_0x1d8ce7,_0x619d2b){const _0x491374=a0_0xfa02,_0x2d1699=_0x1d8ce7();while(!![]){try{const _0x259bd5=parseInt(_0x491374(0x10b))/0x1+-parseInt(_0x491374(0x155))/0x2*(-parseInt(_0x491374(0x103))/0x3)+parseInt(_0x491374(0xee))/0x4+-parseInt(_0x491374(0x156))/0x5*(-parseInt(_0x491374(0x14b))/0x6)+parseInt(_0x491374(0xfb))/0x7+parseInt(_0x491374(0xef))/0x8*(-parseInt(_0x491374(0xfa))/0x9)+-parseInt(_0x491374(0x141))/0xa;if(_0x259bd5===_0x619d2b)break;else _0x2d1699['push'](_0x2d1699['shift']());}catch(_0x496f67){_0x2d1699['push'](_0x2d1699['shift']());}}}(a0_0x3927,0xd672b));import{EventEmitter as a0_0x59ad8d}from'events';import{hostname as a0_0x11444b}from'os';var _=/(?:atok|ntok|utok|ghp|github_pat)_[A-Za-z0-9_-]+|Bearer\s+\S+/gi,c=(_0x461794,_0x2c070c)=>(_0x461794??_0x2c070c)[a0_0x240860(0x11a)](/[\r\n\x00-\x1f\x7f]/g,'\x20')[a0_0x240860(0xeb)](0x0,0xf0);function T(_0x110129){const _0x45541f=a0_0x240860;return(_0x110129 instanceof Error?_0x110129['message']:String(_0x110129??_0x45541f(0x153)))[_0x45541f(0x11a)](_,'[REDACTED]')[_0x45541f(0x11a)](/[\r\n\x00-\x1f\x7f]/g,'\x20')['slice'](0x0,0xf0);}function a0_0x3927(){const _0x50f72f=['fromAlias','delivered','network_id','<missing>','stringify','type','body','decode','CommHub\x20rejected\x20task','min','s...','name','application/json,\x20text/event-stream','parentTaskId','Authorization','getAllStatus','/events/','task.send.start','AbortError','send_rejected','task.ack','sdk-','status','task.replied','send_reply','sseAbort','SSE\x20connected','data:\x20','agent','url','\x20duration_ms=','mcp_http','53074740PLeqkJ','send','error','emit','running','connect','text/event-stream','<pending>','\x20lifecycle=','error_code','10462998TnCzyK','connectSSE','\x20from=','task_id','2.0','string','cwd','disconnected','unknown\x20error','from_alias','2780714bjthvK','5GkBhPn','broadcast','SSE\x20failed:\x20','failed','\x20to=','text','task.send.delivered','toAlias','abort','pop','send_message','split','task.send.failed','heartbeatInterval','SSE\x20reconnecting\x20in\x20','message','content','slice','new_message','transport','6488752vsdIXR','12248LvlAOU','signal','match','disconnect','completed',']\x20[commhub:','token','\x20task_id=','task.expired','sleep','alias','5562JvyHjd','9424828JFssXf','now','parse','getReader','messages','networkId','lifecycle_tracking','sdk','3izNcEU','duration_ms','send_failed','CommHub\x20response\x20omitted\x20task_id','missing_task_id','get_inbox','lifecycleTracking','[commhub:task]\x20','1029229CfQMas','to_alias','message_id','get_all_status','heartbeat\x20failed:\x20','call','inbox\x20error:\x20','<unknown>','log','Bearer\x20','heartbeatTimer','read','\x20network_id=','toTimeString','reconnectDelay','replace','SSE\x20error:\x20','task','new_task','resumeId','registered','sending'];a0_0x3927=function(){return _0x50f72f;};return a0_0x3927();}function y(_0x50dd5b,_0x26c289=process.env.ANET_TASK_TRACE_FORMAT==='json'){const _0x46a26e=a0_0x240860;if(_0x26c289)return JSON[_0x46a26e(0x125)](_0x50dd5b);let _0x156ad9=c(_0x50dd5b['parent_task_id'],_0x46a26e(0x124)),_0x136b5b=c(_0x50dd5b['task_id'],_0x46a26e(0x148)),_0x5bf3ba=_0x50dd5b[_0x46a26e(0x14a)]?'\x20error='+_0x50dd5b[_0x46a26e(0x14a)]+':'+(_0x50dd5b['error_message']??''):'';return _0x46a26e(0x10a)+_0x50dd5b['status']+_0x46a26e(0x14d)+c(_0x50dd5b[_0x46a26e(0x154)],_0x46a26e(0x112))+_0x46a26e(0x15a)+c(_0x50dd5b[_0x46a26e(0x10c)],'<unknown>')+_0x46a26e(0xf6)+_0x136b5b+'\x20parent_task_id='+_0x156ad9+_0x46a26e(0x117)+c(_0x50dd5b[_0x46a26e(0x123)],_0x46a26e(0x112))+'\x20transport='+_0x50dd5b[_0x46a26e(0xed)]+_0x46a26e(0x13f)+_0x50dd5b[_0x46a26e(0x104)]+_0x46a26e(0x149)+_0x50dd5b[_0x46a26e(0x101)]+_0x5bf3ba;}function b(_0x309e22){const _0x3e8a2e=a0_0x240860;return{'event':{'sending':_0x3e8a2e(0x132),'delivered':_0x3e8a2e(0x15c),'failed':_0x3e8a2e(0x162),'acked':_0x3e8a2e(0x135),'started':'task.started','replied':_0x3e8a2e(0x138),'expired':_0x3e8a2e(0xf7)}[_0x309e22[_0x3e8a2e(0x137)]],..._0x309e22};}function w(_0x485425){const _0x24dc5a=a0_0x240860;let _0x55ef2b=_0x485425?.[_0x24dc5a(0x14e)]||_0x485425?.['message_id']||_0x485425?.['id'];if(_0x55ef2b)return String(_0x55ef2b);let _0x30b2b4=_0x485425?.[_0x24dc5a(0xea)]?.[0x0]?.['text'];if(typeof _0x30b2b4!==_0x24dc5a(0x150))return null;try{let _0x1798c=JSON[_0x24dc5a(0xfd)](_0x30b2b4);return _0x1798c?.[_0x24dc5a(0x14e)]||_0x1798c?.[_0x24dc5a(0x10d)]||_0x1798c?.['id']||null;}catch{return null;}}async function h(_0x45f05f,_0x524841){const _0x5ae68a=a0_0x240860;let _0x5ea059=_0x524841[_0x5ae68a(0xfc)]??Date[_0x5ae68a(0xfc)],_0x133027=_0x5ea059(),_0x4936d7=(_0x33de68,_0x5a571c,_0x41691c,_0xf327e9)=>{const _0x291d1f=_0x5ae68a;_0x524841['log'](y(b({'from_alias':_0x45f05f[_0x291d1f(0x121)],'to_alias':_0x45f05f[_0x291d1f(0x15d)],'task_id':_0x5a571c,'parent_task_id':_0x45f05f[_0x291d1f(0x12e)],'network_id':_0x45f05f[_0x291d1f(0x100)],'transport':_0x45f05f['transport'],'status':_0x33de68,'duration_ms':_0x5ea059()-_0x133027,'lifecycle_tracking':_0x45f05f[_0x291d1f(0x109)],..._0x41691c!==void 0x0?{'error_code':_0xf327e9||_0x291d1f(0x105),'error_message':T(_0x41691c)}:{}})));};_0x4936d7(_0x5ae68a(0x120),null);try{let _0x532c49=await _0x524841['send'](),_0x271066=w(_0x532c49);if(_0x271066)_0x4936d7(_0x5ae68a(0x122),_0x271066);else{if(_0x532c49?.['ok']===!0x1||_0x532c49?.[_0x5ae68a(0x143)])_0x4936d7('failed',_0x271066,_0x532c49?.[_0x5ae68a(0x143)]||_0x5ae68a(0x129),_0x5ae68a(0x134));else _0x4936d7(_0x5ae68a(0x159),null,_0x5ae68a(0x106),_0x5ae68a(0x107));}return _0x532c49;}catch(_0x54d25c){throw _0x4936d7(_0x5ae68a(0x159),null,_0x54d25c,_0x5ae68a(0x105)),_0x54d25c;}}function a0_0xfa02(_0x5ea432,_0x4d7ff6){_0x5ea432=_0x5ea432-0xe8;const _0x392711=a0_0x3927();let _0xfa0231=_0x392711[_0x5ea432];return _0xfa0231;}async function u(_0x58ded2,_0x4e8d76){const _0x46835b=a0_0x240860;return h({'fromAlias':_0x58ded2[_0x46835b(0x121)],'toAlias':_0x58ded2[_0x46835b(0xf9)],'parentTaskId':_0x58ded2[_0x46835b(0x12e)]||null,'networkId':_0x58ded2['networkId']||null,'transport':_0x46835b(0x140),'lifecycleTracking':'not_tracked'},_0x4e8d76);}class k extends a0_0x59ad8d{['url'];[a0_0x240860(0xf9)];[a0_0x240860(0xf5)];[a0_0x240860(0x13d)];['resumeId'];[a0_0x240860(0x163)];[a0_0x240860(0x119)];[a0_0x240860(0x115)];['sseAbort'];[a0_0x240860(0x145)]=!0x1;constructor(_0x550012){const _0x565047=a0_0x240860;super();if(this[_0x565047(0x13e)]=_0x550012[_0x565047(0x13e)][_0x565047(0x11a)](/\/$/,''),this['alias']=_0x550012['alias'],this[_0x565047(0xf5)]=_0x550012['token'],this[_0x565047(0x13d)]=_0x550012[_0x565047(0x13d)]||_0x565047(0x102),this[_0x565047(0x11e)]=_0x565047(0x136)+_0x550012['alias']+'-'+Date[_0x565047(0xfc)]()['toString'](0x24),this[_0x565047(0x163)]=_0x550012['heartbeatInterval']??0x2bf20,this[_0x565047(0x119)]=_0x550012[_0x565047(0x119)]??0xbb8,_0x550012['autoConnect']!==!0x1)this['connect']();}[a0_0x240860(0x113)](_0x4b788e){const _0x5428ea=a0_0x240860;console[_0x5428ea(0x113)]('['+new Date()[_0x5428ea(0x118)]()['slice'](0x0,0x8)+_0x5428ea(0xf4)+this[_0x5428ea(0xf9)]+']\x20'+_0x4b788e);}async[a0_0x240860(0x110)](_0x1e3ef4,_0x5d3248){const _0xe8bd55=a0_0x240860;let _0x5154b4={'Content-Type':'application/json','Accept':_0xe8bd55(0x12d)};if(this[_0xe8bd55(0xf5)])_0x5154b4[_0xe8bd55(0x12f)]=_0xe8bd55(0x114)+this[_0xe8bd55(0xf5)];let _0x5e1651=await(await fetch(this[_0xe8bd55(0x13e)]+'/mcp',{'method':'POST','headers':_0x5154b4,'body':JSON['stringify']({'jsonrpc':_0xe8bd55(0x14f),'id':Date[_0xe8bd55(0xfc)](),'method':'tools/call','params':{'name':_0x1e3ef4,'arguments':_0x5d3248}})}))[_0xe8bd55(0x15b)](),_0x2a9e3e=_0x5e1651[_0xe8bd55(0xf1)](/data: (.+)/),_0x2a46f7=_0x2a9e3e?JSON[_0xe8bd55(0xfd)](_0x2a9e3e[0x1]):JSON[_0xe8bd55(0xfd)](_0x5e1651),_0x1b5d6e=_0x2a46f7?.['result']?.[_0xe8bd55(0xea)]?.[0x0]?.['text'];return _0x1b5d6e?JSON[_0xe8bd55(0xfd)](_0x1b5d6e):_0x2a46f7;}async[a0_0x240860(0x146)](){const _0x53d85d=a0_0x240860;if(this[_0x53d85d(0x145)])return;this[_0x53d85d(0x145)]=!0x0,await this[_0x53d85d(0x137)]('idle'),this['log'](_0x53d85d(0x11f)),this[_0x53d85d(0x115)]=setInterval(()=>{const _0x18ced7=_0x53d85d;this['status']('idle')['catch'](_0x5a727d=>this[_0x18ced7(0x113)](_0x18ced7(0x10f)+_0x5a727d[_0x18ced7(0xe9)]));},this[_0x53d85d(0x163)]),this[_0x53d85d(0x14c)]();}async[a0_0x240860(0xf2)](){const _0xa20671=a0_0x240860;if(this[_0xa20671(0x145)]=!0x1,this['sseAbort']?.[_0xa20671(0x15e)](),this['heartbeatTimer'])clearInterval(this[_0xa20671(0x115)]);await this[_0xa20671(0x137)]('offline')['catch'](()=>{}),this['log'](_0xa20671(0x152));}async[a0_0x240860(0x142)](_0x1df799,_0x2f4ba3,_0x35e566='normal'){const _0x583976=a0_0x240860;return u({'alias':_0x1df799,'fromAlias':this[_0x583976(0xf9)]},{'log':_0x4be846=>console[_0x583976(0x113)](_0x4be846),'send':()=>this[_0x583976(0x110)]('send_task',{'alias':_0x1df799,'task':_0x2f4ba3,'priority':_0x35e566,'from_session':this[_0x583976(0xf9)]})});}async[a0_0x240860(0xe9)](_0x47dfc0,_0x974a6c){const _0x34ed86=a0_0x240860;return this[_0x34ed86(0x110)](_0x34ed86(0x160),{'alias':_0x47dfc0,'message':_0x974a6c,'from_session':this[_0x34ed86(0xf9)]});}async['reply'](_0x153e61,_0x4ca25c,_0x3d1304=a0_0x240860(0xf3)){const _0x44489e=a0_0x240860;return this[_0x44489e(0x110)](_0x44489e(0x139),{'in_reply_to':_0x153e61,'text':_0x4ca25c,'status':_0x3d1304});}async[a0_0x240860(0x137)](_0x5e13a5,_0x5ebc83){const _0xf8a758=a0_0x240860;return this['call']('report_status',{'resume_id':this[_0xf8a758(0x11e)],'alias':this[_0xf8a758(0xf9)],'status':_0x5e13a5,'server':a0_0x11444b(),'hostname':a0_0x11444b(),'agent':this[_0xf8a758(0x13d)],'project_dir':process[_0xf8a758(0x151)](),..._0x5ebc83});}async[a0_0x240860(0x130)](){const _0x14c30d=a0_0x240860;return this[_0x14c30d(0x110)](_0x14c30d(0x10e),{});}async[a0_0x240860(0x157)](_0x36d094,_0x2e3e57){const _0x149bb8=a0_0x240860;return this[_0x149bb8(0x110)](_0x149bb8(0x157),{'message':_0x36d094,'filter_server':_0x2e3e57?.['server'],'filter_status':_0x2e3e57?.[_0x149bb8(0x137)]});}async['connectSSE'](){const _0x26ff5c=a0_0x240860;let _0x15c140=encodeURIComponent(this[_0x26ff5c(0xf9)]),_0x58c2b5=this['url']+_0x26ff5c(0x131)+_0x15c140,_0x30a412=this[_0x26ff5c(0x119)];while(this[_0x26ff5c(0x145)]){try{this[_0x26ff5c(0x13a)]=new AbortController();let _0x4e5ea9={'Accept':_0x26ff5c(0x147)};if(this[_0x26ff5c(0xf5)])_0x4e5ea9[_0x26ff5c(0x12f)]=_0x26ff5c(0x114)+this[_0x26ff5c(0xf5)];let _0x511bf7=await fetch(_0x58c2b5,{'headers':_0x4e5ea9,'signal':this[_0x26ff5c(0x13a)][_0x26ff5c(0xf0)]});if(!_0x511bf7['ok']||!_0x511bf7[_0x26ff5c(0x127)]){this[_0x26ff5c(0x113)](_0x26ff5c(0x158)+_0x511bf7[_0x26ff5c(0x137)]),await this['sleep'](_0x30a412),_0x30a412=Math[_0x26ff5c(0x12a)](_0x30a412*1.5,0xea60);continue;}_0x30a412=this['reconnectDelay'];let _0x38fecf=_0x511bf7[_0x26ff5c(0x127)][_0x26ff5c(0xfe)](),_0x2f9bfb=new TextDecoder(),_0x24607d='';while(this[_0x26ff5c(0x145)]){let {done:_0x1d6c6c,value:_0x26bf96}=await _0x38fecf[_0x26ff5c(0x116)]();if(_0x1d6c6c)break;_0x24607d+=_0x2f9bfb[_0x26ff5c(0x128)](_0x26bf96,{'stream':!0x0});let _0x37a360=_0x24607d[_0x26ff5c(0x161)]('\x0a');_0x24607d=_0x37a360[_0x26ff5c(0x15f)]()||'';for(let _0x48fdad of _0x37a360){if(!_0x48fdad['startsWith'](_0x26ff5c(0x13c)))continue;try{let _0x3cd990=JSON[_0x26ff5c(0xfd)](_0x48fdad[_0x26ff5c(0xeb)](0x6));if(_0x3cd990[_0x26ff5c(0x126)]==='connected'){this['log'](_0x26ff5c(0x13b)),this[_0x26ff5c(0x144)]('connected');continue;}if(_0x3cd990[_0x26ff5c(0x126)]===_0x26ff5c(0x11d)||_0x3cd990[_0x26ff5c(0x126)]===_0x26ff5c(0xec)||_0x3cd990[_0x26ff5c(0x126)]===_0x26ff5c(0x157))await this['processInbox']();}catch{}}}}catch(_0x4b0e70){if(_0x4b0e70[_0x26ff5c(0x12c)]===_0x26ff5c(0x133))break;this[_0x26ff5c(0x144)](_0x26ff5c(0x143),_0x4b0e70),this[_0x26ff5c(0x113)](_0x26ff5c(0x11b)+_0x4b0e70['message']);}if(this[_0x26ff5c(0x145)])this['emit'](_0x26ff5c(0x152)),this[_0x26ff5c(0x113)](_0x26ff5c(0xe8)+_0x30a412/0x3e8+_0x26ff5c(0x12b)),await this[_0x26ff5c(0xf8)](_0x30a412),_0x30a412=Math[_0x26ff5c(0x12a)](_0x30a412*1.5,0xea60);}}async['processInbox'](){const _0xae381d=a0_0x240860;try{let _0x12eb26=(await this['call'](_0xae381d(0x108),{'alias':this[_0xae381d(0xf9)],'limit':0xa}))?.[_0xae381d(0xff)]||[];for(let _0x12e458 of _0x12eb26)await this[_0xae381d(0x110)]('ack_inbox',{'alias':this[_0xae381d(0xf9)],'message_id':_0x12e458['id']}),this['log']('←\x20'+_0x12e458['from_session']+':\x20'+_0x12e458['content'][_0xae381d(0xeb)](0x0,0x3c)),this[_0xae381d(0x144)](_0xae381d(0x11c),_0x12e458),this[_0xae381d(0x144)]('message',_0x12e458);}catch(_0x4ab21f){this[_0xae381d(0x113)](_0xae381d(0x111)+_0x4ab21f[_0xae381d(0xe9)]);}}[a0_0x240860(0xf8)](_0x3f5ab1){return new Promise(_0x4560de=>setTimeout(_0x4560de,_0x3f5ab1));}}var O=k;export{k as CommHub,O as default};
|
|
1
|
+
const a0_0xd22e14=a0_0x577f;function a0_0x577f(_0x156dac,_0x221cfe){_0x156dac=_0x156dac-0xc0;const _0x58dd58=a0_0x58dd();let _0x577f53=_0x58dd58[_0x156dac];return _0x577f53;}(function(_0x1d1314,_0x3f478f){const _0x53d495=a0_0x577f,_0x70bc36=_0x1d1314();while(!![]){try{const _0x4994aa=parseInt(_0x53d495(0xe8))/0x1*(-parseInt(_0x53d495(0xde))/0x2)+-parseInt(_0x53d495(0xe0))/0x3+parseInt(_0x53d495(0xc0))/0x4+parseInt(_0x53d495(0xe4))/0x5*(-parseInt(_0x53d495(0xc3))/0x6)+-parseInt(_0x53d495(0x11a))/0x7*(parseInt(_0x53d495(0x130))/0x8)+parseInt(_0x53d495(0x10d))/0x9*(parseInt(_0x53d495(0xd9))/0xa)+parseInt(_0x53d495(0x12a))/0xb*(parseInt(_0x53d495(0xf2))/0xc);if(_0x4994aa===_0x3f478f)break;else _0x70bc36['push'](_0x70bc36['shift']());}catch(_0x1d1526){_0x70bc36['push'](_0x70bc36['shift']());}}}(a0_0x58dd,0x7d31a));import{EventEmitter as a0_0x434893}from'events';import{hostname as a0_0x73d679}from'os';var K=/(?:atok|ntok|utok|ghp|github_pat)_[A-Za-z0-9_-]+|Bearer\s+\S+/gi,L=(_0x49931b,_0x4be464)=>(_0x49931b??_0x4be464)[a0_0xd22e14(0xf5)](/[\r\n\x00-\x1f\x7f]/g,'\x20')[a0_0xd22e14(0x11e)](0x0,0xf0);function N(_0x225e09){const _0xc06f7f=a0_0xd22e14;return(_0x225e09 instanceof Error?_0x225e09['message']:String(_0x225e09??_0xc06f7f(0x10e)))[_0xc06f7f(0xf5)](K,_0xc06f7f(0xc8))[_0xc06f7f(0xf5)](/[\r\n\x00-\x1f\x7f]/g,'\x20')[_0xc06f7f(0x11e)](0x0,0xf0);}function O(_0x4c6b1c,_0x13ddeb=process.env.ANET_TASK_TRACE_FORMAT===a0_0xd22e14(0x138)){const _0x4d3752=a0_0xd22e14;if(_0x13ddeb)return JSON['stringify'](_0x4c6b1c);let _0x55df5b=L(_0x4c6b1c[_0x4d3752(0xce)],_0x4d3752(0xf7)),_0x38d669=L(_0x4c6b1c[_0x4d3752(0xc4)],'<pending>'),_0xd005f9=_0x4c6b1c['error_code']?_0x4d3752(0xd6)+_0x4c6b1c['error_code']+':'+(_0x4c6b1c[_0x4d3752(0x106)]??''):'';return _0x4d3752(0xcd)+_0x4c6b1c[_0x4d3752(0xdb)]+'\x20from='+L(_0x4c6b1c['from_alias'],_0x4d3752(0xc7))+'\x20to='+L(_0x4c6b1c[_0x4d3752(0x108)],_0x4d3752(0xc7))+_0x4d3752(0xe6)+_0x38d669+_0x4d3752(0xc2)+_0x55df5b+_0x4d3752(0x132)+L(_0x4c6b1c[_0x4d3752(0x102)],_0x4d3752(0xc7))+_0x4d3752(0x126)+_0x4c6b1c[_0x4d3752(0xe7)]+'\x20duration_ms='+_0x4c6b1c['duration_ms']+_0x4d3752(0x120)+_0x4c6b1c[_0x4d3752(0x12c)]+_0xd005f9;}function U(_0x6ca7c7){const _0x49fb70=a0_0xd22e14;return{'event':{'sending':_0x49fb70(0x133),'delivered':_0x49fb70(0xdd),'failed':_0x49fb70(0xf0),'acked':_0x49fb70(0xcf),'started':_0x49fb70(0xd8),'replied':_0x49fb70(0xc5),'expired':_0x49fb70(0xfd)}[_0x6ca7c7['status']],..._0x6ca7c7};}function j(_0x3a2405){const _0x84511=a0_0xd22e14;let _0x15e4ae=_0x3a2405?.[_0x84511(0xc4)]||_0x3a2405?.[_0x84511(0x105)]||_0x3a2405?.['id'];if(_0x15e4ae)return String(_0x15e4ae);let _0x38bd0a=_0x3a2405?.[_0x84511(0xfe)]?.[0x0]?.[_0x84511(0x121)];if(typeof _0x38bd0a!==_0x84511(0xef))return null;try{let _0x2cbf5e=JSON[_0x84511(0x10f)](_0x38bd0a);return _0x2cbf5e?.[_0x84511(0xc4)]||_0x2cbf5e?.[_0x84511(0x105)]||_0x2cbf5e?.['id']||null;}catch{return null;}}async function X(_0xd13016,_0x1d4f7f){const _0x1dfacb=a0_0xd22e14;let _0x5080cb=_0x1d4f7f[_0x1dfacb(0xd3)]??Date[_0x1dfacb(0xd3)],_0x390743=_0x5080cb(),_0x1f1bbc=(_0x32b5b5,_0x43e76b,_0x2e3713,_0x553098)=>{const _0x10b7c9=_0x1dfacb;_0x1d4f7f[_0x10b7c9(0xf8)](O(U({'from_alias':_0xd13016[_0x10b7c9(0x114)],'to_alias':_0xd13016[_0x10b7c9(0xf1)],'task_id':_0x43e76b,'parent_task_id':_0xd13016[_0x10b7c9(0xf9)],'network_id':_0xd13016['networkId'],'transport':_0xd13016['transport'],'status':_0x32b5b5,'duration_ms':_0x5080cb()-_0x390743,'lifecycle_tracking':_0xd13016['lifecycleTracking'],..._0x2e3713!==void 0x0?{'error_code':_0x553098||_0x10b7c9(0xe2),'error_message':N(_0x2e3713)}:{}})));};_0x1f1bbc('sending',null);try{let _0x68d09e=await _0x1d4f7f['send'](),_0x229ce2=j(_0x68d09e);if(_0x229ce2)_0x1f1bbc(_0x1dfacb(0x11d),_0x229ce2);else{if(_0x68d09e?.['ok']===!0x1||_0x68d09e?.[_0x1dfacb(0x113)])_0x1f1bbc('failed',_0x229ce2,_0x68d09e?.[_0x1dfacb(0x113)]||_0x1dfacb(0x11f),_0x1dfacb(0xc6));else _0x1f1bbc(_0x1dfacb(0x119),null,_0x1dfacb(0xcb),_0x1dfacb(0x136));}return _0x68d09e;}catch(_0x4008cf){throw _0x1f1bbc(_0x1dfacb(0x119),null,_0x4008cf,_0x1dfacb(0xe2)),_0x4008cf;}}async function Y(_0xd2358,_0x46a346){const _0x3f954f=a0_0xd22e14;return X({'fromAlias':_0xd2358['fromAlias'],'toAlias':_0xd2358[_0x3f954f(0x10c)],'parentTaskId':_0xd2358[_0x3f954f(0xf9)]||null,'networkId':_0xd2358[_0x3f954f(0xee)]||null,'transport':_0x3f954f(0xfc),'lifecycleTracking':_0x3f954f(0x10a)},_0x46a346);}class $ extends a0_0x434893{[a0_0xd22e14(0x139)];[a0_0xd22e14(0x10c)];[a0_0xd22e14(0x110)];['agent'];['resumeId'];['heartbeatInterval'];['reconnectDelay'];[a0_0xd22e14(0x122)];[a0_0xd22e14(0xfa)];[a0_0xd22e14(0x107)]=!0x1;constructor(_0x457a5){const _0x46f622=a0_0xd22e14;super();if(this['url']=_0x457a5['url'][_0x46f622(0xf5)](/\/$/,''),this[_0x46f622(0x10c)]=_0x457a5[_0x46f622(0x10c)],this[_0x46f622(0x110)]=_0x457a5[_0x46f622(0x110)],this['agent']=_0x457a5[_0x46f622(0x116)]||_0x46f622(0x12b),this[_0x46f622(0x129)]='sdk-'+_0x457a5[_0x46f622(0x10c)]+'-'+Date[_0x46f622(0xd3)]()[_0x46f622(0xd4)](0x24),this[_0x46f622(0xed)]=_0x457a5[_0x46f622(0xed)]??0x2bf20,this[_0x46f622(0xd2)]=_0x457a5['reconnectDelay']??0xbb8,_0x457a5[_0x46f622(0xfb)]!==!0x1)this['connect']();}[a0_0xd22e14(0xf8)](_0x348bf5){const _0x450c54=a0_0xd22e14;console['log']('['+new Date()['toTimeString']()[_0x450c54(0x11e)](0x0,0x8)+_0x450c54(0x100)+this[_0x450c54(0x10c)]+']\x20'+_0x348bf5);}async[a0_0xd22e14(0x124)](_0x22e6b3,_0x63d323){const _0x528471=a0_0xd22e14;let _0xec98f6={'Content-Type':_0x528471(0xd7),'Accept':'application/json,\x20text/event-stream'};if(this[_0x528471(0x110)])_0xec98f6[_0x528471(0x127)]=_0x528471(0xf3)+this[_0x528471(0x110)];let _0x20c434=await(await fetch(this[_0x528471(0x139)]+_0x528471(0x111),{'method':'POST','headers':_0xec98f6,'body':JSON['stringify']({'jsonrpc':_0x528471(0xec),'id':Date['now'](),'method':_0x528471(0x118),'params':{'name':_0x22e6b3,'arguments':_0x63d323}})}))[_0x528471(0x121)](),_0x7d56a5=_0x20c434[_0x528471(0xe5)](/data: (.+)/),_0x1923be=_0x7d56a5?JSON[_0x528471(0x10f)](_0x7d56a5[0x1]):JSON[_0x528471(0x10f)](_0x20c434),_0x512b5d=_0x1923be?.[_0x528471(0xd1)]?.[_0x528471(0xfe)]?.[0x0]?.['text'];return _0x512b5d?JSON[_0x528471(0x10f)](_0x512b5d):_0x1923be;}async[a0_0xd22e14(0xea)](){const _0x83c0b8=a0_0xd22e14;if(this['running'])return;this[_0x83c0b8(0x107)]=!0x0,await this['status'](_0x83c0b8(0x131)),this[_0x83c0b8(0xf8)](_0x83c0b8(0x11b)),this[_0x83c0b8(0x122)]=setInterval(()=>{const _0x7b9ebb=_0x83c0b8;this[_0x7b9ebb(0xdb)]('idle')[_0x7b9ebb(0x135)](_0x37b5ef=>this[_0x7b9ebb(0xf8)](_0x7b9ebb(0x137)+_0x37b5ef[_0x7b9ebb(0xdc)]));},this[_0x83c0b8(0xed)]),this[_0x83c0b8(0xdf)]();}async['disconnect'](){const _0x2bf9fc=a0_0xd22e14;if(this['running']=!0x1,this[_0x2bf9fc(0xfa)]?.['abort'](),this['heartbeatTimer'])clearInterval(this[_0x2bf9fc(0x122)]);await this[_0x2bf9fc(0xdb)](_0x2bf9fc(0xda))[_0x2bf9fc(0x135)](()=>{}),this['log'](_0x2bf9fc(0xcc));}async[a0_0xd22e14(0xeb)](_0x23968c,_0x5bd7eb,_0x168ef4=a0_0xd22e14(0x10b)){const _0x2aaaca=a0_0xd22e14;return Y({'alias':_0x23968c,'fromAlias':this[_0x2aaaca(0x10c)]},{'log':_0x33e743=>console[_0x2aaaca(0xf8)](_0x33e743),'send':()=>this[_0x2aaaca(0x124)](_0x2aaaca(0x125),{'alias':_0x23968c,'task':_0x5bd7eb,'priority':_0x168ef4,'from_session':this[_0x2aaaca(0x10c)]})});}async[a0_0xd22e14(0xdc)](_0x73a19b,_0x422c12){const _0x42b86e=a0_0xd22e14;return this[_0x42b86e(0x124)](_0x42b86e(0x123),{'alias':_0x73a19b,'message':_0x422c12,'from_session':this[_0x42b86e(0x10c)]});}async['reply'](_0x1aa6f0,_0x87a4d3,_0xbd659e=a0_0xd22e14(0xe3)){const _0x506c71=a0_0xd22e14;return this[_0x506c71(0x124)]('send_reply',{'in_reply_to':_0x1aa6f0,'text':_0x87a4d3,'status':_0xbd659e});}async[a0_0xd22e14(0xdb)](_0x4ce3b0,_0x1fba53){const _0x5127fa=a0_0xd22e14;return this[_0x5127fa(0x124)](_0x5127fa(0xe9),{'resume_id':this['resumeId'],'alias':this[_0x5127fa(0x10c)],'status':_0x4ce3b0,'server':a0_0x73d679(),'hostname':a0_0x73d679(),'agent':this[_0x5127fa(0x116)],'project_dir':process['cwd'](),..._0x1fba53});}async['getAllStatus'](){const _0x8b21cb=a0_0xd22e14;return this['call'](_0x8b21cb(0xc9),{});}async['broadcast'](_0x195e48,_0x4744d3){const _0x494f8e=a0_0xd22e14;return this[_0x494f8e(0x124)]('broadcast',{'message':_0x195e48,'filter_server':_0x4744d3?.['server'],'filter_status':_0x4744d3?.[_0x494f8e(0xdb)]});}async[a0_0xd22e14(0xdf)](){const _0x144a09=a0_0xd22e14;let _0x2f2b0e=encodeURIComponent(this[_0x144a09(0x10c)]),_0x247441=this[_0x144a09(0x139)]+_0x144a09(0x11c)+_0x2f2b0e,_0x5b76e5=this[_0x144a09(0xd2)];while(this[_0x144a09(0x107)]){try{this[_0x144a09(0xfa)]=new AbortController();let _0x3af5ae={'Accept':_0x144a09(0x134)};if(this['token'])_0x3af5ae['Authorization']=_0x144a09(0xf3)+this[_0x144a09(0x110)];let _0x232c74=await fetch(_0x247441,{'headers':_0x3af5ae,'signal':this[_0x144a09(0xfa)]['signal']});if(!_0x232c74['ok']||!_0x232c74['body']){this[_0x144a09(0xf8)]('SSE\x20failed:\x20'+_0x232c74[_0x144a09(0xdb)]),await this['sleep'](_0x5b76e5),_0x5b76e5=Math[_0x144a09(0x115)](_0x5b76e5*1.5,0xea60);continue;}_0x5b76e5=this[_0x144a09(0xd2)];let _0x4cb610=_0x232c74['body']['getReader'](),_0x37a21b=new TextDecoder(),_0x2af45b='';while(this[_0x144a09(0x107)]){let {done:_0xbd8184,value:_0x2aec28}=await _0x4cb610[_0x144a09(0x112)]();if(_0xbd8184)break;_0x2af45b+=_0x37a21b[_0x144a09(0x103)](_0x2aec28,{'stream':!0x0});let _0x3090c6=_0x2af45b[_0x144a09(0x12e)]('\x0a');_0x2af45b=_0x3090c6['pop']()||'';for(let _0x4d642a of _0x3090c6){if(!_0x4d642a[_0x144a09(0xf4)](_0x144a09(0x109)))continue;try{let _0x5337e8=JSON[_0x144a09(0x10f)](_0x4d642a[_0x144a09(0x11e)](0x6));if(_0x5337e8[_0x144a09(0xc1)]==='connected'){this[_0x144a09(0xf8)](_0x144a09(0xd5)),this[_0x144a09(0x101)](_0x144a09(0x128));continue;}if(_0x5337e8[_0x144a09(0xc1)]==='new_task'||_0x5337e8[_0x144a09(0xc1)]==='new_message'||_0x5337e8[_0x144a09(0xc1)]===_0x144a09(0x117))await this[_0x144a09(0xff)]();}catch{}}}}catch(_0xb0eda2){if(_0xb0eda2[_0x144a09(0xe1)]===_0x144a09(0x104))break;this['emit']('error',_0xb0eda2),this[_0x144a09(0xf8)]('SSE\x20error:\x20'+_0xb0eda2[_0x144a09(0xdc)]);}if(this[_0x144a09(0x107)])this[_0x144a09(0x101)]('disconnected'),this[_0x144a09(0xf8)](_0x144a09(0x12d)+_0x5b76e5/0x3e8+_0x144a09(0xd0)),await this[_0x144a09(0xf6)](_0x5b76e5),_0x5b76e5=Math[_0x144a09(0x115)](_0x5b76e5*1.5,0xea60);}}async['processInbox'](){const _0x38e38e=a0_0xd22e14;try{let _0x4b58a8=(await this[_0x38e38e(0x124)]('get_inbox',{'alias':this[_0x38e38e(0x10c)],'limit':0xa}))?.['messages']||[];for(let _0x48763c of _0x4b58a8)await this[_0x38e38e(0x124)]('ack_inbox',{'alias':this[_0x38e38e(0x10c)],'message_id':_0x48763c['id']}),this[_0x38e38e(0xf8)]('←\x20'+_0x48763c[_0x38e38e(0xca)]+':\x20'+_0x48763c[_0x38e38e(0xfe)][_0x38e38e(0x11e)](0x0,0x3c)),this[_0x38e38e(0x101)](_0x38e38e(0x12f),_0x48763c),this[_0x38e38e(0x101)](_0x38e38e(0xdc),_0x48763c);}catch(_0x1fbeed){this[_0x38e38e(0xf8)]('inbox\x20error:\x20'+_0x1fbeed[_0x38e38e(0xdc)]);}}[a0_0xd22e14(0xf6)](_0x52bd8d){return new Promise(_0x31f66f=>setTimeout(_0x31f66f,_0x52bd8d));}}var F=$;function a0_0x58dd(){const _0x31373f=['CommHub\x20response\x20omitted\x20task_id','disconnected','[commhub:task]\x20','parent_task_id','task.ack','s...','result','reconnectDelay','now','toString','SSE\x20connected','\x20error=','application/json','task.started','20PDLRXU','offline','status','message','task.send.delivered','2yApTnq','connectSSE','2916048ledaMH','name','send_failed','completed','5HVefun','match','\x20task_id=','transport','691738BUmITr','report_status','connect','send','2.0','heartbeatInterval','networkId','string','task.send.failed','toAlias','343428ISLoou','Bearer\x20','startsWith','replace','sleep','<missing>','log','parentTaskId','sseAbort','autoConnect','mcp_http','task.expired','content','processInbox',']\x20[commhub:','emit','network_id','decode','AbortError','message_id','error_message','running','to_alias','data:\x20','not_tracked','normal','alias','4218624XFwodf','unknown\x20error','parse','token','/mcp','read','error','fromAlias','min','agent','broadcast','tools/call','failed','7gcycnw','registered','/events/','delivered','slice','CommHub\x20rejected\x20task','\x20lifecycle=','text','heartbeatTimer','send_message','call','send_task','\x20transport=','Authorization','connected','resumeId','374mRNKUJ','sdk','lifecycle_tracking','SSE\x20reconnecting\x20in\x20','split','task','413128qLDXZR','idle','\x20network_id=','task.send.start','text/event-stream','catch','missing_task_id','heartbeat\x20failed:\x20','json','url','3090240bMwFnO','type','\x20parent_task_id=','2729334sQQtzI','task_id','task.replied','send_rejected','<unknown>','[REDACTED]','get_all_status','from_session'];a0_0x58dd=function(){return _0x31373f;};return a0_0x58dd();}export{F as default,$ as CommHub};
|
|
@@ -2,22 +2,36 @@
|
|
|
2
2
|
* RFC-020 §2.5 / RFC-002 §2.2 — Feishu bridge worker.
|
|
3
3
|
*
|
|
4
4
|
* Entry point spawned by agent-node when a node profile has `channels.feishu`
|
|
5
|
-
* enabled.
|
|
6
|
-
* "agent-node direct bridge" model, not the full commhub-gateway:
|
|
5
|
+
* enabled. This worker owns the FeishuAdapter and its WSClient connection.
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
* - Inbound IM event → access whitelist gate → forward to agent-node's main
|
|
10
|
-
* `think()` via parent IPC.
|
|
11
|
-
* - think() result → adapter.send() back to the originating conversation.
|
|
7
|
+
* 🔴 There are TWO outbound paths, and which one runs is decided at line ~445:
|
|
12
8
|
*
|
|
13
|
-
*
|
|
9
|
+
* const client = commhubClient ?? createEnvCommHubClient();
|
|
10
|
+
* if (client) return createCommHubEventHandler(...); // (A)
|
|
11
|
+
* if (typeof process.send === "function") ... // (B)
|
|
12
|
+
*
|
|
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).
|
|
19
|
+
*
|
|
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.
|
|
29
|
+
*
|
|
30
|
+
* Still true of both paths (unchanged from the first cut):
|
|
14
31
|
* - No separate gateway ntok_ / dedicated commhub alias.
|
|
15
|
-
* - IM messages do NOT pass through commhub task dispatch.
|
|
16
|
-
* - Feishu messages do NOT appear in Dashboard topology / Chat.
|
|
17
32
|
*
|
|
18
|
-
* The
|
|
19
|
-
*
|
|
20
|
-
* — tracked in #182.
|
|
33
|
+
* The remaining §2.9 work (meta_json columns, SSE passthrough, Dashboard
|
|
34
|
+
* topology / Chat visibility for Feishu conversations) is tracked in #182.
|
|
21
35
|
*
|
|
22
36
|
* Milestones:
|
|
23
37
|
* M1: worker entry scaffold.
|
|
@@ -29,8 +43,29 @@
|
|
|
29
43
|
* M4: agent-node spawn integration (fork(this) wired by agent-node).
|
|
30
44
|
* M5: group @bot trigger refinement, image up/down, Docker smoke.
|
|
31
45
|
*/
|
|
32
|
-
import type { NormalizedIMEvent } from "../types.js";
|
|
46
|
+
import type { IMCorrelationStore, NormalizedIMEvent } from "../types.js";
|
|
33
47
|
import { FeishuAdapter } from "./adapter.js";
|
|
48
|
+
export type IMBridgeCommHubInboxMessage = {
|
|
49
|
+
id: string;
|
|
50
|
+
type?: string;
|
|
51
|
+
content: string;
|
|
52
|
+
from_session?: string;
|
|
53
|
+
in_reply_to?: string;
|
|
54
|
+
meta?: unknown;
|
|
55
|
+
};
|
|
56
|
+
export interface IMBridgeCommHubClient {
|
|
57
|
+
sendTask(args: {
|
|
58
|
+
alias: string;
|
|
59
|
+
task: string;
|
|
60
|
+
priority?: "high" | "normal" | "low";
|
|
61
|
+
ttlSeconds?: number;
|
|
62
|
+
meta?: unknown;
|
|
63
|
+
}): Promise<{
|
|
64
|
+
taskId: string;
|
|
65
|
+
}>;
|
|
66
|
+
getInbox(alias: string): Promise<IMBridgeCommHubInboxMessage[]>;
|
|
67
|
+
ackInbox(alias: string, messageId: string): Promise<void>;
|
|
68
|
+
}
|
|
34
69
|
export interface FeishuBridgeOptions {
|
|
35
70
|
/** Absolute path to `.anet/nodes/<node>/channels/feishu/`. */
|
|
36
71
|
channelDir: string;
|
|
@@ -46,6 +81,14 @@ export interface FeishuBridgeOptions {
|
|
|
46
81
|
onEvent?: (event: NormalizedIMEvent) => Promise<void>;
|
|
47
82
|
/** Fatal WS failure after initial readiness (for worker lifecycle ownership). */
|
|
48
83
|
onTerminalError?: (error: Error) => void;
|
|
84
|
+
/** Persistent task/message correlation state. Defaults to channelDir/state.json. */
|
|
85
|
+
correlationStore?: IMCorrelationStore;
|
|
86
|
+
/** CommHub task transport. Defaults to COMMHUB_URL/COMMHUB_TOKEN when available. */
|
|
87
|
+
commhubClient?: IMBridgeCommHubClient;
|
|
88
|
+
/** Poll interval for CommHub replies. Defaults to 1500ms. */
|
|
89
|
+
commhubPollMs?: number;
|
|
90
|
+
/** 出站传输模式。省略时按 ANET_FEISHU_BRIDGE_MODE,再省略则 "direct"。 */
|
|
91
|
+
bridgeMode?: FeishuBridgeMode;
|
|
49
92
|
}
|
|
50
93
|
/** Bridge → parent: inbound IM event ready for think(). */
|
|
51
94
|
export interface BridgeIncomingEnvelope {
|
|
@@ -103,6 +146,24 @@ export type WithRateLimitHandle = {
|
|
|
103
146
|
floodKeyCount: number;
|
|
104
147
|
};
|
|
105
148
|
};
|
|
149
|
+
/**
|
|
150
|
+
* 出站传输模式。**显式声明,不靠环境变量在场与否去猜。**
|
|
151
|
+
*
|
|
152
|
+
* direct — parent IPC → agent-node 的 think()。**默认。**
|
|
153
|
+
* 2026-06-24 的第一版路径,飞书消息不进 CommHub 任务分发,
|
|
154
|
+
* 也不出现在 Dashboard 拓扑 / Chat 里。
|
|
155
|
+
* commhub — 入站事件变成一个 CommHub task,回复带 in_reply_to,
|
|
156
|
+
* correlation store 跟踪状态。**必须显式打开。**
|
|
157
|
+
*
|
|
158
|
+
* 🔴 为什么要显式:在此之前是 `commhubClient ?? createEnvCommHubClient()` ——
|
|
159
|
+
* 有 COMMHUB_URL 就走 commhub、没有就悄悄回落 IPC。两条路径的可观测性、
|
|
160
|
+
* Dashboard 可见性、失败语义完全不同,而**运维看不出自己在哪条上**,
|
|
161
|
+
* 文件头注释也因此和代码说了相反的话长达一次发布。
|
|
162
|
+
*/
|
|
163
|
+
export type FeishuBridgeMode = "commhub" | "direct";
|
|
164
|
+
export declare const DEFAULT_FEISHU_BRIDGE_MODE: FeishuBridgeMode;
|
|
165
|
+
/** 解析模式。优先级:显式入参 > 环境变量 > 默认。非法值直接抛,不静默取默认。 */
|
|
166
|
+
export declare function resolveFeishuBridgeMode(explicit?: FeishuBridgeMode, env?: NodeJS.ProcessEnv): FeishuBridgeMode;
|
|
106
167
|
/**
|
|
107
168
|
* IPC handler — forwards inbound events to the parent agent-node and routes
|
|
108
169
|
* the parent's reply back to Feishu via the adapter. The parent contract is
|
|
@@ -127,7 +188,8 @@ export type WithRateLimitHandle = {
|
|
|
127
188
|
* the agent-node.log (closes the prior silent-success blindspot).
|
|
128
189
|
*/
|
|
129
190
|
/** @internal exported for test harness; not intended for production callers. */
|
|
130
|
-
export declare function createIPCEventHandler(adapter: FeishuAdapter, ttlMs: number, ackPlaceholder: boolean): (event: NormalizedIMEvent) => Promise<void>;
|
|
191
|
+
export declare function createIPCEventHandler(adapter: FeishuAdapter, ttlMs: number, ackPlaceholder: boolean, correlationStore?: IMCorrelationStore): (event: NormalizedIMEvent) => Promise<void>;
|
|
192
|
+
export declare function createCommHubEventHandler(nodeAlias: string, adapter: FeishuAdapter, ttlMs: number, ackPlaceholder: boolean, correlationStore: IMCorrelationStore | undefined, commhubClient: IMBridgeCommHubClient, pollMs?: number): (event: NormalizedIMEvent) => Promise<void>;
|
|
131
193
|
export { FeishuAdapter } from "./adapter.js";
|
|
132
194
|
export { loadFeishuChannelConfig } from "./config.js";
|
|
133
195
|
export type { FeishuAccessList, FeishuChannelConfig, FeishuChannelEnv, } from "./config.js";
|