@sleep2agi/agent-network 2.2.22-preview.0 → 2.2.22-preview.2
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/bin/cli.js +1 -1
- package/dist/src/client.js +1 -1
- package/dist/src/im/feishu/bridge.d.ts +25 -0
- package/dist/src/im/feishu/worker.js +13 -10
- package/dist/src/node-server.js +1 -1
- package/package.json +2 -1
package/dist/src/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function a0_0x3bca(_0x2582d9,_0x2ba9ec){_0x2582d9=_0x2582d9-0x165;const _0x3d7672=a0_0x3d76();let _0x3bcab3=_0x3d7672[_0x2582d9];return _0x3bcab3;}const a0_0x583dfe=a0_0x3bca;(function(_0x55e82b,_0x2907fd){const _0x4784c0=a0_0x3bca,_0xe0e97a=_0x55e82b();while(!![]){try{const _0x595d12=parseInt(_0x4784c0(0x16e))/0x1*(-parseInt(_0x4784c0(0x198))/0x2)+-parseInt(_0x4784c0(0x1a5))/0x3+-parseInt(_0x4784c0(0x197))/0x4*(-parseInt(_0x4784c0(0x18e))/0x5)+-parseInt(_0x4784c0(0x16d))/0x6+parseInt(_0x4784c0(0x167))/0x7*(-parseInt(_0x4784c0(0x177))/0x8)+parseInt(_0x4784c0(0x1a4))/0x9*(-parseInt(_0x4784c0(0x191))/0xa)+-parseInt(_0x4784c0(0x17e))/0xb*(-parseInt(_0x4784c0(0x165))/0xc);if(_0x595d12===_0x2907fd)break;else _0xe0e97a['push'](_0xe0e97a['shift']());}catch(_0x310ec5){_0xe0e97a['push'](_0xe0e97a['shift']());}}}(a0_0x3d76,0x80588));import{EventEmitter as a0_0x520c89}from'events';import{hostname as a0_0x29ecc8}from'os';class T extends a0_0x520c89{[a0_0x583dfe(0x17c)];['alias'];[a0_0x583dfe(0x1a9)];[a0_0x583dfe(0x196)];[a0_0x583dfe(0x1ba)];['heartbeatInterval'];[a0_0x583dfe(0x188)];[a0_0x583dfe(0x179)];['sseAbort'];[a0_0x583dfe(0x1af)]=!0x1;constructor(_0x26cc19){const _0x4db6aa=a0_0x583dfe;super();if(this[_0x4db6aa(0x17c)]=_0x26cc19['url'][_0x4db6aa(0x194)](/\/$/,''),this[_0x4db6aa(0x193)]=_0x26cc19['alias'],this[_0x4db6aa(0x1a9)]=_0x26cc19['token'],this[_0x4db6aa(0x196)]=_0x26cc19[_0x4db6aa(0x196)]||_0x4db6aa(0x182),this[_0x4db6aa(0x1ba)]=_0x4db6aa(0x1a2)+_0x26cc19['alias']+'-'+Date[_0x4db6aa(0x19e)]()[_0x4db6aa(0x184)](0x24),this[_0x4db6aa(0x172)]=_0x26cc19['heartbeatInterval']??0x2bf20,this[_0x4db6aa(0x188)]=_0x26cc19[_0x4db6aa(0x188)]??0xbb8,_0x26cc19[_0x4db6aa(0x18c)]!==!0x1)this[_0x4db6aa(0x199)]();}[a0_0x583dfe(0x173)](_0x5f0df5){const _0x2b5536=a0_0x583dfe;console[_0x2b5536(0x173)]('['+new Date()[_0x2b5536(0x171)]()[_0x2b5536(0x16f)](0x0,0x8)+']\x20[commhub:'+this[_0x2b5536(0x193)]+']\x20'+_0x5f0df5);}async['call'](_0x492e18,_0x27e453){const _0x4c13a0=a0_0x583dfe;let _0xd32662={'Content-Type':_0x4c13a0(0x19a),'Accept':_0x4c13a0(0x1a6)};if(this[_0x4c13a0(0x1a9)])_0xd32662['Authorization']=_0x4c13a0(0x1b3)+this[_0x4c13a0(0x1a9)];let _0x5856b5=await(await fetch(this[_0x4c13a0(0x17c)]+_0x4c13a0(0x175),{'method':_0x4c13a0(0x176),'headers':_0xd32662,'body':JSON[_0x4c13a0(0x1b8)]({'jsonrpc':_0x4c13a0(0x1b7),'id':Date['now'](),'method':_0x4c13a0(0x169),'params':{'name':_0x492e18,'arguments':_0x27e453}})}))[_0x4c13a0(0x1b4)](),_0x84edf6=_0x5856b5['match'](/data: (.+)/),_0x5b0d8e=_0x84edf6?JSON[_0x4c13a0(0x1a7)](_0x84edf6[0x1]):JSON[_0x4c13a0(0x1a7)](_0x5856b5),_0x1cce53=_0x5b0d8e?.[_0x4c13a0(0x1bc)]?.[_0x4c13a0(0x18b)]?.[0x0]?.[_0x4c13a0(0x1b4)];return _0x1cce53?JSON[_0x4c13a0(0x1a7)](_0x1cce53):_0x5b0d8e;}async[a0_0x583dfe(0x199)](){const _0xdb4c87=a0_0x583dfe;if(this[_0xdb4c87(0x1af)])return;this[_0xdb4c87(0x1af)]=!0x0,await this['status'](_0xdb4c87(0x1ae)),this[_0xdb4c87(0x173)]('registered'),this['heartbeatTimer']=setInterval(()=>{const _0x15713f=_0xdb4c87;this[_0x15713f(0x1ad)](_0x15713f(0x1ae))[_0x15713f(0x19f)](_0x4fedb1=>this[_0x15713f(0x173)]('heartbeat\x20failed:\x20'+_0x4fedb1[_0x15713f(0x170)]));},this[_0xdb4c87(0x172)]),this['connectSSE']();}async[a0_0x583dfe(0x16b)](){const _0x5d807c=a0_0x583dfe;if(this['running']=!0x1,this[_0x5d807c(0x1bb)]?.[_0x5d807c(0x18a)](),this[_0x5d807c(0x179)])clearInterval(this[_0x5d807c(0x179)]);await this[_0x5d807c(0x1ad)](_0x5d807c(0x185))[_0x5d807c(0x19f)](()=>{}),this[_0x5d807c(0x173)](_0x5d807c(0x1b6));}async[a0_0x583dfe(0x17f)](_0x3faeb0,_0x4f7006,_0x3c8484=a0_0x583dfe(0x19b)){const _0x5d14b6=a0_0x583dfe;return this['call'](_0x5d14b6(0x1ac),{'alias':_0x3faeb0,'task':_0x4f7006,'priority':_0x3c8484,'from_session':this['alias']});}async[a0_0x583dfe(0x170)](_0x241c40,_0x4d19c2){const _0x47d734=a0_0x583dfe;return this[_0x47d734(0x1a8)](_0x47d734(0x174),{'alias':_0x241c40,'message':_0x4d19c2,'from_session':this[_0x47d734(0x193)]});}async[a0_0x583dfe(0x19d)](_0x83dc11,_0x4b2bd6,_0x364d8b=a0_0x583dfe(0x166)){const _0x526366=a0_0x583dfe;return this[_0x526366(0x1a8)](_0x526366(0x1bf),{'in_reply_to':_0x83dc11,'text':_0x4b2bd6,'status':_0x364d8b});}async[a0_0x583dfe(0x1ad)](_0x2b878a,_0x5496b2){const _0x15560a=a0_0x583dfe;return this[_0x15560a(0x1a8)](_0x15560a(0x17b),{'resume_id':this['resumeId'],'alias':this[_0x15560a(0x193)],'status':_0x2b878a,'server':a0_0x29ecc8(),'hostname':a0_0x29ecc8(),'agent':this[_0x15560a(0x196)],'project_dir':process[_0x15560a(0x1a1)](),..._0x5496b2});}async[a0_0x583dfe(0x17a)](){const _0x4f97ac=a0_0x583dfe;return this[_0x4f97ac(0x1a8)](_0x4f97ac(0x1a0),{});}async[a0_0x583dfe(0x1be)](_0x1d94f4,_0x167f4c){const _0x394b7e=a0_0x583dfe;return this[_0x394b7e(0x1a8)](_0x394b7e(0x1be),{'message':_0x1d94f4,'filter_server':_0x167f4c?.[_0x394b7e(0x190)],'filter_status':_0x167f4c?.[_0x394b7e(0x1ad)]});}async[a0_0x583dfe(0x16a)](){const _0xa4d268=a0_0x583dfe;let _0x110aca=encodeURIComponent(this[_0xa4d268(0x193)]),_0xd8273a=this['url']+'/events/'+_0x110aca,_0x285809=this[_0xa4d268(0x188)];while(this[_0xa4d268(0x1af)]){try{this[_0xa4d268(0x1bb)]=new AbortController();let _0x5bb12a={'Accept':_0xa4d268(0x187)};if(this[_0xa4d268(0x1a9)])_0x5bb12a[_0xa4d268(0x180)]=_0xa4d268(0x1b3)+this[_0xa4d268(0x1a9)];let _0x4d0278=await fetch(_0xd8273a,{'headers':_0x5bb12a,'signal':this[_0xa4d268(0x1bb)][_0xa4d268(0x19c)]});if(!_0x4d0278['ok']||!_0x4d0278[_0xa4d268(0x1b0)]){this[_0xa4d268(0x173)]('SSE\x20failed:\x20'+_0x4d0278[_0xa4d268(0x1ad)]),await this['sleep'](_0x285809),_0x285809=Math[_0xa4d268(0x183)](_0x285809*1.5,0xea60);continue;}_0x285809=this['reconnectDelay'];let _0x1e7517=_0x4d0278[_0xa4d268(0x1b0)][_0xa4d268(0x1b2)](),_0x44ad7d=new TextDecoder(),_0x362255='';while(this[_0xa4d268(0x1af)]){let {done:_0x272a54,value:_0x107d54}=await _0x1e7517[_0xa4d268(0x16c)]();if(_0x272a54)break;_0x362255+=_0x44ad7d[_0xa4d268(0x168)](_0x107d54,{'stream':!0x0});let _0x4a1a4c=_0x362255['split']('\x0a');_0x362255=_0x4a1a4c['pop']()||'';for(let _0x11a188 of _0x4a1a4c){if(!_0x11a188[_0xa4d268(0x1b1)](_0xa4d268(0x18d)))continue;try{let _0x5e82be=JSON[_0xa4d268(0x1a7)](_0x11a188[_0xa4d268(0x16f)](0x6));if(_0x5e82be[_0xa4d268(0x1aa)]==='connected'){this['log']('SSE\x20connected'),this[_0xa4d268(0x1a3)](_0xa4d268(0x1ab));continue;}if(_0x5e82be[_0xa4d268(0x1aa)]==='new_task'||_0x5e82be['type']===_0xa4d268(0x195)||_0x5e82be[_0xa4d268(0x1aa)]===_0xa4d268(0x1be))await this['processInbox']();}catch{}}}}catch(_0x10f8e3){if(_0x10f8e3[_0xa4d268(0x1bd)]===_0xa4d268(0x189))break;this[_0xa4d268(0x1a3)](_0xa4d268(0x1b9),_0x10f8e3),this[_0xa4d268(0x173)]('SSE\x20error:\x20'+_0x10f8e3[_0xa4d268(0x170)]);}if(this[_0xa4d268(0x1af)])this['emit'](_0xa4d268(0x1b6)),this['log'](_0xa4d268(0x18f)+_0x285809/0x3e8+'s...'),await this[_0xa4d268(0x17d)](_0x285809),_0x285809=Math[_0xa4d268(0x183)](_0x285809*1.5,0xea60);}}async['processInbox'](){const _0xbeba88=a0_0x583dfe;try{let _0x128652=(await this['call']('get_inbox',{'alias':this[_0xbeba88(0x193)],'limit':0xa}))?.[_0xbeba88(0x181)]||[];for(let _0x21a5d2 of _0x128652)await this['call'](_0xbeba88(0x1b5),{'alias':this[_0xbeba88(0x193)],'message_id':_0x21a5d2['id']}),this[_0xbeba88(0x173)]('←\x20'+_0x21a5d2[_0xbeba88(0x178)]+':\x20'+_0x21a5d2[_0xbeba88(0x18b)][_0xbeba88(0x16f)](0x0,0x3c)),this['emit'](_0xbeba88(0x186),_0x21a5d2),this[_0xbeba88(0x1a3)](_0xbeba88(0x170),_0x21a5d2);}catch(_0x4be925){this[_0xbeba88(0x173)](_0xbeba88(0x192)+_0x4be925[_0xbeba88(0x170)]);}}['sleep'](_0x2f2e41){return new Promise(_0x52df72=>setTimeout(_0x52df72,_0x2f2e41));}}var $=T;function a0_0x3d76(){const _0x727d8f=['/mcp','POST','7678456ajgpOY','from_session','heartbeatTimer','getAllStatus','report_status','url','sleep','121fMQbnw','send','Authorization','messages','sdk','min','toString','offline','task','text/event-stream','reconnectDelay','AbortError','abort','content','autoConnect','data:\x20','5CHjBrt','SSE\x20reconnecting\x20in\x20','server','1872740ShZCGs','inbox\x20error:\x20','alias','replace','new_message','agent','363628ITRvDe','1048932PbhQJO','connect','application/json','normal','signal','reply','now','catch','get_all_status','cwd','sdk-','emit','36DHfPWz','1789644cswbgG','application/json,\x20text/event-stream','parse','call','token','type','connected','send_task','status','idle','running','body','startsWith','getReader','Bearer\x20','text','ack_inbox','disconnected','2.0','stringify','error','resumeId','sseAbort','result','name','broadcast','send_reply','5279340PZxnwi','completed','7BVaAwR','decode','tools/call','connectSSE','disconnect','read','6301290nkVLpd','2biSjHH','slice','message','toTimeString','heartbeatInterval','log','send_message'];a0_0x3d76=function(){return _0x727d8f;};return a0_0x3d76();}export{$ as default,T as CommHub};
|
|
@@ -62,6 +62,31 @@ export interface BridgeReplyEnvelope {
|
|
|
62
62
|
* connected and the EventDispatcher is registered.
|
|
63
63
|
*/
|
|
64
64
|
export declare function startFeishuBridge(opts: FeishuBridgeOptions): Promise<FeishuAdapter>;
|
|
65
|
+
/**
|
|
66
|
+
* IPC handler — forwards inbound events to the parent agent-node and routes
|
|
67
|
+
* the parent's reply back to Feishu via the adapter. The parent contract is
|
|
68
|
+
* a single round-trip per event keyed on `idempotencyKey`.
|
|
69
|
+
*
|
|
70
|
+
* ackPlaceholder behavior (RFC-020 §4.2, Vincent ask 2026-06-26):
|
|
71
|
+
* - On event arrival, bridge sends a "⏳ 处理中…" placeholder into the
|
|
72
|
+
* originating thread BEFORE forwarding the IPC envelope. The placeholder
|
|
73
|
+
* is sent so the user gets an immediate push notification ("the bot saw
|
|
74
|
+
* my message"). The placeholder send is awaited so logs stay in order.
|
|
75
|
+
* - On reply IPC, bridge ALWAYS calls adapter.send for the final reply —
|
|
76
|
+
* a new message in the same thread, NOT an in-place edit of the
|
|
77
|
+
* placeholder. Vincent rejected the edit-in-place pattern 2026-06-26:
|
|
78
|
+
* pushing a fresh message gives him a second notification ("the bot
|
|
79
|
+
* replied") that an edit silently misses on most IM clients.
|
|
80
|
+
* - On TTL expiry without reply, bridge similarly send a NEW
|
|
81
|
+
* "[处理超时…]" message in-thread, never edits the placeholder.
|
|
82
|
+
* - adapter.edit remains in the IMAdapter interface for future use but is
|
|
83
|
+
* not called from this path. Tests in tests/feishu-bridge-* assert
|
|
84
|
+
* editCalls.length === 0 to lock that behavior in.
|
|
85
|
+
* - All success paths log to stderr so the round-trip is observable from
|
|
86
|
+
* the agent-node.log (closes the prior silent-success blindspot).
|
|
87
|
+
*/
|
|
88
|
+
/** @internal exported for test harness; not intended for production callers. */
|
|
89
|
+
export declare function createIPCEventHandler(adapter: FeishuAdapter, ttlMs: number, ackPlaceholder: boolean): (event: NormalizedIMEvent) => Promise<void>;
|
|
65
90
|
export { FeishuAdapter } from "./adapter.js";
|
|
66
91
|
export { loadFeishuChannelConfig } from "./config.js";
|
|
67
92
|
export type { FeishuAccessList, FeishuChannelConfig, FeishuChannelEnv, } from "./config.js";
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import*as
|
|
3
|
-
`)}import{existsSync as
|
|
4
|
-
`);return}J.set(
|
|
5
|
-
`)}
|
|
6
|
-
`)}
|
|
7
|
-
`)}
|
|
8
|
-
`)}
|
|
9
|
-
`)
|
|
10
|
-
`)}
|
|
11
|
-
`),
|
|
2
|
+
import*as R from"@larksuiteoapi/node-sdk";import _ from"node:crypto";import{existsSync as F,mkdirSync as x,readFileSync as C,writeFileSync as M}from"node:fs";import{join as z}from"node:path";import{Readable as T}from"node:stream";class N{platform="feishu";ingressMode="socket";feishuConfig=null;connectionName="";client=null;wsClient=null;botOpenId=null;mediaDir=null;health_={connected:!1,lastEventAt:null,lastError:null};async init(Q){if(Q.platform!=="feishu")throw Error(`FeishuAdapter.init: expected platform "feishu", got "${Q.platform}"`);let J=Q.platformConfig;if(!J?.appId||!J?.appSecret)throw Error("FeishuAdapter.init: appId / appSecret missing in platformConfig");this.feishuConfig=J,this.connectionName=Q.connectionName,this.client=new R.Client({appId:J.appId,appSecret:J.appSecret,disableTokenCache:!1}),this.botOpenId=await P(this.client),this.mediaDir=J.channelDir?z(J.channelDir,"media"):null}async start(Q){if(!this.feishuConfig||!this.client)throw Error("FeishuAdapter.start: call init() first");let{appId:J,appSecret:Z,access:$,groupPolicy:V}=this.feishuConfig,X=this.connectionName,Y=this.botOpenId,G=this.mediaDir,W=this.client,q=new R.EventDispatcher({});q.register({"im.message.receive_v1":async(B)=>{try{this.health_={...this.health_,lastEventAt:Date.now()};let H=b(B,X,Y);if(!H)return;await k(B,H,W,G);let U=w(H,$,V);if(!U.allow){L("deny",H,U.reason);return}await Q(H)}catch(H){let U=H instanceof Error?H.message:String(H);this.health_={...this.health_,lastError:U},L("error",null,U)}}}),this.wsClient=new R.WSClient({appId:J,appSecret:Z,loggerLevel:R.LoggerLevel.warn}),await this.wsClient.start({eventDispatcher:q}),this.health_={...this.health_,connected:!0,lastError:null}}async stop(){this.health_={...this.health_,connected:!1},this.wsClient=null,this.client=null,this.feishuConfig=null}async send(Q){if(!this.client)throw Error("FeishuAdapter.send: call init() first");let J,Z;if(Q.imagePath){let G=await E(this.client,Q.imagePath);if(!G)throw Error(`FeishuAdapter.send: image upload failed for ${Q.imagePath}`);J="image",Z=JSON.stringify({image_key:G})}else{let G=Q.text??Q.markdown;if(!G)throw Error("FeishuAdapter.send: requires text, markdown, or imagePath");J="text",Z=JSON.stringify({text:G})}let $=Q.replyToMessageId??Q.target.threadRootId;if($){let W=(await this.client.im.message.reply({path:{message_id:$},data:{msg_type:J,content:Z}}))?.data?.message_id;if(!W)throw Error("FeishuAdapter.send: reply returned no message_id");return{messageId:W}}let V=Q.target.conversationType==="dm"?"open_id":"chat_id",Y=(await this.client.im.message.create({params:{receive_id_type:V},data:{receive_id:Q.target.conversationId,msg_type:J,content:Z}}))?.data?.message_id;if(!Y)throw Error("FeishuAdapter.send: create returned no message_id");return{messageId:Y}}async edit(Q,J,Z){if(!this.client)throw Error("FeishuAdapter.edit: call init() first");let $=Z.text??Z.markdown;if(!$)throw Error("FeishuAdapter.edit: M3 supports text only");await this.client.im.message.update({path:{message_id:J},data:{msg_type:"text",content:JSON.stringify({text:$})}})}health(){return{...this.health_}}}function b(Q,J,Z){let $=Q,V=$?.message,X=$?.sender,Y=X?.sender_id?.open_id;if(!V||!Y)return null;let G;if(V.message_type==="text")try{G=JSON.parse(V.content).text}catch{G=V.content}else if(V.message_type==="file")try{G=`[文件: ${JSON.parse(V.content).file_name??"unknown"}]`}catch{G="[文件]"}else if(V.message_type==="sticker")G="[表情]";else if(V.message_type==="image")G=void 0;else return null;let W=V.chat_type==="group"?"group":"dm",q=Array.isArray(V.mentions)?V.mentions:[],B=Z?q.some((U)=>U?.id?.open_id===Z):q.length>0,H=`${J}#feishu`;return{platform:"feishu",connectionId:H,tenantId:X?.tenant_key,conversation:{platform:"feishu",conversationId:V.chat_id,conversationType:W,threadRootId:V.root_id},sender:{id:Y},messageId:V.message_id,mentioned:B,content:G?{text:G}:{},receivedAt:Date.now(),idempotencyKey:`feishu:${H}:${V.message_id}`}}async function k(Q,J,Z,$){if(!Z||!$)return;let X=Q?.message;if(!X||X.message_type!=="image")return;let Y;try{Y=JSON.parse(X.content).image_key}catch{return}if(!Y||!X.message_id)return;let G=await D(Z,X.message_id,Y,$);if(G)J.content={...J.content,images:[G]}}async function D(Q,J,Z,$){try{let V=await Q.im.messageResource.get({path:{message_id:J,file_key:Z},params:{type:"image"}});if(!V)return null;let X=V,Y=[];await new Promise((q,B)=>{X.on("data",(H)=>Y.push(Buffer.from(H))),X.on("end",()=>q()),X.on("error",(H)=>B(H))}),x($,{recursive:!0});let G=`img_${Date.now()}_${_.randomBytes(4).toString("hex")}.png`,W=z($,G);return M(W,Buffer.concat(Y)),W}catch{return null}}async function E(Q,J){try{if(!F(J))return null;let Z=C(J),$=T.from(Z);return(await Q.im.image.create({data:{image_type:"message",image:$}}))?.image_key??null}catch{return null}}async function P(Q){try{let Z=await Q.request({method:"GET",url:"/open-apis/bot/v3/info"});return Z?.bot?.open_id??Z?.data?.bot?.open_id??null}catch{return null}}function w(Q,J,Z){if(Q.conversation.conversationType==="dm")return J.allowFrom.includes(Q.sender.id)?{allow:!0,reason:""}:{allow:!1,reason:"sender not in allowFrom (dm)"};if(!J.allowChats.includes(Q.conversation.conversationId))return{allow:!1,reason:"chat not in allowChats"};if(Z==="all")return{allow:!0,reason:""};if(Z==="observe")return{allow:!1,reason:"groupPolicy=observe — chat in allowChats but no trigger"};if(Q.mentioned)return{allow:!0,reason:""};return{allow:!1,reason:`groupPolicy=${Z} requires @bot mention (not mentioned)`}}function L(Q,J,Z){let $=new Date().toISOString(),V=J?`${J.conversation.conversationType}:${J.conversation.conversationId}`:"?",X=J?J.sender.id:"?";process.stderr.write(`[${$}] [feishu:audit] ${Q} from=${X} conv=${V} — ${Z}
|
|
3
|
+
`)}import{existsSync as O,readFileSync as j}from"node:fs";import{join as K}from"node:path";function A(Q){let J=I(K(Q,".env")),Z=J.FEISHU_APP_ID,$=J.FEISHU_APP_SECRET;if(!Z||!$)throw Error(`feishu channel: FEISHU_APP_ID / FEISHU_APP_SECRET missing in ${Q}/.env`);let V=u(K(Q,"access.json"));return{appId:Z,appSecret:$,access:V,groupPolicy:"mention",ackPlaceholder:!0,auditRaw:!1,taskTimeoutMs:300000,channelDir:Q}}function I(Q){if(!O(Q))return{};let J={};for(let Z of j(Q,"utf-8").split(/\r?\n/)){let $=Z.trim();if(!$||$.startsWith("#"))continue;let V=$.indexOf("=");if(V<0)continue;let X=$.slice(0,V).trim(),Y=$.slice(V+1).trim().replace(/^["']|["']$/g,"");J[X]=Y}return J}function u(Q){if(!O(Q))return{allowFrom:[],allowChats:[]};try{let J=JSON.parse(j(Q,"utf-8"));return{allowFrom:Array.isArray(J.allowFrom)?J.allowFrom:[],allowChats:Array.isArray(J.allowChats)?J.allowChats:[]}}catch{return{allowFrom:[],allowChats:[]}}}var y=900000,f=120000;async function S(Q){let J=A(Q.channelDir),Z=new N;await Z.init({platform:"feishu",connectionName:Q.nodeAlias,ingressMode:"socket",groupPolicy:J.groupPolicy,ackPlaceholder:J.ackPlaceholder,auditRaw:J.auditRaw,taskTimeoutMs:J.taskTimeoutMs,platformConfig:J});let $=J.taskTimeoutMs||y,V=Q.onEvent??p(Z,$,J.ackPlaceholder);return await Z.start(h(V)),Z}function h(Q){let J=new Map;return async(Z)=>{let $=Date.now();if(J.size>200){for(let[V,X]of J)if($-X>f)J.delete(V)}if(J.has(Z.idempotencyKey)){process.stderr.write(`[feishu:bridge] dedup drop ${Z.idempotencyKey}
|
|
4
|
+
`);return}J.set(Z.idempotencyKey,$),await Q(Z)}}function p(Q,J,Z){if(typeof process.send==="function")return l(Q,J,Z);return g}var v="⏳ 处理中…",m="[处理超时,任务可能仍在后台运行]";function l(Q,J,Z){if(typeof process.send!=="function")throw Error("createIPCEventHandler: parent process.send unavailable (not forked)");let $=new Map;return process.on("message",(V)=>{if(!c(V))return;let X=$.get(V.eventKey);if(!X)return;$.delete(V.eventKey);let{text:Y,eventKey:G}=V,{event:W,placeholderMessageId:q}=X;(async()=>{try{let{messageId:B}=await Q.send({target:W.conversation,text:Y,replyToMessageId:W.messageId,correlation:{taskId:G}}),H=q?` (after placeholder=${q})`:"";process.stderr.write(`[feishu:bridge] reply sent (messageId=${B})${H} for ${G}
|
|
5
|
+
`)}catch(B){let H=B instanceof Error?B.message:String(B);process.stderr.write(`[feishu:bridge] reply delivery failed: ${H}
|
|
6
|
+
`)}})()}),async(V)=>{if($.set(V.idempotencyKey,{event:V}),setTimeout(()=>{let Y=$.get(V.idempotencyKey);if(!Y)return;$.delete(V.idempotencyKey);let{placeholderMessageId:G}=Y;(async()=>{try{await Q.send({target:V.conversation,text:m,replyToMessageId:V.messageId,correlation:{taskId:V.idempotencyKey}});let W=G?` (after placeholder=${G})`:"";process.stderr.write(`[feishu:bridge] timeout-notify sent${W} for ${V.idempotencyKey} after ${J}ms
|
|
7
|
+
`)}catch(W){let q=W instanceof Error?W.message:String(W);process.stderr.write(`[feishu:bridge] timeout-notify send failed: ${q}
|
|
8
|
+
`)}})()},J),Z)try{let{messageId:Y}=await Q.send({target:V.conversation,text:v,replyToMessageId:V.messageId,correlation:{taskId:V.idempotencyKey}}),G=$.get(V.idempotencyKey);if(G)G.placeholderMessageId=Y,process.stderr.write(`[feishu:bridge] placeholder sent (messageId=${Y}) for ${V.idempotencyKey}
|
|
9
|
+
`)}catch(Y){let G=Y instanceof Error?Y.message:String(Y);process.stderr.write(`[feishu:bridge] placeholder send failed: ${G} — reply will still send as a new message
|
|
10
|
+
`)}let X={type:"event",event:V};process.send(X)}}function c(Q){if(!Q||typeof Q!=="object")return!1;let J=Q;return J.type==="reply"&&typeof J.eventKey==="string"&&typeof J.text==="string"}async function g(Q){process.stderr.write(`[feishu:bridge] event from=${Q.sender.id} conv=${Q.conversation.conversationType}:${Q.conversation.conversationId} mentioned=${Q.mentioned} text=${(Q.content.text??"").slice(0,80)}
|
|
11
|
+
`)}function d(Q){let J={};for(let Z=0;Z<Q.length;Z++){let $=Q[Z],V=Q[Z+1];if($==="--channel-dir"&&V)J.channelDir=V,Z++;else if($==="--node-alias"&&V)J.nodeAlias=V,Z++}return J}async function o(){let Q=d(process.argv.slice(2));if(!Q.channelDir||!Q.nodeAlias)process.stderr.write(`usage: feishu-worker --channel-dir <path> --node-alias <alias>
|
|
12
|
+
`),process.exit(2);try{await S({channelDir:Q.channelDir,nodeAlias:Q.nodeAlias}),process.stderr.write(`[feishu:worker] bridge online — node=${Q.nodeAlias} dir=${Q.channelDir} ipc=${typeof process.send==="function"?"yes":"no"}
|
|
13
|
+
`)}catch(J){let Z=J instanceof Error?J.stack??J.message:String(J);process.stderr.write(`[feishu:worker] startup failed: ${Z}
|
|
14
|
+
`),process.exit(1)}}o();
|
package/dist/src/node-server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
const a0_0x46492c=a0_0x4ca9;(function(_0x13f52c,_0x5c868a){const _0x291654=a0_0x4ca9,_0x331d56=_0x13f52c();while(!![]){try{const _0x345745=-parseInt(_0x291654(0x136))/0x1*(-parseInt(_0x291654(0x173))/0x2)+parseInt(_0x291654(0x140))/0x3*(parseInt(_0x291654(0xe8))/0x4)+-parseInt(_0x291654(0x110))/0x5*(parseInt(_0x291654(0x16a))/0x6)+-parseInt(_0x291654(0x157))/0x7*(parseInt(_0x291654(0x138))/0x8)+parseInt(_0x291654(0x132))/0x9*(-parseInt(_0x291654(0xf9))/0xa)+parseInt(_0x291654(0x14a))/0xb+parseInt(_0x291654(0x16b))/0xc;if(_0x345745===_0x5c868a)break;else _0x331d56['push'](_0x331d56['shift']());}catch(_0x37b189){_0x331d56['push'](_0x331d56['shift']());}}}(a0_0x225b,0xb5055));import{readFileSync as a0_0x4cc358,existsSync as a0_0x364285}from'fs';import{randomUUID as a0_0x17c95e}from'crypto';import{join as a0_0x2175ac}from'path';import{hostname as a0_0x47b9f6}from'os';import{execSync as a0_0xd3af48}from'child_process';import{Server as a0_0x38247c}from'@modelcontextprotocol/sdk/server/index.js';import{StdioServerTransport as a0_0x281413}from'@modelcontextprotocol/sdk/server/stdio.js';import{ListToolsRequestSchema as a0_0xbb978b,CallToolRequestSchema as a0_0xbc40e}from'@modelcontextprotocol/sdk/types.js';function I(_0x2007b8){const _0x21657b=a0_0x4ca9;if(!a0_0x364285(_0x2007b8))return;for(let _0x55b4bf of a0_0x4cc358(_0x2007b8,_0x21657b(0x142))[_0x21657b(0x134)]('\x0a')){let _0x459e7e=_0x55b4bf['trim']();if(!_0x459e7e||_0x459e7e[_0x21657b(0xf7)]('#'))continue;let _0x2e0941=_0x459e7e[_0x21657b(0x13a)]('=');if(_0x2e0941<0x0)continue;let _0x543e9f=_0x459e7e[_0x21657b(0xe6)](0x0,_0x2e0941)[_0x21657b(0x15d)](),_0x304ea7=_0x459e7e[_0x21657b(0xe6)](_0x2e0941+0x1)['trim']()[_0x21657b(0x12e)](/^["']|["']$/g,'');if(!process.env[_0x543e9f])process.env[_0x543e9f]=_0x304ea7;}}var L=process.env.HOME||'~',U=a0_0x2175ac(L,'.claude/channels/commhub');I(a0_0x2175ac(U,a0_0x46492c(0x107)));function a0_0x225b(){const _0x3c0b11=['Reply\x20text\x20/\x20result\x20summary','exit','.anet','(none)','init\x20failed:\x20','Update\x20this\x20session\x27s\x20status\x20in\x20CommHub\x20(working/idle/blocked/error).\x20Returns\x20inbox_count.','data:\x20','completed','Task\x20content','now','.env','stdin','broadcast','SSE\x20stream\x20ended,\x20reconnecting...','message_id','Progress\x200-100','/mcp','connect','SIGINT','5ToOGqo','Target\x20session\x20alias','Message\x20content','failed','SSE\x20fatal:\x20','text','Get\x20status\x20of\x20all\x20sessions\x20from\x20CommHub.','→\x20injected\x20task\x20','re-registered\x20as\x20\x22','http://127.0.0.1:9200','commhub','from','Send\x20a\x20message\x20to\x20another\x20session\x20(no\x20task\x20lifecycle,\x20just\x20chat).\x20Use\x20for\x20replies\x20and\x20status\x20updates.','working','notification','token','in_progress','get_all_status','[commhub]\x20WARN:\x20COMMHUB_ALIAS\x20env\x20var\x20is\x20unset\x20—\x20outbound\x20from_session\x20','messages','status','message','connected','hub','unattributed-','from_session','starting\x20SSE\x20listener...','\x20ALIAS=','Task\x20outcome:\x20completed/failed/cancelled\x20for\x20final\x20results,\x20blocked/error/in_progress\x20for\x20status\x20updates','\x22\x20(','replace','commhub_send_task','read','cancelled','123399VRgvix','You\x20can\x20also\x20use\x20commhub_report_status\x20to\x20update\x20your\x20session\x20status.','split','stderr','838RAUPqu','\x20PROJECT_ENV=','16896sGKjTf','stringify','indexOf','0.3.0','set','would\x20mis-attribute.\x20Refusing\x20to\x20guess\x20from\x20TMUX_NAME=','object','idle','6EHSArw','normal','utf-8','min','send_message','Send\x20a\x20task\x20to\x20another\x20session\x20via\x20CommHub.','heartbeat\x20failed:\x20','then','...\x20TMUX=','high','11567479aDeLmi','replied','ack_inbox','send_reply','SSE\x20connected\x20as\x20\x22','2.0','offline','session\x20disconnected','Reply\x20to\x20a\x20CommHub\x20task\x20—\x20report\x20completion\x20or\x20send\x20a\x20message\x20back\x20to\x20the\x20hub.','config.json',':\x20inbox_count=','cwd','POST','4151KkYcZP','no\x20response','pid','claude-code','type','warning:\x20could\x20not\x20register:\x20','trim','commhub_report_status','Session\x20alias:\x20','setRequestHandler','.\x20Restart\x20node\x20via\x20`anet\x20node\x20start\x20<alias>`\x20so\x20the\x20env\x20is\x20set\x20explicitly\x20(#203).\x0a','CommHub\x20init\x20failed:\x20','new_task','ENV:\x20URL=','priority','notifications/claude/channel','Reply\x20using\x20the\x20commhub_reply\x20tool\x20to\x20report\x20status\x20or\x20results\x20back.','body','SSE\x20error:\x20','8720886yPdaYp','6878256IvjNSO','statusText','report_status','delete','low','get_inbox','fatal:\x20','write','3026fIyJlP','catch','blocked','commhub-channel','content','\x20from\x20','none','pop','parse','initialize','send_task','result','alias','length','commhub_send_message','join','error','getReader','slice','string','1136796uyRnmN','Messages\x20from\x20CommHub\x20arrive\x20as\x20<channel\x20source=\x22commhub\x22\x20task_id=\x22...\x22\x20priority=\x22...\x22\x20from=\x22...\x22>','inbox_count','application/json','commhub_get_all_status','SSE\x20connection\x20error:\x20','task','The\x20task_id\x20from\x20the\x20channel\x20message\x20(or\x20\x27hub\x27\x20for\x20general)','new_message','shutting\x20down,\x20reporting\x20offline...','\x22\x20after\x20SSE\x20reconnect','SSE\x20连续\x20>1h\x20连不上\x20hub\x20(','application/json,\x20text/event-stream',']\x20[commhub]\x20',')\x20—\x20放弃自动重连。手动\x20anet\x20node\x20start\x20恢复。','startsWith','\x20RESUME_ID=','10eLJDGU','end','find','Bearer\x20'];a0_0x225b=function(){return _0x3c0b11;};return a0_0x225b();}var v=process[a0_0x46492c(0x155)]()['replace'](/\//g,'-');I(a0_0x2175ac(U,v,'.env'));function d(){const _0x4cb4d8=a0_0x46492c;try{return a0_0xd3af48('tmux\x20display-message\x20-p\x20\x27#S\x27',{'encoding':_0x4cb4d8(0x142),'timeout':0x7d0})[_0x4cb4d8(0x15d)]();}catch{return'';}}function a0_0x4ca9(_0x28b5e1,_0x5344b9){_0x28b5e1=_0x28b5e1-0xd7;const _0x225bda=a0_0x225b();let _0x4ca966=_0x225bda[_0x28b5e1];return _0x4ca966;}function m(){const _0x263cde=a0_0x46492c;try{let _0x3cea15=a0_0x2175ac(L,_0x263cde(0xff),_0x263cde(0x153));if(a0_0x364285(_0x3cea15))return JSON[_0x263cde(0xdc)](a0_0x4cc358(_0x3cea15,_0x263cde(0x142)));}catch{}return{};}var u=m(),j=process.env.COMMHUB_URL||u['hub']||a0_0x46492c(0x119),f=process.env.COMMHUB_TMUX||d();function r(){const _0x10646a=a0_0x46492c;if(process.env.COMMHUB_ALIAS&&process.env.COMMHUB_ALIAS['trim']())return process.env.COMMHUB_ALIAS[_0x10646a(0x15d)]();return process[_0x10646a(0x135)][_0x10646a(0x172)](_0x10646a(0x122)+(_0x10646a(0x13d)+(f||_0x10646a(0x100))+'\x20/\x20hostname='+a0_0x47b9f6()+_0x10646a(0x161))),_0x10646a(0x128)+process[_0x10646a(0x159)];}var G=r(),K=process.env.COMMHUB_RESUME_ID||process.env.CLAUDE_RESUME_ID||a0_0x17c95e(),F=process.env.COMMHUB_TOKEN||u[a0_0x46492c(0x11f)]||'';function W(_0x4df2d4){const _0x264c10=a0_0x46492c;let _0x2cf643=new Date()['toTimeString']()[_0x264c10(0xe6)](0x0,0x8);process[_0x264c10(0x135)][_0x264c10(0x172)]('['+_0x2cf643+_0x264c10(0xf5)+_0x4df2d4+'\x0a');}function N(_0x44b101){return new Promise(_0x48e1e3=>setTimeout(_0x48e1e3,_0x44b101));}W(a0_0x46492c(0x164)+j+a0_0x46492c(0x12b)+G+a0_0x46492c(0xf8)+K['slice'](0x0,0x8)+a0_0x46492c(0x148)+(f||a0_0x46492c(0xda))+'\x20CWD='+process['cwd']()+a0_0x46492c(0x137)+v);var D=new Map(),x=new a0_0x38247c({'name':a0_0x46492c(0xd7),'version':'0.3.0'},{'capabilities':{'experimental':{'claude/channel':{}},'tools':{}},'instructions':[a0_0x46492c(0xe9),'These\x20are\x20tasks\x20dispatched\x20by\x20the\x20hub\x20or\x20other\x20sessions\x20via\x20the\x20CommHub\x20Server.',a0_0x46492c(0x167),a0_0x46492c(0x133),a0_0x46492c(0x15f)+G][a0_0x46492c(0xe3)]('\x0a')});x[a0_0x46492c(0x160)](a0_0xbb978b,async()=>({'tools':[{'name':'commhub_reply','description':a0_0x46492c(0x152),'inputSchema':{'type':a0_0x46492c(0x13e),'properties':{'task_id':{'type':'string','description':a0_0x46492c(0xef)},'text':{'type':a0_0x46492c(0xe7),'description':a0_0x46492c(0xfd)},'status':{'type':a0_0x46492c(0xe7),'enum':[a0_0x46492c(0x104),a0_0x46492c(0x113),a0_0x46492c(0x131),a0_0x46492c(0x175),a0_0x46492c(0xe4),a0_0x46492c(0x120)],'description':a0_0x46492c(0x12c)}},'required':[a0_0x46492c(0x115)]}},{'name':a0_0x46492c(0x15e),'description':a0_0x46492c(0x102),'inputSchema':{'type':'object','properties':{'status':{'type':a0_0x46492c(0xe7),'enum':[a0_0x46492c(0x11d),a0_0x46492c(0x13f),a0_0x46492c(0x175),a0_0x46492c(0xe4)]},'task':{'type':'string','description':'Current\x20task\x20description'},'progress':{'type':'number','description':a0_0x46492c(0x10c)}},'required':[a0_0x46492c(0x124)]}},{'name':a0_0x46492c(0x12f),'description':a0_0x46492c(0x145),'inputSchema':{'type':'object','properties':{'alias':{'type':a0_0x46492c(0xe7),'description':'Target\x20session\x20alias'},'task':{'type':a0_0x46492c(0xe7),'description':a0_0x46492c(0x105)},'priority':{'type':a0_0x46492c(0xe7),'enum':[a0_0x46492c(0x149),a0_0x46492c(0x141),a0_0x46492c(0x16f)],'description':'Priority\x20(default:\x20normal)'}},'required':[a0_0x46492c(0xe0),a0_0x46492c(0xee)]}},{'name':a0_0x46492c(0xe2),'description':a0_0x46492c(0x11c),'inputSchema':{'type':a0_0x46492c(0x13e),'properties':{'alias':{'type':'string','description':a0_0x46492c(0x111)},'message':{'type':a0_0x46492c(0xe7),'description':a0_0x46492c(0x112)}},'required':['alias','message']}},{'name':'commhub_get_all_status','description':a0_0x46492c(0x116),'inputSchema':{'type':'object','properties':{}}}]}));async function Y(_0x5ddb0d,_0x3739ef){const _0xefb32c=a0_0x46492c;let _0x19925f=await fetch(j+'/mcp',{'method':'POST','headers':{'Content-Type':_0xefb32c(0xeb),'Accept':_0xefb32c(0xf4),...F?{'Authorization':_0xefb32c(0xfc)+F}:{}},'body':JSON[_0xefb32c(0x139)]({'jsonrpc':'2.0','id':0x1,'method':_0xefb32c(0xdd),'params':{'protocolVersion':'2025-03-26','capabilities':{},'clientInfo':{'name':_0xefb32c(0xd7),'version':_0xefb32c(0x13b)}}})});if(!_0x19925f['ok']){let _0x251074=await _0x19925f[_0xefb32c(0x115)]();return W(_0xefb32c(0x162)+_0x19925f[_0xefb32c(0x124)]+'\x20'+_0x251074[_0xefb32c(0xe6)](0x0,0x64)),{'ok':!0x1,'error':_0xefb32c(0x101)+_0x19925f[_0xefb32c(0x124)]};}await _0x19925f[_0xefb32c(0x115)]();let _0x5ed084=(await(await fetch(j+_0xefb32c(0x10d),{'method':_0xefb32c(0x156),'headers':{'Content-Type':_0xefb32c(0xeb),'Accept':_0xefb32c(0xf4),...F?{'Authorization':_0xefb32c(0xfc)+F}:{}},'body':JSON['stringify']({'jsonrpc':_0xefb32c(0x14f),'id':0x2,'method':'tools/call','params':{'name':_0x5ddb0d,'arguments':_0x3739ef}})}))[_0xefb32c(0x115)]())[_0xefb32c(0x134)]('\x0a')[_0xefb32c(0xfb)](_0x3b90be=>_0x3b90be['startsWith'](_0xefb32c(0x103)));if(_0x5ed084){let _0x83a4be=JSON[_0xefb32c(0xdc)](_0x5ed084['slice'](0x6));return _0x83a4be?.[_0xefb32c(0xdf)]?.[_0xefb32c(0xd8)]?.[0x0]?.[_0xefb32c(0x115)]?JSON['parse'](_0x83a4be[_0xefb32c(0xdf)][_0xefb32c(0xd8)][0x0][_0xefb32c(0x115)]):_0x83a4be;}return{'ok':!0x1,'error':_0xefb32c(0x158)};}x[a0_0x46492c(0x160)](a0_0xbc40e,async _0x492646=>{const _0x18116a=a0_0x46492c;let {name:_0x4fa7d7,arguments:_0x4c2a80}=_0x492646['params'];if(_0x4fa7d7==='commhub_reply'){let {task_id:_0xf56c28,text:_0x11dc7e,status:_0x479744}=_0x4c2a80;if(_0x479744==='completed'||_0x479744==='failed'||_0x479744==='cancelled'){let _0x5019ff=_0x479744==='completed'?_0x18116a(0x14b):_0x479744,_0x1e2a40=_0xf56c28?D['get'](_0xf56c28)||'hub':_0x18116a(0x127),_0x2698cb=await Y(_0x18116a(0x14d),{'alias':_0x1e2a40,'text':_0x11dc7e,'in_reply_to':_0xf56c28||void 0x0,'status':_0x5019ff,'from_session':G});if(_0xf56c28)D[_0x18116a(0x16e)](_0xf56c28);return{'content':[{'type':'text','text':JSON[_0x18116a(0x139)](_0x2698cb)}]};}let _0x470863=await Y(_0x18116a(0x16d),{'resume_id':K,'alias':G,'status':_0x479744==='blocked'?_0x18116a(0x175):_0x479744===_0x18116a(0xe4)?_0x18116a(0xe4):_0x18116a(0x11d),'task':_0x11dc7e[_0x18116a(0xe6)](0x0,0xc8),'output':_0x11dc7e});return{'content':[{'type':_0x18116a(0x115),'text':JSON[_0x18116a(0x139)](_0x470863)}]};}if(_0x4fa7d7===_0x18116a(0x15e)){let {status:_0x185d45,task:_0x4b0482,progress:_0x5ec4d4}=_0x4c2a80,_0x1ed774=await Y('report_status',{'resume_id':K,'alias':G,'status':_0x185d45,'task':_0x4b0482,'progress':_0x5ec4d4});return{'content':[{'type':'text','text':JSON[_0x18116a(0x139)](_0x1ed774)}]};}if(_0x4fa7d7===_0x18116a(0x12f)){let {alias:_0x43748a,task:_0x6b379b,priority:_0x12e710}=_0x4c2a80,_0x2f86fb=await Y(_0x18116a(0xde),{'alias':_0x43748a,'task':_0x6b379b,'priority':_0x12e710||_0x18116a(0x141),'from_session':G});return{'content':[{'type':_0x18116a(0x115),'text':JSON['stringify'](_0x2f86fb)}]};}if(_0x4fa7d7==='commhub_send_message'){let {alias:_0x103f32,message:_0x421998}=_0x4c2a80,_0x5b0e0d=await Y(_0x18116a(0x144),{'alias':_0x103f32,'message':_0x421998,'from_session':G});return{'content':[{'type':'text','text':JSON[_0x18116a(0x139)](_0x5b0e0d)}]};}if(_0x4fa7d7===_0x18116a(0xec)){let _0x50ef26=await Y(_0x18116a(0x121),{});return{'content':[{'type':'text','text':JSON[_0x18116a(0x139)](_0x50ef26)}]};}return{'content':[{'type':_0x18116a(0x115),'text':JSON[_0x18116a(0x139)]({'error':'unknown\x20tool'})}]};});var O=0x3e8,R=0x7530,T=0x36ee80;async function l(){const _0x1a10bf=a0_0x46492c;try{await Y(_0x1a10bf(0x16d),{'resume_id':K,'alias':G,'status':_0x1a10bf(0x13f),'server':a0_0x47b9f6(),'hostname':a0_0x47b9f6(),'agent':_0x1a10bf(0x15a),'project_dir':process[_0x1a10bf(0x155)](),'tmux_name':f||void 0x0}),W(_0x1a10bf(0x118)+G+_0x1a10bf(0xf2));}catch(_0x3f522d){W('re-register\x20failed:\x20'+_0x3f522d);}}async function o(){const _0x10c8d0=a0_0x46492c;let _0x344bd2=j+'/events/'+encodeURIComponent(G),_0x4850f1={};if(F)_0x4850f1['Authorization']=_0x10c8d0(0xfc)+F;W('connecting\x20to\x20'+_0x344bd2);let _0x1fc06f=O,_0x3b9dc9=!0x0,_0xfc7937=null;while(!0x0){try{let _0x345098=await fetch(_0x344bd2,{'headers':_0x4850f1});if(!_0x345098['ok']){if(W(_0x10c8d0(0x169)+_0x345098[_0x10c8d0(0x124)]+'\x20'+_0x345098[_0x10c8d0(0x16c)]),_0xfc7937=_0xfc7937??Date['now'](),Date[_0x10c8d0(0x106)]()-_0xfc7937>T){W(_0x10c8d0(0xf3)+j+_0x10c8d0(0xf6));return;}await N(_0x1fc06f),_0x1fc06f=Math['min'](_0x1fc06f*0x2,R);continue;}let _0x37008c=_0x345098[_0x10c8d0(0x168)][_0x10c8d0(0xe5)](),_0x3bd0fc=new TextDecoder(),_0xf98715='';_0x1fc06f=O;while(!0x0){let {done:_0x1437f7,value:_0x25c25b}=await _0x37008c[_0x10c8d0(0x130)]();if(_0x1437f7)break;_0xf98715+=_0x3bd0fc['decode'](_0x25c25b,{'stream':!0x0});let _0x145d17=_0xf98715[_0x10c8d0(0x134)]('\x0a\x0a');_0xf98715=_0x145d17[_0x10c8d0(0xdb)]()||'';for(let _0x173303 of _0x145d17){let _0x127596=_0x173303[_0x10c8d0(0x134)]('\x0a')[_0x10c8d0(0xfb)](_0x32c918=>_0x32c918[_0x10c8d0(0xf7)](_0x10c8d0(0x103)));if(!_0x127596)continue;try{let _0x50aebb=JSON[_0x10c8d0(0xdc)](_0x127596[_0x10c8d0(0xe6)](0x6));if(await a(_0x50aebb),_0x50aebb[_0x10c8d0(0x15b)]===_0x10c8d0(0x126)){if(_0xfc7937=null,!_0x3b9dc9)await l();_0x3b9dc9=!0x1;}}catch(_0x56b3fc){W('parse\x20error:\x20'+_0x56b3fc);}}}W(_0x10c8d0(0x10a));}catch(_0x468a93){W(_0x10c8d0(0xed)+_0x468a93);}if(_0xfc7937=_0xfc7937??Date['now'](),Date[_0x10c8d0(0x106)]()-_0xfc7937>T){W(_0x10c8d0(0xf3)+j+_0x10c8d0(0xf6));return;}await N(_0x1fc06f),_0x1fc06f=Math[_0x10c8d0(0x143)](_0x1fc06f*0x2,R);}}async function a(_0xe8eb58){const _0x1cd076=a0_0x46492c;if(_0xe8eb58[_0x1cd076(0x15b)]===_0x1cd076(0x126)){W(_0x1cd076(0x14e)+G+'\x22');return;}if(_0xe8eb58[_0x1cd076(0x15b)]===_0x1cd076(0xf0)){if(W('←\x20message\x20from\x20'+_0xe8eb58['from']+':\x20'+_0xe8eb58[_0x1cd076(0x125)]['slice'](0x0,0x3c)),await x[_0x1cd076(0x11e)]({'method':_0x1cd076(0x166),'params':{'content':_0xe8eb58[_0x1cd076(0x125)],'meta':{'sender':_0xe8eb58[_0x1cd076(0x11b)]||_0x1cd076(0x127),'sender_id':_0x1cd076(0x11a),'user':_0xe8eb58['from']||_0x1cd076(0x127),'priority':_0x1cd076(0x141)}}}),_0xe8eb58[_0x1cd076(0x10b)])await Y(_0x1cd076(0x14c),{'alias':G,'message_id':_0xe8eb58['message_id']});return;}if(_0xe8eb58['type']===_0x1cd076(0x163)||_0xe8eb58['type']===_0x1cd076(0x109)){W('←\x20'+_0xe8eb58[_0x1cd076(0x15b)]+_0x1cd076(0x154)+_0xe8eb58[_0x1cd076(0xea)]+'\x20priority='+(_0xe8eb58[_0x1cd076(0x165)]||_0x1cd076(0x141)));let _0x38ff0c=await Y(_0x1cd076(0x170),{'alias':G,'limit':0x5});if(_0x38ff0c?.['ok']&&_0x38ff0c[_0x1cd076(0x123)]?.[_0x1cd076(0xe1)]>0x0)for(let _0x39dd38 of _0x38ff0c[_0x1cd076(0x123)]){let _0x17a599={'sender':_0x39dd38[_0x1cd076(0x129)]||_0x1cd076(0x127),'sender_id':_0x1cd076(0x11a),'user':_0x39dd38[_0x1cd076(0x129)]||_0x1cd076(0x127),'task_id':_0x39dd38['id'],'priority':_0x39dd38[_0x1cd076(0x165)]||'normal'};D[_0x1cd076(0x13c)](_0x39dd38['id'],_0x39dd38['from_session']||_0x1cd076(0x127)),await x['notification']({'method':'notifications/claude/channel','params':{'content':_0x39dd38[_0x1cd076(0xd8)],'meta':_0x17a599}}),W(_0x1cd076(0x117)+_0x39dd38['id'][_0x1cd076(0xe6)](0x0,0x8)+_0x1cd076(0xd9)+_0x39dd38['from_session']+':\x20'+_0x39dd38['content'][_0x1cd076(0xe6)](0x0,0x3c)),await Y(_0x1cd076(0x14c),{'alias':G,'message_id':_0x39dd38['id']});}}}async function n(){const _0xcd959=a0_0x46492c;let _0x2396e9=new a0_0x281413();await x[_0xcd959(0x10e)](_0x2396e9),W('MCP\x20stdio\x20connected'),W(_0xcd959(0x12a)),o()['catch'](_0x5ad11f=>W(_0xcd959(0x114)+_0x5ad11f)),Y(_0xcd959(0x16d),{'resume_id':K,'alias':G,'status':'idle','server':a0_0x47b9f6(),'hostname':a0_0x47b9f6(),'agent':'claude-code','project_dir':process[_0xcd959(0x155)](),'tmux_name':f||void 0x0})[_0xcd959(0x147)](()=>W('registered\x20as\x20\x22'+G+_0xcd959(0x12d)+K[_0xcd959(0xe6)](0x0,0x8)+')'))['catch'](_0x1be390=>W(_0xcd959(0x15c)+_0x1be390)),setInterval(()=>{const _0x1b5722=_0xcd959;Y(_0x1b5722(0x16d),{'resume_id':K,'alias':G,'status':_0x1b5722(0x13f),'server':a0_0x47b9f6(),'hostname':a0_0x47b9f6(),'agent':'claude-code','project_dir':process['cwd'](),'tmux_name':f||void 0x0})[_0x1b5722(0x174)](_0x34d0b1=>W(_0x1b5722(0x146)+_0x34d0b1));},0x2bf20),W('ready\x20—\x20waiting\x20for\x20events');}n()[a0_0x46492c(0x174)](_0xbbcab7=>{const _0x1eb077=a0_0x46492c;W(_0x1eb077(0x171)+_0xbbcab7),process[_0x1eb077(0xfe)](0x1);});async function b(){const _0x2bc112=a0_0x46492c;W(_0x2bc112(0xf1)),await Y(_0x2bc112(0x16d),{'resume_id':K,'alias':G,'status':_0x2bc112(0x150),'task':_0x2bc112(0x151)})['catch'](()=>{}),process[_0x2bc112(0xfe)](0x0);}process[a0_0x46492c(0x108)]['on'](a0_0x46492c(0xfa),()=>b()),process['on']('SIGTERM',()=>b()),process['on'](a0_0x46492c(0x10f),()=>b());
|
|
2
|
+
const a0_0x2380c2=a0_0x4d59;(function(_0x3e376b,_0xa77d2c){const _0x310c38=a0_0x4d59,_0x360f8d=_0x3e376b();while(!![]){try{const _0x1800f3=-parseInt(_0x310c38(0x177))/0x1*(-parseInt(_0x310c38(0x195))/0x2)+-parseInt(_0x310c38(0x144))/0x3*(-parseInt(_0x310c38(0x19a))/0x4)+-parseInt(_0x310c38(0x166))/0x5+parseInt(_0x310c38(0x133))/0x6+parseInt(_0x310c38(0x19f))/0x7*(parseInt(_0x310c38(0x183))/0x8)+-parseInt(_0x310c38(0x124))/0x9+-parseInt(_0x310c38(0x17e))/0xa;if(_0x1800f3===_0xa77d2c)break;else _0x360f8d['push'](_0x360f8d['shift']());}catch(_0x2ced74){_0x360f8d['push'](_0x360f8d['shift']());}}}(a0_0x27f3,0xb64d2));import{readFileSync as a0_0x6820d6,existsSync as a0_0x11a009}from'fs';import{randomUUID as a0_0x268b37}from'crypto';import{join as a0_0x23af58}from'path';import{hostname as a0_0xfb0465}from'os';import{execSync as a0_0x45ddf0}from'child_process';import{Server as a0_0x7d3b09}from'@modelcontextprotocol/sdk/server/index.js';import{StdioServerTransport as a0_0xc7b897}from'@modelcontextprotocol/sdk/server/stdio.js';import{ListToolsRequestSchema as a0_0x2d5715,CallToolRequestSchema as a0_0xe760bd}from'@modelcontextprotocol/sdk/types.js';function I(_0x554e13){const _0x505753=a0_0x4d59;if(!a0_0x11a009(_0x554e13))return;for(let _0x47981a of a0_0x6820d6(_0x554e13,_0x505753(0x11c))[_0x505753(0x16e)]('\x0a')){let _0x140c1d=_0x47981a[_0x505753(0x13a)]();if(!_0x140c1d||_0x140c1d['startsWith']('#'))continue;let _0x116191=_0x140c1d[_0x505753(0x180)]('=');if(_0x116191<0x0)continue;let _0x557193=_0x140c1d[_0x505753(0x1a0)](0x0,_0x116191)[_0x505753(0x13a)](),_0x29098c=_0x140c1d[_0x505753(0x1a0)](_0x116191+0x1)[_0x505753(0x13a)]()[_0x505753(0x146)](/^["']|["']$/g,'');if(!process.env[_0x557193])process.env[_0x557193]=_0x29098c;}}var L=process.env.HOME||'~',U=a0_0x23af58(L,a0_0x2380c2(0x197));I(a0_0x23af58(U,a0_0x2380c2(0x189)));var v=process[a0_0x2380c2(0x19d)]()[a0_0x2380c2(0x146)](/\//g,'-');I(a0_0x23af58(U,v,'.env'));function d(){const _0x44dc3c=a0_0x2380c2;try{return a0_0x45ddf0('tmux\x20display-message\x20-p\x20\x27#S\x27',{'encoding':'utf-8','timeout':0x7d0})[_0x44dc3c(0x13a)]();}catch{return'';}}function m(){const _0x538289=a0_0x2380c2;try{let _0x4301db=a0_0x23af58(L,'.anet',_0x538289(0x19e));if(a0_0x11a009(_0x4301db))return JSON['parse'](a0_0x6820d6(_0x4301db,_0x538289(0x11c)));}catch{}return{};}var u=m(),j=process.env.COMMHUB_URL||u[a0_0x2380c2(0x15f)]||a0_0x2380c2(0x172),f=process.env.COMMHUB_TMUX||d();function r(){const _0x591ce5=a0_0x2380c2;if(process.env.COMMHUB_ALIAS&&process.env.COMMHUB_ALIAS['trim']())return process.env.COMMHUB_ALIAS[_0x591ce5(0x13a)]();return process['stderr'][_0x591ce5(0x15a)](_0x591ce5(0x156)+(_0x591ce5(0x15e)+(f||_0x591ce5(0x17b))+'\x20/\x20hostname='+a0_0xfb0465()+_0x591ce5(0x199))),'unattributed-'+process[_0x591ce5(0x161)];}function a0_0x4d59(_0x5b5ca2,_0x44e245){_0x5b5ca2=_0x5b5ca2-0x11a;const _0x27f351=a0_0x27f3();let _0x4d5941=_0x27f351[_0x5b5ca2];return _0x4d5941;}var G=r(),K=process.env.COMMHUB_RESUME_ID||process.env.CLAUDE_RESUME_ID||a0_0x268b37(),F=process.env.COMMHUB_TOKEN||u[a0_0x2380c2(0x136)]||'';function W(_0xb13af2){const _0x43cc96=a0_0x2380c2;let _0x43db02=new Date()[_0x43cc96(0x138)]()['slice'](0x0,0x8);process[_0x43cc96(0x149)][_0x43cc96(0x15a)]('['+_0x43db02+_0x43cc96(0x170)+_0xb13af2+'\x0a');}function N(_0x8dac13){return new Promise(_0x42d6de=>setTimeout(_0x42d6de,_0x8dac13));}W('ENV:\x20URL='+j+a0_0x2380c2(0x167)+G+a0_0x2380c2(0x182)+K[a0_0x2380c2(0x1a0)](0x0,0x8)+'...\x20TMUX='+(f||'none')+'\x20CWD='+process[a0_0x2380c2(0x19d)]()+a0_0x2380c2(0x18a)+v);var D=new Map(),x=new a0_0x7d3b09({'name':'commhub-channel','version':a0_0x2380c2(0x1a6)},{'capabilities':{'experimental':{'claude/channel':{}},'tools':{}},'instructions':[a0_0x2380c2(0x14c),a0_0x2380c2(0x17d),a0_0x2380c2(0x14f),'You\x20can\x20also\x20use\x20commhub_report_status\x20to\x20update\x20your\x20session\x20status.',a0_0x2380c2(0x175)+G][a0_0x2380c2(0x176)]('\x0a')});x[a0_0x2380c2(0x125)](a0_0x2d5715,async()=>({'tools':[{'name':a0_0x2380c2(0x13c),'description':'Reply\x20to\x20a\x20CommHub\x20task\x20—\x20report\x20completion\x20or\x20send\x20a\x20message\x20back\x20to\x20the\x20hub.','inputSchema':{'type':a0_0x2380c2(0x143),'properties':{'task_id':{'type':a0_0x2380c2(0x139),'description':a0_0x2380c2(0x17f)},'text':{'type':'string','description':a0_0x2380c2(0x1a5)},'status':{'type':'string','enum':[a0_0x2380c2(0x14e),a0_0x2380c2(0x141),a0_0x2380c2(0x1a4),a0_0x2380c2(0x16c),a0_0x2380c2(0x148),a0_0x2380c2(0x127)],'description':a0_0x2380c2(0x15c)}},'required':[a0_0x2380c2(0x16f)]}},{'name':a0_0x2380c2(0x191),'description':'Update\x20this\x20session\x27s\x20status\x20in\x20CommHub\x20(working/idle/blocked/error).\x20Returns\x20inbox_count.','inputSchema':{'type':a0_0x2380c2(0x143),'properties':{'status':{'type':a0_0x2380c2(0x139),'enum':[a0_0x2380c2(0x126),a0_0x2380c2(0x128),a0_0x2380c2(0x16c),a0_0x2380c2(0x148)]},'task':{'type':a0_0x2380c2(0x139),'description':a0_0x2380c2(0x179)},'progress':{'type':a0_0x2380c2(0x12f),'description':a0_0x2380c2(0x169)}},'required':[a0_0x2380c2(0x17a)]}},{'name':a0_0x2380c2(0x11d),'description':a0_0x2380c2(0x193),'inputSchema':{'type':a0_0x2380c2(0x143),'properties':{'alias':{'type':a0_0x2380c2(0x139),'description':a0_0x2380c2(0x1ad)},'task':{'type':'string','description':a0_0x2380c2(0x154)},'priority':{'type':a0_0x2380c2(0x139),'enum':['high',a0_0x2380c2(0x196),a0_0x2380c2(0x121)],'description':a0_0x2380c2(0x14a)}},'required':[a0_0x2380c2(0x1a8),a0_0x2380c2(0x14d)]}},{'name':a0_0x2380c2(0x174),'description':a0_0x2380c2(0x13b),'inputSchema':{'type':a0_0x2380c2(0x143),'properties':{'alias':{'type':a0_0x2380c2(0x139),'description':a0_0x2380c2(0x1ad)},'message':{'type':a0_0x2380c2(0x139),'description':a0_0x2380c2(0x194)}},'required':[a0_0x2380c2(0x1a8),'message']}},{'name':a0_0x2380c2(0x159),'description':a0_0x2380c2(0x173),'inputSchema':{'type':'object','properties':{}}}]}));async function Y(_0x26d8c5,_0x461895){const _0x5dd478=a0_0x2380c2;let _0x49dbe0=await fetch(j+_0x5dd478(0x186),{'method':_0x5dd478(0x158),'headers':{'Content-Type':_0x5dd478(0x131),'Accept':'application/json,\x20text/event-stream',...F?{'Authorization':_0x5dd478(0x132)+F}:{}},'body':JSON[_0x5dd478(0x12a)]({'jsonrpc':_0x5dd478(0x15d),'id':0x1,'method':_0x5dd478(0x1a2),'params':{'protocolVersion':_0x5dd478(0x11a),'capabilities':{},'clientInfo':{'name':'commhub-channel','version':_0x5dd478(0x1a6)}}})});if(!_0x49dbe0['ok']){let _0x570792=await _0x49dbe0[_0x5dd478(0x16f)]();return W(_0x5dd478(0x1ab)+_0x49dbe0[_0x5dd478(0x17a)]+'\x20'+_0x570792[_0x5dd478(0x1a0)](0x0,0x64)),{'ok':!0x1,'error':_0x5dd478(0x187)+_0x49dbe0[_0x5dd478(0x17a)]};}await _0x49dbe0[_0x5dd478(0x16f)]();let _0x12edf7=(await(await fetch(j+_0x5dd478(0x186),{'method':_0x5dd478(0x158),'headers':{'Content-Type':_0x5dd478(0x131),'Accept':_0x5dd478(0x1a3),...F?{'Authorization':_0x5dd478(0x132)+F}:{}},'body':JSON[_0x5dd478(0x12a)]({'jsonrpc':_0x5dd478(0x15d),'id':0x2,'method':_0x5dd478(0x137),'params':{'name':_0x26d8c5,'arguments':_0x461895}})}))[_0x5dd478(0x16f)]())['split']('\x0a')[_0x5dd478(0x150)](_0xfc2279=>_0xfc2279['startsWith']('data:\x20'));if(_0x12edf7){let _0x5ab394=JSON[_0x5dd478(0x129)](_0x12edf7[_0x5dd478(0x1a0)](0x6));return _0x5ab394?.[_0x5dd478(0x153)]?.[_0x5dd478(0x120)]?.[0x0]?.['text']?JSON['parse'](_0x5ab394[_0x5dd478(0x153)][_0x5dd478(0x120)][0x0][_0x5dd478(0x16f)]):_0x5ab394;}return{'ok':!0x1,'error':_0x5dd478(0x1a9)};}x[a0_0x2380c2(0x125)](a0_0xe760bd,async _0x34835b=>{const _0x345dc5=a0_0x2380c2;let {name:_0x365c7f,arguments:_0x21c2a3}=_0x34835b['params'];if(_0x365c7f===_0x345dc5(0x13c)){let {task_id:_0x19ca0a,text:_0xffb8be,status:_0x1ec47b}=_0x21c2a3;if(_0x1ec47b===_0x345dc5(0x14e)||_0x1ec47b===_0x345dc5(0x141)||_0x1ec47b==='cancelled'){let _0x47be5e=_0x1ec47b===_0x345dc5(0x14e)?'replied':_0x1ec47b,_0x4974c1=_0x19ca0a?D['get'](_0x19ca0a)||_0x345dc5(0x15f):_0x345dc5(0x15f),_0x42473d=await Y('send_reply',{'alias':_0x4974c1,'text':_0xffb8be,'in_reply_to':_0x19ca0a||void 0x0,'status':_0x47be5e,'from_session':G});if(_0x19ca0a)D[_0x345dc5(0x178)](_0x19ca0a);return{'content':[{'type':_0x345dc5(0x16f),'text':JSON[_0x345dc5(0x12a)](_0x42473d)}]};}let _0x164412=await Y(_0x345dc5(0x12d),{'resume_id':K,'alias':G,'status':_0x1ec47b===_0x345dc5(0x16c)?'blocked':_0x1ec47b===_0x345dc5(0x148)?_0x345dc5(0x148):_0x345dc5(0x126),'task':_0xffb8be[_0x345dc5(0x1a0)](0x0,0xc8),'output':_0xffb8be});return{'content':[{'type':_0x345dc5(0x16f),'text':JSON[_0x345dc5(0x12a)](_0x164412)}]};}if(_0x365c7f==='commhub_report_status'){let {status:_0x164155,task:_0x1ec597,progress:_0x23e143}=_0x21c2a3,_0x5a49e5=await Y(_0x345dc5(0x12d),{'resume_id':K,'alias':G,'status':_0x164155,'task':_0x1ec597,'progress':_0x23e143});return{'content':[{'type':_0x345dc5(0x16f),'text':JSON['stringify'](_0x5a49e5)}]};}if(_0x365c7f===_0x345dc5(0x11d)){let {alias:_0x441ef7,task:_0x53f02d,priority:_0x18f0de}=_0x21c2a3,_0x3d398f=await Y('send_task',{'alias':_0x441ef7,'task':_0x53f02d,'priority':_0x18f0de||_0x345dc5(0x196),'from_session':G});return{'content':[{'type':_0x345dc5(0x16f),'text':JSON[_0x345dc5(0x12a)](_0x3d398f)}]};}if(_0x365c7f===_0x345dc5(0x174)){let {alias:_0x4da32e,message:_0x51d7e6}=_0x21c2a3,_0x2d1668=await Y('send_message',{'alias':_0x4da32e,'message':_0x51d7e6,'from_session':G});return{'content':[{'type':_0x345dc5(0x16f),'text':JSON[_0x345dc5(0x12a)](_0x2d1668)}]};}if(_0x365c7f===_0x345dc5(0x159)){let _0x54cb99=await Y('get_all_status',{});return{'content':[{'type':_0x345dc5(0x16f),'text':JSON[_0x345dc5(0x12a)](_0x54cb99)}]};}return{'content':[{'type':'text','text':JSON[_0x345dc5(0x12a)]({'error':_0x345dc5(0x151)})}]};});function a0_0x27f3(){const _0x1f1e1c=['join','1ZYgJKr','delete','Current\x20task\x20description','status','(none)','\x20priority=','These\x20are\x20tasks\x20dispatched\x20by\x20the\x20hub\x20or\x20other\x20sessions\x20via\x20the\x20CommHub\x20Server.','22285350JcSJal','The\x20task_id\x20from\x20the\x20channel\x20message\x20(or\x20\x27hub\x27\x20for\x20general)','indexOf','warning:\x20could\x20not\x20register:\x20','\x20RESUME_ID=','736aexEeO','\x20from\x20','broadcast','/mcp','init\x20failed:\x20','get_inbox','.env','\x20PROJECT_ENV=','end','now','message',')\x20—\x20放弃自动重连。手动\x20anet\x20node\x20start\x20恢复。','parse\x20error:\x20','from','commhub_report_status','getReader','Send\x20a\x20task\x20to\x20another\x20session\x20via\x20CommHub.','Message\x20content','2586998lwWStq','normal','.claude/channels/commhub','fatal:\x20','.\x20Restart\x20node\x20via\x20`anet\x20node\x20start\x20<alias>`\x20so\x20the\x20env\x20is\x20set\x20explicitly\x20(#203).\x0a','8NIoCOQ','connecting\x20to\x20','registered\x20as\x20\x22','cwd','config.json','79905tjVhgT','slice','min','initialize','application/json,\x20text/event-stream','cancelled','Reply\x20text\x20/\x20result\x20summary','0.3.0','set','alias','no\x20response','SSE\x20connected\x20as\x20\x22','CommHub\x20init\x20failed:\x20','SSE\x20fatal:\x20','Target\x20session\x20alias','2025-03-26','commhub','utf-8','commhub_send_task',':\x20inbox_count=','messages','content','low','SSE\x20stream\x20ended,\x20reconnecting...','SSE\x20connection\x20error:\x20','8771481oWGDNy','setRequestHandler','working','in_progress','idle','parse','stringify','stdin','inbox_count','report_status','MCP\x20stdio\x20connected','number','exit','application/json','Bearer\x20','8464932rJCZVe','then','ack_inbox','token','tools/call','toTimeString','string','trim','Send\x20a\x20message\x20to\x20another\x20session\x20(no\x20task\x20lifecycle,\x20just\x20chat).\x20Use\x20for\x20replies\x20and\x20status\x20updates.','commhub_reply','connected','claude-code','SIGINT','shutting\x20down,\x20reporting\x20offline...','failed','re-register\x20failed:\x20','object','297885zujayn','new_message','replace','decode','error','stderr','Priority\x20(default:\x20normal)','from_session','Messages\x20from\x20CommHub\x20arrive\x20as\x20<channel\x20source=\x22commhub\x22\x20task_id=\x22...\x22\x20priority=\x22...\x22\x20from=\x22...\x22>','task','completed','Reply\x20using\x20the\x20commhub_reply\x20tool\x20to\x20report\x20status\x20or\x20results\x20back.','find','unknown\x20tool','heartbeat\x20failed:\x20','result','Task\x20content','new_task','[commhub]\x20WARN:\x20COMMHUB_ALIAS\x20env\x20var\x20is\x20unset\x20—\x20outbound\x20from_session\x20','offline','POST','commhub_get_all_status','write','connect','Task\x20outcome:\x20completed/failed/cancelled\x20for\x20final\x20results,\x20blocked/error/in_progress\x20for\x20status\x20updates','2.0','would\x20mis-attribute.\x20Refusing\x20to\x20guess\x20from\x20TMUX_NAME=','hub','data:\x20','pid','type','→\x20injected\x20task\x20','SSE\x20连续\x20>1h\x20连不上\x20hub\x20(','body','16205ZGJAkC','\x20ALIAS=','message_id','Progress\x200-100','priority','catch','blocked','SIGTERM','split','text',']\x20[commhub]\x20','notifications/claude/channel','http://127.0.0.1:9200','Get\x20status\x20of\x20all\x20sessions\x20from\x20CommHub.','commhub_send_message','Session\x20alias:\x20'];a0_0x27f3=function(){return _0x1f1e1c;};return a0_0x27f3();}var O=0x3e8,R=0x7530,T=0x36ee80;async function l(){const _0x1e13c0=a0_0x2380c2;try{await Y(_0x1e13c0(0x12d),{'resume_id':K,'alias':G,'status':'idle','server':a0_0xfb0465(),'hostname':a0_0xfb0465(),'agent':'claude-code','project_dir':process['cwd'](),'tmux_name':f||void 0x0}),W('re-registered\x20as\x20\x22'+G+'\x22\x20after\x20SSE\x20reconnect');}catch(_0x5984cc){W(_0x1e13c0(0x142)+_0x5984cc);}}async function o(){const _0x46274a=a0_0x2380c2;let _0x548f22=j+'/events/'+encodeURIComponent(G),_0x442a78={};if(F)_0x442a78['Authorization']=_0x46274a(0x132)+F;W(_0x46274a(0x19b)+_0x548f22);let _0x372567=O,_0x3a1850=!0x0,_0x219a75=null;while(!0x0){try{let _0x57820b=await fetch(_0x548f22,{'headers':_0x442a78});if(!_0x57820b['ok']){if(W('SSE\x20error:\x20'+_0x57820b['status']+'\x20'+_0x57820b['statusText']),_0x219a75=_0x219a75??Date[_0x46274a(0x18c)](),Date[_0x46274a(0x18c)]()-_0x219a75>T){W(_0x46274a(0x164)+j+_0x46274a(0x18e));return;}await N(_0x372567),_0x372567=Math['min'](_0x372567*0x2,R);continue;}let _0x4693b6=_0x57820b[_0x46274a(0x165)][_0x46274a(0x192)](),_0x2888d9=new TextDecoder(),_0xb1d270='';_0x372567=O;while(!0x0){let {done:_0x3b97b5,value:_0x5c237c}=await _0x4693b6['read']();if(_0x3b97b5)break;_0xb1d270+=_0x2888d9[_0x46274a(0x147)](_0x5c237c,{'stream':!0x0});let _0x385b85=_0xb1d270[_0x46274a(0x16e)]('\x0a\x0a');_0xb1d270=_0x385b85['pop']()||'';for(let _0xab83f0 of _0x385b85){let _0x1cc695=_0xab83f0[_0x46274a(0x16e)]('\x0a')[_0x46274a(0x150)](_0x74a2e0=>_0x74a2e0['startsWith'](_0x46274a(0x160)));if(!_0x1cc695)continue;try{let _0x4cb2a5=JSON[_0x46274a(0x129)](_0x1cc695[_0x46274a(0x1a0)](0x6));if(await a(_0x4cb2a5),_0x4cb2a5['type']===_0x46274a(0x13d)){if(_0x219a75=null,!_0x3a1850)await l();_0x3a1850=!0x1;}}catch(_0x28f3a8){W(_0x46274a(0x18f)+_0x28f3a8);}}}W(_0x46274a(0x122));}catch(_0x5a6f73){W(_0x46274a(0x123)+_0x5a6f73);}if(_0x219a75=_0x219a75??Date[_0x46274a(0x18c)](),Date[_0x46274a(0x18c)]()-_0x219a75>T){W(_0x46274a(0x164)+j+_0x46274a(0x18e));return;}await N(_0x372567),_0x372567=Math[_0x46274a(0x1a1)](_0x372567*0x2,R);}}async function a(_0x345e09){const _0x5bd200=a0_0x2380c2;if(_0x345e09[_0x5bd200(0x162)]===_0x5bd200(0x13d)){W(_0x5bd200(0x1aa)+G+'\x22');return;}if(_0x345e09[_0x5bd200(0x162)]===_0x5bd200(0x145)){if(W('←\x20message\x20from\x20'+_0x345e09[_0x5bd200(0x190)]+':\x20'+_0x345e09['message'][_0x5bd200(0x1a0)](0x0,0x3c)),await x['notification']({'method':_0x5bd200(0x171),'params':{'content':_0x345e09[_0x5bd200(0x18d)],'meta':{'sender':_0x345e09[_0x5bd200(0x190)]||_0x5bd200(0x15f),'sender_id':_0x5bd200(0x11b),'user':_0x345e09['from']||_0x5bd200(0x15f),'priority':_0x5bd200(0x196)}}}),_0x345e09[_0x5bd200(0x168)])await Y(_0x5bd200(0x135),{'alias':G,'message_id':_0x345e09[_0x5bd200(0x168)]});return;}if(_0x345e09['type']===_0x5bd200(0x155)||_0x345e09[_0x5bd200(0x162)]===_0x5bd200(0x185)){W('←\x20'+_0x345e09[_0x5bd200(0x162)]+_0x5bd200(0x11e)+_0x345e09[_0x5bd200(0x12c)]+_0x5bd200(0x17c)+(_0x345e09[_0x5bd200(0x16a)]||_0x5bd200(0x196)));let _0x105937=await Y(_0x5bd200(0x188),{'alias':G,'limit':0x5});if(_0x105937?.['ok']&&_0x105937['messages']?.['length']>0x0)for(let _0x79521e of _0x105937[_0x5bd200(0x11f)]){let _0x3f650f={'sender':_0x79521e[_0x5bd200(0x14b)]||_0x5bd200(0x15f),'sender_id':_0x5bd200(0x11b),'user':_0x79521e[_0x5bd200(0x14b)]||_0x5bd200(0x15f),'task_id':_0x79521e['id'],'priority':_0x79521e[_0x5bd200(0x16a)]||_0x5bd200(0x196)};D[_0x5bd200(0x1a7)](_0x79521e['id'],_0x79521e[_0x5bd200(0x14b)]||_0x5bd200(0x15f)),await x['notification']({'method':_0x5bd200(0x171),'params':{'content':_0x79521e['content'],'meta':_0x3f650f}}),W(_0x5bd200(0x163)+_0x79521e['id'][_0x5bd200(0x1a0)](0x0,0x8)+_0x5bd200(0x184)+_0x79521e[_0x5bd200(0x14b)]+':\x20'+_0x79521e[_0x5bd200(0x120)][_0x5bd200(0x1a0)](0x0,0x3c)),await Y('ack_inbox',{'alias':G,'message_id':_0x79521e['id']});}}}async function n(){const _0x5b3d6e=a0_0x2380c2;let _0x333ac3=new a0_0xc7b897();await x[_0x5b3d6e(0x15b)](_0x333ac3),W(_0x5b3d6e(0x12e)),W('starting\x20SSE\x20listener...'),o()[_0x5b3d6e(0x16b)](_0x49d02e=>W(_0x5b3d6e(0x1ac)+_0x49d02e)),Y(_0x5b3d6e(0x12d),{'resume_id':K,'alias':G,'status':'idle','server':a0_0xfb0465(),'hostname':a0_0xfb0465(),'agent':_0x5b3d6e(0x13e),'project_dir':process['cwd'](),'tmux_name':f||void 0x0})[_0x5b3d6e(0x134)](()=>W(_0x5b3d6e(0x19c)+G+'\x22\x20('+K[_0x5b3d6e(0x1a0)](0x0,0x8)+')'))[_0x5b3d6e(0x16b)](_0x4d44b3=>W(_0x5b3d6e(0x181)+_0x4d44b3)),setInterval(()=>{const _0x181a9e=_0x5b3d6e;Y(_0x181a9e(0x12d),{'resume_id':K,'alias':G,'status':_0x181a9e(0x128),'server':a0_0xfb0465(),'hostname':a0_0xfb0465(),'agent':_0x181a9e(0x13e),'project_dir':process['cwd'](),'tmux_name':f||void 0x0})['catch'](_0x4fae60=>W(_0x181a9e(0x152)+_0x4fae60));},0x2bf20),W('ready\x20—\x20waiting\x20for\x20events');}n()[a0_0x2380c2(0x16b)](_0x1f7c88=>{const _0xdb0100=a0_0x2380c2;W(_0xdb0100(0x198)+_0x1f7c88),process['exit'](0x1);});async function b(){const _0x33e55d=a0_0x2380c2;W(_0x33e55d(0x140)),await Y(_0x33e55d(0x12d),{'resume_id':K,'alias':G,'status':_0x33e55d(0x157),'task':'session\x20disconnected'})['catch'](()=>{}),process[_0x33e55d(0x130)](0x0);}process[a0_0x2380c2(0x12b)]['on'](a0_0x2380c2(0x18b),()=>b()),process['on'](a0_0x2380c2(0x16d),()=>b()),process['on'](a0_0x2380c2(0x13f),()=>b());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sleep2agi/agent-network",
|
|
3
|
-
"version": "2.2.22-preview.
|
|
3
|
+
"version": "2.2.22-preview.2",
|
|
4
4
|
"description": "AI Agent Network CLI — Local-first multi-agent orchestration across 4 runtimes (Claude Code CLI / Claude Agent SDK / Codex SDK / Grok Build ACP) and 8+ LLM providers (Anthropic / OpenAI / xAI Grok / MiniMax / DeepSeek / GLM / Kimi / InternLM / Xiaomi MiMo / OpenRouter). Apache 2.0.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/src/client.js",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
21
|
"typecheck": "tsc --noEmit",
|
|
22
|
+
"test:feishu-bridge": "bun tests/feishu-bridge-ackplaceholder.test.ts",
|
|
22
23
|
"build": "bun build src/client.ts --outdir dist/src --target node --minify && bun build bin/cli.ts --outdir dist/bin --target node --minify --external @sleep2agi/commhub-server --external bun:sqlite --external '../../server/*' && bun build src/node-server.ts --outdir dist/src --target node --minify --external @modelcontextprotocol/sdk && bun build src/im/feishu/worker.ts --outdir dist/src/im/feishu --target node --minify --external @larksuiteoapi/node-sdk && tsc --emitDeclarationOnly --declaration --outDir dist && npx javascript-obfuscator dist/bin/cli.js --output dist/bin/cli.js --compact true --string-array true --string-array-encoding base64 && npx javascript-obfuscator dist/src/client.js --output dist/src/client.js --compact true --string-array true && npx javascript-obfuscator dist/src/node-server.js --output dist/src/node-server.js --compact true --string-array true",
|
|
23
24
|
"prepublishOnly": "npm run build"
|
|
24
25
|
},
|