@easbot/gateway 0.2.48 → 0.3.0
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/chunks/chunk-3EE2AOK7.mjs +44 -0
- package/dist/chunks/chunk-6C5TBG7Z.cjs +1 -0
- package/dist/chunks/chunk-CPQSQ7FU.cjs +44 -0
- package/dist/chunks/chunk-HQBRVVXS.mjs +1 -0
- package/dist/chunks/{permissions-VBDNAQUT.cjs → permissions-CQIMDMA3.cjs} +1 -1
- package/dist/chunks/{permissions-42BQOY5P.mjs → permissions-VGMKDEK7.mjs} +1 -1
- package/dist/chunks/server-7LXANJ4O.cjs +1 -0
- package/dist/chunks/server-XGZGHXC5.mjs +1 -0
- package/dist/index.cjs +31 -31
- package/dist/index.d.cts +2 -45
- package/dist/index.d.ts +2 -45
- package/dist/index.mjs +29 -29
- package/package.json +5 -5
- package/dist/chunks/chunk-7OFQ65NG.mjs +0 -7
- package/dist/chunks/chunk-AUPHFE34.cjs +0 -7
- package/dist/chunks/chunk-GY3SWWW3.cjs +0 -1
- package/dist/chunks/chunk-HAMGVOQD.mjs +0 -1
- package/dist/chunks/chunk-LBRRMDDL.mjs +0 -44
- package/dist/chunks/chunk-RZS4QZWL.cjs +0 -44
- package/dist/chunks/log-JFEBRH2W.cjs +0 -1
- package/dist/chunks/log-MIT4H7S5.mjs +0 -1
- package/dist/chunks/server-4SVVHWFK.cjs +0 -1
- package/dist/chunks/server-BJCPH37W.mjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var d=Object.defineProperty;var e=(b,a,c)=>a in b?d(b,a,{enumerable:true,configurable:true,writable:true,value:c}):b[a]=c;var f=(b,a,c)=>e(b,typeof a!="symbol"?a+"":a,c);export{f as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var chunkTQ74GHLT_cjs=require('./chunk-TQ74GHLT.cjs');require('./chunk-
|
|
1
|
+
'use strict';var chunkTQ74GHLT_cjs=require('./chunk-TQ74GHLT.cjs');require('./chunk-6C5TBG7Z.cjs');Object.defineProperty(exports,"clearPermissionStateForTests",{enumerable:true,get:function(){return chunkTQ74GHLT_cjs.e}});Object.defineProperty(exports,"consumePendingPermission",{enumerable:true,get:function(){return chunkTQ74GHLT_cjs.d}});Object.defineProperty(exports,"getActivePermissionChat",{enumerable:true,get:function(){return chunkTQ74GHLT_cjs.b}});Object.defineProperty(exports,"savePendingPermission",{enumerable:true,get:function(){return chunkTQ74GHLT_cjs.c}});Object.defineProperty(exports,"setActivePermissionChat",{enumerable:true,get:function(){return chunkTQ74GHLT_cjs.a}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{e as clearPermissionStateForTests,d as consumePendingPermission,b as getActivePermissionChat,c as savePendingPermission,a as setActivePermissionChat}from'./chunk-NXFFFRVB.mjs';import'./chunk-
|
|
1
|
+
export{e as clearPermissionStateForTests,d as consumePendingPermission,b as getActivePermissionChat,c as savePendingPermission,a as setActivePermissionChat}from'./chunk-NXFFFRVB.mjs';import'./chunk-HQBRVVXS.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunkCPQSQ7FU_cjs=require('./chunk-CPQSQ7FU.cjs');require('./chunk-6C5TBG7Z.cjs');Object.defineProperty(exports,"ChannelPluginLoader",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.oa}});Object.defineProperty(exports,"GatewayServer",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.$a}});Object.defineProperty(exports,"GatewayWebSocketServer",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.pa}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{oa as ChannelPluginLoader,$a as GatewayServer,pa as GatewayWebSocketServer}from'./chunk-3EE2AOK7.mjs';import'./chunk-HQBRVVXS.mjs';
|
package/dist/index.cjs
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
'use strict';var chunkTQ74GHLT_cjs=require('./chunks/chunk-TQ74GHLT.cjs'),
|
|
2
|
-
`);}async function
|
|
1
|
+
'use strict';var chunkTQ74GHLT_cjs=require('./chunks/chunk-TQ74GHLT.cjs'),chunkCPQSQ7FU_cjs=require('./chunks/chunk-CPQSQ7FU.cjs'),chunk6C5TBG7Z_cjs=require('./chunks/chunk-6C5TBG7Z.cjs'),utils=require('@easbot/utils'),qrcode=require('qrcode'),fs=require('fs'),index_js=require('@modelcontextprotocol/sdk/server/index.js'),stdio_js=require('@modelcontextprotocol/sdk/server/stdio.js'),types_js=require('@modelcontextprotocol/sdk/types.js');var g=utils.Log.create({service:"gateway"}),P=class t extends Error{constructor(e,n,o){super(e);chunk6C5TBG7Z_cjs.a(this,"type");chunk6C5TBG7Z_cjs.a(this,"stage");chunk6C5TBG7Z_cjs.a(this,"cause");this.type="GatewayInitializationError",this.stage=n,this.cause=o,Error.captureStackTrace&&Error.captureStackTrace(this,t);}};function oe(t){let r=["ECONNRESET","EPIPE","ETIMEDOUT","ECONNREFUSED","ENOTFOUND","EHOSTUNREACH","ENETUNREACH"],e=t.code;return r.includes(e??"")}function Nt(){process.on("unhandledRejection",t=>{let r=t instanceof Error?t:new Error(String(t));oe(r)||g.error("unhandled promise rejection",{error:r.message,stack:r.stack});}),process.on("uncaughtException",t=>{oe(t)||(g.error("uncaught exception",{error:t.message,stack:t.stack}),process.exit(1));});}exports.Gateway=void 0;(rr=>{let t={initialized:false,initPromise:null,directory:".easbot",config:null},r,e={server:null,config:null,initialized:false,status:"stopped"};async function n(a={}){if(t.initialized)return;if(t.initPromise)return t.initPromise;let l={directory:a.directory??".easbot",printLogs:a.printLogs??false,logLevel:a.logLevel??"INFO"};return t.directory=l.directory,t.initPromise=(async()=>{chunkCPQSQ7FU_cjs.Z();try{Nt();}catch(c){throw new P("Failed to install unhandled exception handlers","server",c instanceof Error?c:void 0)}utils.Fetch.hasProxyConfigured()&&(utils.Fetch.enableProxy({connectTimeout:1e4,keepAliveTimeout:3e4}),g.info("global proxy enabled",{proxyUrl:utils.Fetch.getProxyUrl()}));try{t.config=await chunkCPQSQ7FU_cjs.w(l.directory);}catch(c){throw new P("Failed to load gateway configuration","config",c instanceof Error?c:void 0)}t.initialized=true,g.info("gateway runtime initialized",{directory:l.directory,logLevel:l.logLevel});})(),t.initPromise}rr.init=n;function o(){return t.initialized}rr.isInitialized=o;function u(){return r||(r=async()=>{if(!t.initialized)throw new P("Gateway not initialized. Call init() first.","server");let a=chunkCPQSQ7FU_cjs._(),l=await chunkCPQSQ7FU_cjs.w(a.directory);return l.server?.enabled?(e={server:null,config:l,initialized:true,status:"stopped"},g.info("gateway initialized",{port:l.server?.port,hostname:l.server?.hostname}),e):(g.debug("gateway server disabled or not configured"),{server:null,config:l,initialized:true,status:"stopped"})}),r}function d(){return u()()}rr.state=d;async function y(){return (await d()).server}rr.get=y;async function i(){return (await d()).config?.server?.enabled??false}rr.isEnabled=i;async function f(){return (await d()).config}rr.config=f;function p(){return e.status}rr.getStatus=p;async function s(a){g.debug("Gateway.start: called"),t.initialized||await n();let l=await d();if(!(l.config?.server?.enabled??true))throw g.warn("gateway server is disabled"),new Error("Gateway server is disabled");if(e.status==="running"){g.info("gateway server is already running");return}if(e.status==="starting"){g.info("gateway server is starting");return}e.status="starting";try{let c={...l.config?.server,...a};g.debug("gateway start: creating server with config",{port:c.port,hostname:c.hostname,path:c.path,https:c.https?.enabled});let E=await ge(c);e.server=E,e.status="running",e.error=void 0,g.info("gateway server started",{port:c.port,hostname:c.hostname});}catch(c){throw e.status="error",e.error=c instanceof Error?c.message:String(c),g.error("failed to start gateway server",{error:e.error}),c}}rr.start=s;async function m(){if(e.status==="stopped"){g.info("gateway server is already stopped");return}if(e.status==="stopping"){g.info("gateway server is stopping");return}e.status="stopping";try{e.server&&await e.server.stop(),e.server=null,e.status="stopped",e.error=void 0,await utils.Log.close(),g.info("gateway server stopped");}catch(a){throw e.status="error",e.error=a instanceof Error?a.message:String(a),g.error("failed to stop gateway server",{error:e.error}),a}}rr.stop=m;async function C(a){g.info("restarting gateway server"),(e.status==="running"||e.status==="starting")&&await m(),await s(a);}rr.restart=C;async function Y(){let a=chunkCPQSQ7FU_cjs._(),l=await chunkCPQSQ7FU_cjs.w(a.directory);return e.config=l,t.config=l,g.info("gateway config reloaded"),l}rr.reloadConfig=Y;async function ge(a,l){g.debug("createGatewayServer: starting");let{GatewayServer:G}=await import('./chunks/server-7LXANJ4O.cjs'),c=new G(a),E=l?.startupTimeout??3e4;if(await(async()=>{let S=new Promise((x,le)=>{setTimeout(()=>{le(new Error(`Gateway server startup timeout after ${E}ms`));},E);});try{await Promise.race([c.start(),S]);}catch(x){g.error("gateway server start failed, attempting cleanup",{error:x instanceof Error?x.message:String(x)});try{await c.stop();}catch{}throw x}})(),l?.onStarted)try{await l.onStarted(c);}catch(S){g.warn("server started but onStarted callback failed",{error:S instanceof Error?S.message:String(S)});}return g.info("gateway server created and started",{port:a.port,hostname:a.hostname}),c}rr.createGatewayServer=ge;})(exports.Gateway||(exports.Gateway={}));async function qt(t){let r=await qrcode.toString(t,{type:"terminal",errorCorrectionLevel:"L",small:true});process.stderr.write(`${r}
|
|
2
|
+
`);}async function _(t){let r=await fetch(`${t}/ilink/bot/get_bot_qrcode?bot_type=3`);if(!r.ok)throw new Error(`Failed to get QR code: HTTP ${r.status}`);let e=await r.json();if(!e.qrcode)throw new Error("No qrcode in response");let n=e.qrcode_img_content||"";return n&&await qt(n),{qrcodeUrl:n,qrcodeId:e.qrcode,message:"Scan the QR code with WeChat to connect."}}async function V(t){let{qrcodeId:r,apiBaseUrl:e,timeoutMs:n=48e4,maxRetries:o=3}=t,u=Date.now()+n,d=r,y=0;for(;Date.now()<u;){try{let i=new AbortController,f=setTimeout(()=>i.abort(),6e4),p=await fetch(`${e}/ilink/bot/get_qrcode_status?qrcode=${encodeURIComponent(d)}`,{headers:{"iLink-App-ClientVersion":"1"},signal:i.signal});if(clearTimeout(f),!p.ok)throw new Error(`HTTP ${p.status}`);let s=await p.json();switch(s.status){case "confirmed":return {connected:!0,token:s.bot_token,accountId:s.ilink_bot_id,baseUrl:s.baseurl,userId:s.ilink_user_id,message:"Connected to WeChat successfully!"};case "scaned":process.stderr.write(`QR code scanned, waiting for confirmation...
|
|
3
3
|
`);break;case "expired":{if(y+=1,y>=o)return {connected:!1,message:"QR code expired after maximum retries."};process.stderr.write(`QR code expired, refreshing...
|
|
4
|
-
`),d=(await
|
|
5
|
-
`);break;default:break}}catch(i){if(i instanceof Error&&i.name==="AbortError")continue;throw i}await new Promise(i=>setTimeout(i,1e3));}return {connected:false,message:"Login timed out."}}function jt(
|
|
6
|
-
`)}function Vt(
|
|
7
|
-
`);}}),await n.connect(o);let u=
|
|
8
|
-
`),clearInterval(p),i();}},5e3);r.logForDebugging("[Weixin MCP] Starting poll loop"),await
|
|
4
|
+
`),d=(await _(e)).qrcodeId;break}case "wait":process.stderr.write(`QR code waiting, please wait...
|
|
5
|
+
`);break;default:break}}catch(i){if(i instanceof Error&&i.name==="AbortError")continue;throw i}await new Promise(i=>setTimeout(i,1e3));}return {connected:false,message:"Login timed out."}}function jt(t){return ["Claude Code needs your approval.","",`Tool: ${t.tool_name}`,`Reason: ${t.description}`,`Input: ${t.input_preview}`,"",`Reply with: yes ${t.request_id}`,`Or deny with: no ${t.request_id}`].join(`
|
|
6
|
+
`)}function Vt(t){let r=new index_js.Server({name:"weixin",version:t},{capabilities:{experimental:{"claude/channel":{},"claude/channel/permission":{}},tools:{}},instructions:'Messages from WeChat arrive as <channel source="plugin:weixin:weixin" chat_id="..." sender_id="...">. Reply using the reply tool with the chat_id from the channel tag. Use absolute paths for file attachments.'});return r.setRequestHandler(types_js.ListToolsRequestSchema,async()=>({tools:[{name:"reply",description:"Reply to a WeChat message. Pass the chat_id from the channel tag.",inputSchema:{type:"object",properties:{chat_id:{type:"string",description:"The chat_id from the channel notification"},text:{type:"string",description:"The reply text"},files:{type:"array",items:{type:"string"},description:"Optional absolute file paths to attach"}},required:["chat_id","text"]}},{name:"send_typing",description:"Send a typing indicator to a WeChat user.",inputSchema:{type:"object",properties:{chat_id:{type:"string",description:"The chat_id (user ID)"}},required:["chat_id"]}}]})),r.setRequestHandler(types_js.CallToolRequestSchema,async e=>{let{name:n,arguments:o}=e.params,u=chunkCPQSQ7FU_cjs.Ha();if(!u)return {content:[{type:"text",text:"WeChat not connected. Run `easbot weixin login` first."}],isError:true};let d=u.baseUrl||chunkCPQSQ7FU_cjs.Ea,y=chunkCPQSQ7FU_cjs.Fa;switch(n){case "reply":{let i=typeof o?.chat_id=="string"?o.chat_id:"",f=typeof o?.text=="string"?o.text:"",p=Array.isArray(o?.files)?o.files.filter(m=>typeof m=="string"):void 0;if(!i||!f)return {content:[{type:"text",text:"Missing chat_id or text parameter."}],isError:true};let s=chunkCPQSQ7FU_cjs.Qa(i)||"";try{if(p&&p.length>0){for(let[m,C]of p.entries()){if(!fs.existsSync(C))return {content:[{type:"text",text:`File not found: ${C}`}],isError:!0};await chunkCPQSQ7FU_cjs.Pa({filePath:C,to:i,text:m===0?f:"",baseUrl:d,token:u.token,contextToken:s,cdnBaseUrl:y});}return {content:[{type:"text",text:"Message sent with attachments."}]}}return await chunkCPQSQ7FU_cjs.Oa({to:i,text:f,baseUrl:d,token:u.token,contextToken:s}),{content:[{type:"text",text:"Message sent."}]}}catch(m){return {content:[{type:"text",text:`Failed to send: ${m}`}],isError:true}}}case "send_typing":{let i=typeof o?.chat_id=="string"?o.chat_id:"";if(!i)return {content:[{type:"text",text:"Missing chat_id parameter."}],isError:true};try{let f=chunkCPQSQ7FU_cjs.Qa(i),p=await chunkCPQSQ7FU_cjs.Ka(d,u.token,i,f);return p.typing_ticket&&await chunkCPQSQ7FU_cjs.La(d,u.token,{ilink_user_id:i,typing_ticket:p.typing_ticket,status:chunkCPQSQ7FU_cjs.Ma.TYPING}),{content:[{type:"text",text:"Typing indicator sent."}]}}catch(f){return {content:[{type:"text",text:`Failed to send typing: ${f}`}],isError:true}}}default:return {content:[{type:"text",text:`Unknown tool: ${n}`}],isError:true}}}),r}async function ie(t,r){r.enableConfigs(),r.initializeAnalyticsSink();let e=chunkCPQSQ7FU_cjs.Ha();e||(process.stderr.write("[weixin] No account configured. Run `easbot weixin login` to connect your WeChat account.\n"),await Promise.all([r.shutdown1PEventLogging(),r.shutdownDatadog()]),process.exit(1));let n=Vt(t),o=new stdio_js.StdioServerTransport;r.registerPermissionHandler(n,async s=>{let m=s.channel_context?.chat_id,C=m?{chatId:m,contextToken:chunkCPQSQ7FU_cjs.Qa(m)}:chunkTQ74GHLT_cjs.b();if(!C){r.logForDebugging(`[Weixin MCP] No active chat available for permission request ${s.request_id}`);return}try{chunkTQ74GHLT_cjs.c(s,C.chatId,C.contextToken),await chunkCPQSQ7FU_cjs.Oa({to:C.chatId,text:jt(s),baseUrl:u,token:e.token,contextToken:C.contextToken||""});}catch(Y){process.stderr.write(`[weixin] Failed to relay permission request ${s.request_id}: ${Y}
|
|
7
|
+
`);}}),await n.connect(o);let u=e.baseUrl||chunkCPQSQ7FU_cjs.Ea,d=new AbortController,y=false,i=async()=>{y||(y=true,d.signal.aborted||d.abort(),await Promise.all([r.shutdown1PEventLogging(),r.shutdownDatadog()]),process.exit(0));};process.stdin.on("end",()=>{i();}),process.stdin.on("error",()=>{i();}),process.on("SIGINT",()=>{i();}),process.on("SIGTERM",()=>{i();}),process.on("SIGHUP",()=>{i();});let f=process.ppid,p=setInterval(()=>{try{process.kill(f,0);}catch{process.stderr.write(`[weixin] Parent process exited, shutting down...
|
|
8
|
+
`),clearInterval(p),i();}},5e3);r.logForDebugging("[Weixin MCP] Starting poll loop"),await chunkCPQSQ7FU_cjs.Ra({baseUrl:u,cdnBaseUrl:chunkCPQSQ7FU_cjs.Fa,token:e.token,onMessage:async s=>{await n.notification({method:"notifications/claude/channel",params:{content:s.text,meta:{chat_id:s.fromUserId,sender_id:s.fromUserId,message_id:s.messageId,...s.attachmentPath&&{attachment_path:s.attachmentPath},...s.attachmentType&&{attachment_type:s.attachmentType}}}});},onPermissionResponse:async s=>{await n.notification({method:"notifications/claude/channel/permission",params:{request_id:s.requestId,behavior:s.behavior}});},abortSignal:d.signal}),clearInterval(p),await i();}function ae(){process.stdout.write(["Usage:"," easbot weixin serve"," easbot weixin login"," easbot weixin login clear"," easbot weixin access pair <code>","","Current user (read from account.json):"," easbot weixin user",' easbot weixin ensure-user [--display-name "<name>"]'," easbot weixin remove-user"].join(`
|
|
9
9
|
`)+`
|
|
10
|
-
`);}async function Kt(
|
|
11
|
-
`);return}let r=
|
|
10
|
+
`);}async function Kt(t=false){if(t){chunkCPQSQ7FU_cjs.Ja(),process.stdout.write(`WeChat account cleared.
|
|
11
|
+
`);return}let r=chunkCPQSQ7FU_cjs.Ha();if(r){process.stdout.write(["Already connected:",` User ID: ${r.userId||"unknown"}`,` Connected since: ${utils.formatLocalISO(new Date(r.savedAt))}`,"","Run `easbot weixin login clear` to disconnect."].join(`
|
|
12
12
|
`)+`
|
|
13
13
|
`);return}process.stdout.write(`Starting WeChat QR login...
|
|
14
14
|
|
|
15
|
-
`);let
|
|
15
|
+
`);let e=await _(chunkCPQSQ7FU_cjs.Ea);process.stdout.write(`
|
|
16
16
|
Scan the QR code above with WeChat, or open this URL:
|
|
17
|
-
${
|
|
17
|
+
${e.qrcodeUrl||""}
|
|
18
18
|
|
|
19
|
-
`);let n=await
|
|
20
|
-
`),process.exit(1)),
|
|
19
|
+
`);let n=await V({qrcodeId:e.qrcodeId,apiBaseUrl:chunkCPQSQ7FU_cjs.Ea});(!n.connected||!n.token)&&(process.stderr.write(`Login failed: ${n.message}
|
|
20
|
+
`),process.exit(1)),chunkCPQSQ7FU_cjs.Ia({token:n.token,baseUrl:n.baseUrl||chunkCPQSQ7FU_cjs.Ea,userId:n.userId,savedAt:new Date().toISOString()}),process.stdout.write(["Connected successfully!",` User ID: ${n.userId||"unknown"}`,` Base URL: ${n.baseUrl||chunkCPQSQ7FU_cjs.Ea}`].join(`
|
|
21
21
|
`)+`
|
|
22
|
-
`);}function Yt(
|
|
22
|
+
`);}function Yt(t){(t[0]!=="pair"||!t[1])&&(ae(),process.exit(1));let r=chunkCPQSQ7FU_cjs.Na(t[1]);r||(process.stderr.write(`Invalid or expired pairing code.
|
|
23
23
|
`),process.exit(1)),process.stdout.write(`Paired successfully: ${r}
|
|
24
|
-
`);}function Jt(
|
|
24
|
+
`);}function Jt(t,r){let e={userId:r,channelId:"weixin-main"};for(let n=0;n<t.length;n++){let o=t[n];if(o==="--display-name"||o==="-d"){let u=t[++n];if(!u)return "--display-name requires a value";e.displayName=u;}else return `Unknown argument: ${o}`}return e}function ce(){let t=chunkCPQSQ7FU_cjs.Ha();return t?.userId||(process.stderr.write("No weixin account logged in. Run `easbot weixin login` first.\n"),process.exit(1)),t.userId}async function Xt(){try{let t=chunkCPQSQ7FU_cjs.Ha();if(!t){process.stdout.write(`No weixin account logged in.
|
|
25
25
|
`),process.stdout.write("Run `easbot weixin login` to bind your WeChat via iLink.\n");return}process.stdout.write(`weixin current user:
|
|
26
|
-
`),process.stdout.write(` userId: ${
|
|
27
|
-
`),process.stdout.write(` baseUrl: ${
|
|
28
|
-
`),process.stdout.write(` savedAt: ${utils.formatLocalISO(new Date(
|
|
29
|
-
`);let
|
|
30
|
-
`),process.stdout.write(` uid: ${
|
|
31
|
-
`),
|
|
32
|
-
`),
|
|
33
|
-
`),process.stdout.write(` lastSeen: ${utils.formatLocalISO(new Date(
|
|
26
|
+
`),process.stdout.write(` userId: ${t.userId??"(unknown)"}
|
|
27
|
+
`),process.stdout.write(` baseUrl: ${t.baseUrl}
|
|
28
|
+
`),process.stdout.write(` savedAt: ${utils.formatLocalISO(new Date(t.savedAt))}
|
|
29
|
+
`);let e=(await chunkCPQSQ7FU_cjs.Da()).find(n=>n.stableId===t.userId);e?(process.stdout.write(` contact: registered
|
|
30
|
+
`),process.stdout.write(` uid: ${e.uid}
|
|
31
|
+
`),e.profile.displayName&&process.stdout.write(` display: ${e.profile.displayName}
|
|
32
|
+
`),e.profile.username&&process.stdout.write(` username: ${e.profile.username}
|
|
33
|
+
`),process.stdout.write(` lastSeen: ${utils.formatLocalISO(new Date(e.lastSeenAt))}
|
|
34
34
|
`)):(process.stdout.write(` contact: not registered
|
|
35
|
-
`),process.stdout.write(" hint: run `easbot weixin ensure-user` to register\n"));}catch(
|
|
36
|
-
`),process.exit(1);}}async function Zt(
|
|
37
|
-
`),process.exit(1));try{let n=await
|
|
35
|
+
`),process.stdout.write(" hint: run `easbot weixin ensure-user` to register\n"));}catch(t){process.stderr.write(`user failed: ${t}
|
|
36
|
+
`),process.exit(1);}}async function Zt(t){let r=ce(),e=Jt(t,r);typeof e=="string"&&(process.stderr.write(`${e}
|
|
37
|
+
`),process.exit(1));try{let n=await chunkCPQSQ7FU_cjs.Ba(e),{contact:o,session:u,created:d}=n,y=d.contact&&d.session?"\u5DF2\u521B\u5EFA":"\u5DF2\u5B58\u5728\uFF08\u5DF2\u66F4\u65B0\uFF09";process.stdout.write([`[weixin routing] ${y} user: ${r}`,` contact.uid: ${o.uid}`,` contact.path: ${chunkCPQSQ7FU_cjs.xa()}/contacts/${o.platform}/${o.stableId}.json`,` session.id: ${u.id}`,` session.path: ${chunkCPQSQ7FU_cjs.ya()}/sessions.json`,` profile: ${JSON.stringify(o.profile)}`].join(`
|
|
38
38
|
`)+`
|
|
39
39
|
`);}catch(n){process.stderr.write(`ensure-user failed: ${n}
|
|
40
|
-
`),process.exit(1);}}async function er(
|
|
40
|
+
`),process.exit(1);}}async function er(t){let r=ce();t.length>0&&(process.stderr.write(`Unknown argument: ${t[0]}
|
|
41
41
|
`),process.stderr.write(`Usage: easbot weixin remove-user
|
|
42
|
-
`),process.exit(1));try{let
|
|
43
|
-
`);}catch(
|
|
44
|
-
`),process.exit(1);}}async function tr(
|
|
45
|
-
`),process.exit(1)),await ie(t??"0.0.0",r);return;case "login":await Kt(o[0]==="clear");return;case "access":Yt(o);return;case "user":await Xt();return;case "ensure-user":await Zt(o);return;case "remove-user":await er(o);return;default:ae();}}async function mn(e){let{Log:r}=await import('./chunks/log-JFEBRH2W.cjs'),t=false;await r.init({logDir:e.logDir??process.env.EASBOT_LOG_PATH??process.cwd(),print:e.print??false,dev:e.dev??t,level:e.level??("INFO")});}Object.defineProperty(exports,"AgentRegistry",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.Za}});Object.defineProperty(exports,"AgentRegistryConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.p}});Object.defineProperty(exports,"AgentSyncConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.k}});Object.defineProperty(exports,"AgentSyncManager",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs._a}});Object.defineProperty(exports,"AuthConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.j}});Object.defineProperty(exports,"BaseChannelPlugin",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.qa}});Object.defineProperty(exports,"ChannelConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.h}});Object.defineProperty(exports,"ChannelPluginLoader",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.oa}});Object.defineProperty(exports,"ChannelPluginRegistry",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.Xa}});Object.defineProperty(exports,"CircuitBreakerConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.o}});Object.defineProperty(exports,"ConnectionPoolConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.m}});Object.defineProperty(exports,"DEBUG_AGENT_FILTER",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.T}});Object.defineProperty(exports,"DEFAULT_AGENT_FILTER",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.S}});Object.defineProperty(exports,"DEFAULT_AGENT_REGISTRY_CONFIG",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.ha}});Object.defineProperty(exports,"DEFAULT_CONNECTION_POOL_CONFIG",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.ja}});Object.defineProperty(exports,"DEFAULT_SYNC_CONFIG",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.ia}});Object.defineProperty(exports,"DEFAULT_TOKEN_AUTH_CONFIG",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.ga}});Object.defineProperty(exports,"DEFAULT_WEBSOCKET_SERVER_CONFIG",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.fa}});Object.defineProperty(exports,"DiscordPlugin",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.sa}});Object.defineProperty(exports,"FeishuChannelConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.c}});Object.defineProperty(exports,"FeishuPlugin",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.ua}});Object.defineProperty(exports,"GatewayClientConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.s}});Object.defineProperty(exports,"GatewayClusterConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.l}});Object.defineProperty(exports,"GatewayConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.t}});Object.defineProperty(exports,"GatewayServer",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.$a}});Object.defineProperty(exports,"GatewayServerConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.r}});Object.defineProperty(exports,"GatewaySessionManager",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.na}});Object.defineProperty(exports,"HTTPSConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.i}});Object.defineProperty(exports,"MessageQueueConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.n}});Object.defineProperty(exports,"MessageRouter",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.ka}});Object.defineProperty(exports,"MessageStore",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.la}});Object.defineProperty(exports,"NostrChannelConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.g}});Object.defineProperty(exports,"NostrPlugin",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.Va}});Object.defineProperty(exports,"SdkEventBridge",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.R}});Object.defineProperty(exports,"SdkEventBus",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.Q}});Object.defineProperty(exports,"SdkEventType",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.P}});Object.defineProperty(exports,"SdkMessageCollector",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.U}});Object.defineProperty(exports,"SessionConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.q}});Object.defineProperty(exports,"SessionStore",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.ma}});Object.defineProperty(exports,"SignalChannelConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.f}});Object.defineProperty(exports,"SignalPlugin",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.Ua}});Object.defineProperty(exports,"SlackChannelConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.b}});Object.defineProperty(exports,"SlackPlugin",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.ta}});Object.defineProperty(exports,"TelegramChannelConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.a}});Object.defineProperty(exports,"TelegramPlugin",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.ra}});Object.defineProperty(exports,"WEIXIN_PLATFORM",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.wa}});Object.defineProperty(exports,"WeChatChannelConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.d}});Object.defineProperty(exports,"WeChatPlugin",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.va}});Object.defineProperty(exports,"WebChatChannelConfigSchema",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.e}});Object.defineProperty(exports,"WebChatPlugin",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.Ta}});Object.defineProperty(exports,"WeixinPlugin",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.Sa}});Object.defineProperty(exports,"clearConfigCache",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.z}});Object.defineProperty(exports,"convertToGatewayMessage",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.ba}});Object.defineProperty(exports,"createChannelPlugin",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.Wa}});Object.defineProperty(exports,"createDefaultSessionState",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.da}});Object.defineProperty(exports,"createGatewayMessage",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.$}});Object.defineProperty(exports,"createTextMessage",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.aa}});Object.defineProperty(exports,"ensureContact",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.za}});Object.defineProperty(exports,"ensureSession",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.Aa}});Object.defineProperty(exports,"ensureUser",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.Ba}});Object.defineProperty(exports,"generateSessionId",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.ca}});Object.defineProperty(exports,"generateSubscriptionId",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.ea}});Object.defineProperty(exports,"getAgentAdapter",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.W}});Object.defineProperty(exports,"getAgentRegistryConfig",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.G}});Object.defineProperty(exports,"getAuthConfig",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.L}});Object.defineProperty(exports,"getChannelConfig",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.C}});Object.defineProperty(exports,"getCircuitBreakerConfig",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.F}});Object.defineProperty(exports,"getClusterConfig",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.M}});Object.defineProperty(exports,"getConfig",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.x}});Object.defineProperty(exports,"getConfigDirectory",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.A}});Object.defineProperty(exports,"getConnectionPoolConfig",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.D}});Object.defineProperty(exports,"getDefaultAgent",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.N}});Object.defineProperty(exports,"getGatewayClientConfig",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.I}});Object.defineProperty(exports,"getGatewayClientUrl",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.J}});Object.defineProperty(exports,"getHTTPSConfig",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.K}});Object.defineProperty(exports,"getLogLevel",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.O}});Object.defineProperty(exports,"getMessageQueueConfig",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.E}});Object.defineProperty(exports,"getServerConfig",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.B}});Object.defineProperty(exports,"getSessionConfig",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.H}});Object.defineProperty(exports,"getSupportedPlatforms",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.Ya}});Object.defineProperty(exports,"hasAgentAdapter",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.X}});Object.defineProperty(exports,"isConfigLoaded",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.y}});Object.defineProperty(exports,"listWeixinContacts",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.Da}});Object.defineProperty(exports,"loadConfig",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.w}});Object.defineProperty(exports,"parsePartialConfig",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.v}});Object.defineProperty(exports,"removeUser",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.Ca}});Object.defineProperty(exports,"requireAgentAdapter",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.Y}});Object.defineProperty(exports,"setAgentAdapter",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.V}});Object.defineProperty(exports,"validateConfig",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.u}});Object.defineProperty(exports,"weixinSetStateDir",{enumerable:true,get:function(){return chunkRZS4QZWL_cjs.Ga}});exports.handleWeixinCli=tr;exports.initLog=mn;
|
|
42
|
+
`),process.exit(1));try{let e=await chunkCPQSQ7FU_cjs.Ca(r,"weixin-main");process.stdout.write(`[weixin routing] removed user: ${r} contact=${e.removed.contact} session=${e.removed.session}
|
|
43
|
+
`);}catch(e){process.stderr.write(`remove-user failed: ${e}
|
|
44
|
+
`),process.exit(1);}}async function tr(t,r,e){let[n,...o]=t;switch(n){case "serve":r||(process.stderr.write(`[weixin] serve handler not available in this context.
|
|
45
|
+
`),process.exit(1)),await ie(e??"0.0.0",r);return;case "login":await Kt(o[0]==="clear");return;case "access":Yt(o);return;case "user":await Xt();return;case "ensure-user":await Zt(o);return;case "remove-user":await er(o);return;default:ae();}}Object.defineProperty(exports,"AgentRegistry",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.Za}});Object.defineProperty(exports,"AgentRegistryConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.p}});Object.defineProperty(exports,"AgentSyncConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.k}});Object.defineProperty(exports,"AgentSyncManager",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs._a}});Object.defineProperty(exports,"AuthConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.j}});Object.defineProperty(exports,"BaseChannelPlugin",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.qa}});Object.defineProperty(exports,"ChannelConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.h}});Object.defineProperty(exports,"ChannelPluginLoader",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.oa}});Object.defineProperty(exports,"ChannelPluginRegistry",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.Xa}});Object.defineProperty(exports,"CircuitBreakerConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.o}});Object.defineProperty(exports,"ConnectionPoolConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.m}});Object.defineProperty(exports,"DEBUG_AGENT_FILTER",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.T}});Object.defineProperty(exports,"DEFAULT_AGENT_FILTER",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.S}});Object.defineProperty(exports,"DEFAULT_AGENT_REGISTRY_CONFIG",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.ha}});Object.defineProperty(exports,"DEFAULT_CONNECTION_POOL_CONFIG",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.ja}});Object.defineProperty(exports,"DEFAULT_SYNC_CONFIG",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.ia}});Object.defineProperty(exports,"DEFAULT_TOKEN_AUTH_CONFIG",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.ga}});Object.defineProperty(exports,"DEFAULT_WEBSOCKET_SERVER_CONFIG",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.fa}});Object.defineProperty(exports,"DiscordPlugin",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.sa}});Object.defineProperty(exports,"FeishuChannelConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.c}});Object.defineProperty(exports,"FeishuPlugin",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.ua}});Object.defineProperty(exports,"GatewayClientConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.s}});Object.defineProperty(exports,"GatewayClusterConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.l}});Object.defineProperty(exports,"GatewayConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.t}});Object.defineProperty(exports,"GatewayServer",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.$a}});Object.defineProperty(exports,"GatewayServerConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.r}});Object.defineProperty(exports,"GatewaySessionManager",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.na}});Object.defineProperty(exports,"HTTPSConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.i}});Object.defineProperty(exports,"MessageQueueConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.n}});Object.defineProperty(exports,"MessageRouter",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.ka}});Object.defineProperty(exports,"MessageStore",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.la}});Object.defineProperty(exports,"NostrChannelConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.g}});Object.defineProperty(exports,"NostrPlugin",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.Va}});Object.defineProperty(exports,"SdkEventBridge",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.R}});Object.defineProperty(exports,"SdkEventBus",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.Q}});Object.defineProperty(exports,"SdkEventType",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.P}});Object.defineProperty(exports,"SdkMessageCollector",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.U}});Object.defineProperty(exports,"SessionConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.q}});Object.defineProperty(exports,"SessionStore",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.ma}});Object.defineProperty(exports,"SignalChannelConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.f}});Object.defineProperty(exports,"SignalPlugin",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.Ua}});Object.defineProperty(exports,"SlackChannelConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.b}});Object.defineProperty(exports,"SlackPlugin",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.ta}});Object.defineProperty(exports,"TelegramChannelConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.a}});Object.defineProperty(exports,"TelegramPlugin",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.ra}});Object.defineProperty(exports,"WEIXIN_PLATFORM",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.wa}});Object.defineProperty(exports,"WeChatChannelConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.d}});Object.defineProperty(exports,"WeChatPlugin",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.va}});Object.defineProperty(exports,"WebChatChannelConfigSchema",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.e}});Object.defineProperty(exports,"WebChatPlugin",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.Ta}});Object.defineProperty(exports,"WeixinPlugin",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.Sa}});Object.defineProperty(exports,"clearConfigCache",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.z}});Object.defineProperty(exports,"convertToGatewayMessage",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.ba}});Object.defineProperty(exports,"createChannelPlugin",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.Wa}});Object.defineProperty(exports,"createDefaultSessionState",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.da}});Object.defineProperty(exports,"createGatewayMessage",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.$}});Object.defineProperty(exports,"createTextMessage",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.aa}});Object.defineProperty(exports,"ensureContact",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.za}});Object.defineProperty(exports,"ensureSession",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.Aa}});Object.defineProperty(exports,"ensureUser",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.Ba}});Object.defineProperty(exports,"generateSessionId",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.ca}});Object.defineProperty(exports,"generateSubscriptionId",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.ea}});Object.defineProperty(exports,"getAgentAdapter",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.W}});Object.defineProperty(exports,"getAgentRegistryConfig",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.G}});Object.defineProperty(exports,"getAuthConfig",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.L}});Object.defineProperty(exports,"getChannelConfig",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.C}});Object.defineProperty(exports,"getCircuitBreakerConfig",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.F}});Object.defineProperty(exports,"getClusterConfig",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.M}});Object.defineProperty(exports,"getConfig",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.x}});Object.defineProperty(exports,"getConfigDirectory",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.A}});Object.defineProperty(exports,"getConnectionPoolConfig",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.D}});Object.defineProperty(exports,"getDefaultAgent",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.N}});Object.defineProperty(exports,"getGatewayClientConfig",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.I}});Object.defineProperty(exports,"getGatewayClientUrl",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.J}});Object.defineProperty(exports,"getHTTPSConfig",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.K}});Object.defineProperty(exports,"getLogLevel",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.O}});Object.defineProperty(exports,"getMessageQueueConfig",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.E}});Object.defineProperty(exports,"getServerConfig",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.B}});Object.defineProperty(exports,"getSessionConfig",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.H}});Object.defineProperty(exports,"getSupportedPlatforms",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.Ya}});Object.defineProperty(exports,"hasAgentAdapter",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.X}});Object.defineProperty(exports,"isConfigLoaded",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.y}});Object.defineProperty(exports,"listWeixinContacts",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.Da}});Object.defineProperty(exports,"loadConfig",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.w}});Object.defineProperty(exports,"parsePartialConfig",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.v}});Object.defineProperty(exports,"removeUser",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.Ca}});Object.defineProperty(exports,"requireAgentAdapter",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.Y}});Object.defineProperty(exports,"setAgentAdapter",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.V}});Object.defineProperty(exports,"validateConfig",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.u}});Object.defineProperty(exports,"weixinSetStateDir",{enumerable:true,get:function(){return chunkCPQSQ7FU_cjs.Ga}});exports.handleWeixinCli=tr;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IGatewayServer, GatewayConfig as GatewayConfig$1, GatewayServerConfig as GatewayServerConfig$1, GatewayMessageReceiveInput, GatewayMessage, GatewayMessagePromptPart, PlatformType, SubAgentConfig, ChannelInfo, AgentPromptPart, AgentAdapter } from '@easbot/types';
|
|
2
2
|
export { AgentAdapter, AgentInfo, ChannelInfo, ChannelListResponse, GatewayMessage, GatewayMessagePromptPart, IGatewayServer, IGlobal, IHookRegistry, IInstance, ISubAgentRunner, MessageContext, MessageMetadata, MessageStorage, MessageType, PlatformType } from '@easbot/types';
|
|
3
3
|
import z, { z as z$1 } from 'zod';
|
|
4
|
-
import { WSContext } from '@easbot/utils';
|
|
4
|
+
import { WSContext, Log } from '@easbot/utils';
|
|
5
5
|
import { Command, EasbotClient } from '@easbot/sdk';
|
|
6
6
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
7
7
|
|
|
@@ -1645,41 +1645,6 @@ declare class AgentSyncManager {
|
|
|
1645
1645
|
removeRemoteNode(nodeId: string): void;
|
|
1646
1646
|
}
|
|
1647
1647
|
|
|
1648
|
-
declare namespace Log {
|
|
1649
|
-
const Level: z.ZodEnum<{
|
|
1650
|
-
DEBUG: "DEBUG";
|
|
1651
|
-
INFO: "INFO";
|
|
1652
|
-
WARN: "WARN";
|
|
1653
|
-
ERROR: "ERROR";
|
|
1654
|
-
}>;
|
|
1655
|
-
type Level = z.infer<typeof Level>;
|
|
1656
|
-
function getLevel(): Level;
|
|
1657
|
-
type Logger = {
|
|
1658
|
-
debug(message?: any, extra?: Record<string, any>): void;
|
|
1659
|
-
info(message?: any, extra?: Record<string, any>): void;
|
|
1660
|
-
error(message?: any, extra?: Record<string, any>): void;
|
|
1661
|
-
warn(message?: any, extra?: Record<string, any>): void;
|
|
1662
|
-
tag(key: string, value: string): Logger;
|
|
1663
|
-
clone(): Logger;
|
|
1664
|
-
time(message: string, extra?: Record<string, any>): {
|
|
1665
|
-
stop(): void;
|
|
1666
|
-
[Symbol.dispose](): void;
|
|
1667
|
-
};
|
|
1668
|
-
};
|
|
1669
|
-
const Default: Logger;
|
|
1670
|
-
interface Options {
|
|
1671
|
-
print: boolean;
|
|
1672
|
-
logDir: string;
|
|
1673
|
-
logFile?: string;
|
|
1674
|
-
dev?: boolean;
|
|
1675
|
-
level?: Level;
|
|
1676
|
-
}
|
|
1677
|
-
function file(): string;
|
|
1678
|
-
function init(options: Options): Promise<void>;
|
|
1679
|
-
function close(): Promise<void>;
|
|
1680
|
-
function create(tags?: Record<string, any>): Logger;
|
|
1681
|
-
}
|
|
1682
|
-
|
|
1683
1648
|
interface LocalCommandResult {
|
|
1684
1649
|
handled: boolean;
|
|
1685
1650
|
reply?: string;
|
|
@@ -3216,12 +3181,4 @@ declare function getAgentAdapter(): AgentAdapter | undefined;
|
|
|
3216
3181
|
declare function hasAgentAdapter(): boolean;
|
|
3217
3182
|
declare function requireAgentAdapter(): AgentAdapter;
|
|
3218
3183
|
|
|
3219
|
-
|
|
3220
|
-
print: boolean;
|
|
3221
|
-
logDir: string;
|
|
3222
|
-
logFile?: string;
|
|
3223
|
-
dev?: boolean;
|
|
3224
|
-
level?: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
|
|
3225
|
-
}): Promise<void>;
|
|
3226
|
-
|
|
3227
|
-
export { type AgentClientFilterConfig, type AgentDeregisterMessage, type AgentHealthStatus, type AgentHeartbeat, type AgentHeartbeatSyncMessage, type AgentListRequestMessage, type AgentListResponseMessage, type AgentMessage, type AgentRegisterMessage, type AgentRegistration, type AgentRegistrationRequest, AgentRegistry, type AgentRegistryConfig, AgentRegistryConfigSchema, type AgentRegistryStats, type AgentSelectionOptions, type AgentSelectionRecord, type AgentSelectionStrategy, type AgentStatusChangeMessage, type AgentSyncConfig, AgentSyncConfigSchema, type AgentSyncInfo, AgentSyncManager, type AuthConfig, AuthConfigSchema, type AuthResult, BaseChannelPlugin, type CancelEvent, type CancelEventHandler, type ChannelConfig, ChannelConfigSchema, type ChannelEvent, type ChannelEventType, type ChannelHealth, type ChannelPlugin, ChannelPluginLoader, ChannelPluginRegistry, type SessionConfig as ChannelSessionConfig, type ChannelStatus, type ChannelStatusType, type ChannelType, type CircuitBreakerConfig, CircuitBreakerConfigSchema, type ClientInterruptMessage, type ClientMessage, type ClientMessageMessage, type ClientMessageType, type ClientPingMessage, type ClientReleaseSubscriptionMessage, type ClientSubscribeMessage, type ClientSubscription, type ClientUnsubscribeMessage, type ConflictResolutionStrategy, type ConnectionCloser, type ConnectionFactory, type ConnectionHealthChecker, type ConnectionPoolConfig, ConnectionPoolConfigSchema, type ConnectionPoolEvent, type ConnectionPoolEventCallback, type ConnectionPoolEventType, type ConnectionPoolStats, type ConnectionState, type CreateSessionRequest, type CreateSessionResponse, DEBUG_AGENT_FILTER, DEFAULT_AGENT_FILTER, DEFAULT_AGENT_REGISTRY_CONFIG, DEFAULT_CONNECTION_POOL_CONFIG, DEFAULT_SYNC_CONFIG, DEFAULT_TOKEN_AUTH_CONFIG, DEFAULT_WEBSOCKET_SERVER_CONFIG, type DiscordBotConfig, DiscordPlugin, type EnsureUserOptions, type FeishuBotConfig, type FeishuChannelConfig, FeishuChannelConfigSchema, FeishuPlugin, Gateway, type GatewayClientConfig, GatewayClientConfigSchema, type GatewayClusterConfig, GatewayClusterConfigSchema, type GatewayConfig, GatewayConfigSchema, type GatewayNodeConfig, type GatewayNodeInfo, GatewayServer, type GatewayServerConfig, GatewayServerConfigSchema, type GatewaySession, GatewaySessionManager, type HTTPSConfig, HTTPSConfigSchema, type HealthCheckResponse, type IAuthProvider, type MessageHandler, type MessagePriority, type MessageQueueConfig, MessageQueueConfigSchema, type MessageRecord, MessageRouter, type MessageStatus, MessageStore, type MessageStoreConfig, type NostrBotConfig, type NostrChannelConfig, NostrChannelConfigSchema, NostrPlugin, type OAuth2AuthConfig, type PartData, type PluginLoaderConfig, type PooledConnection, type PushEventType, type RouteResult, type RoutingConfig, SdkEventBridge, SdkEventBus, SdkEventType, SdkMessageCollector, type SdkSessionStatusProps, type SendMessageRequest, type SendMessageResponse, type SerializableSession, type ServerConnectedMessage, type ServerErrorMessage, type ServerEventMessage, type ServerInterruptedMessage, type ServerMessage, type ServerMessageType, type ServerPongMessage, type ServerResponseMessage, type ServerStatusResponse, type ServerSubscribedMessage, type ServerSubscriptionReleasedMessage, type ServerUnsubscribedMessage, type SessionChannelInfo, type SessionConfig$1 as SessionConfig, SessionConfigSchema, type SessionContext, type SessionEvent, type SessionEventPayload, type SessionEventType$1 as SessionEventType, type SessionFilter, type SessionManagerConfig, type SessionResetPolicy, type SessionState, type SessionStatusType, SessionStore, type SessionStoreConfig, type SignalBotConfig, type SignalChannelConfig, SignalChannelConfigSchema, SignalPlugin, type SlackBotConfig, type SlackChannelConfig, SlackChannelConfigSchema, SlackPlugin, type Subscriber, type SubscriberConnection, type SubscriberType, type Subscription, type SubscriptionOptions, type SubscriptionsResponse, type SyncConfig, type SyncMessage, type SyncMode, type SyncState, type SyncStats, type TelegramBotConfig, type TelegramChannelConfig, TelegramChannelConfigSchema, TelegramPlugin, type TokenAuthConfig, type TokenAuthItem, type TokenConfig, WEIXIN_PLATFORM, type WeChatBotConfig, type WeChatChannelConfig, WeChatChannelConfigSchema, WeChatPlugin, type WebChatChannelConfig, WebChatChannelConfigSchema, type WebChatConfig, WebChatPlugin, type WebSocketConnectionInfo, type WebSocketConnectionState, type WebSocketMessage, type WebSocketMessageBase, type WeixinBotConfig, WeixinPlugin, type WeixinServerDeps, clearConfigCache, convertToGatewayMessage, createChannelPlugin, createDefaultSessionState, createGatewayMessage, createTextMessage, ensureContact, ensureSession, ensureUser, generateSessionId, generateSubscriptionId, getAgentAdapter, getAgentRegistryConfig, getAuthConfig, getChannelConfig, getCircuitBreakerConfig, getClusterConfig, getConfig, getConfigDirectory, getConnectionPoolConfig, getDefaultAgent, getGatewayClientConfig, getGatewayClientUrl, getHTTPSConfig, getLogLevel, getMessageQueueConfig, getServerConfig, getSessionConfig, getSupportedPlatforms, handleWeixinCli, hasAgentAdapter, initLog, isConfigLoaded, listWeixinContacts, loadConfig, parsePartialConfig, removeUser, requireAgentAdapter, setAgentAdapter, validateConfig, setStateDir as weixinSetStateDir };
|
|
3184
|
+
export { type AgentClientFilterConfig, type AgentDeregisterMessage, type AgentHealthStatus, type AgentHeartbeat, type AgentHeartbeatSyncMessage, type AgentListRequestMessage, type AgentListResponseMessage, type AgentMessage, type AgentRegisterMessage, type AgentRegistration, type AgentRegistrationRequest, AgentRegistry, type AgentRegistryConfig, AgentRegistryConfigSchema, type AgentRegistryStats, type AgentSelectionOptions, type AgentSelectionRecord, type AgentSelectionStrategy, type AgentStatusChangeMessage, type AgentSyncConfig, AgentSyncConfigSchema, type AgentSyncInfo, AgentSyncManager, type AuthConfig, AuthConfigSchema, type AuthResult, BaseChannelPlugin, type CancelEvent, type CancelEventHandler, type ChannelConfig, ChannelConfigSchema, type ChannelEvent, type ChannelEventType, type ChannelHealth, type ChannelPlugin, ChannelPluginLoader, ChannelPluginRegistry, type SessionConfig as ChannelSessionConfig, type ChannelStatus, type ChannelStatusType, type ChannelType, type CircuitBreakerConfig, CircuitBreakerConfigSchema, type ClientInterruptMessage, type ClientMessage, type ClientMessageMessage, type ClientMessageType, type ClientPingMessage, type ClientReleaseSubscriptionMessage, type ClientSubscribeMessage, type ClientSubscription, type ClientUnsubscribeMessage, type ConflictResolutionStrategy, type ConnectionCloser, type ConnectionFactory, type ConnectionHealthChecker, type ConnectionPoolConfig, ConnectionPoolConfigSchema, type ConnectionPoolEvent, type ConnectionPoolEventCallback, type ConnectionPoolEventType, type ConnectionPoolStats, type ConnectionState, type CreateSessionRequest, type CreateSessionResponse, DEBUG_AGENT_FILTER, DEFAULT_AGENT_FILTER, DEFAULT_AGENT_REGISTRY_CONFIG, DEFAULT_CONNECTION_POOL_CONFIG, DEFAULT_SYNC_CONFIG, DEFAULT_TOKEN_AUTH_CONFIG, DEFAULT_WEBSOCKET_SERVER_CONFIG, type DiscordBotConfig, DiscordPlugin, type EnsureUserOptions, type FeishuBotConfig, type FeishuChannelConfig, FeishuChannelConfigSchema, FeishuPlugin, Gateway, type GatewayClientConfig, GatewayClientConfigSchema, type GatewayClusterConfig, GatewayClusterConfigSchema, type GatewayConfig, GatewayConfigSchema, type GatewayNodeConfig, type GatewayNodeInfo, GatewayServer, type GatewayServerConfig, GatewayServerConfigSchema, type GatewaySession, GatewaySessionManager, type HTTPSConfig, HTTPSConfigSchema, type HealthCheckResponse, type IAuthProvider, type MessageHandler, type MessagePriority, type MessageQueueConfig, MessageQueueConfigSchema, type MessageRecord, MessageRouter, type MessageStatus, MessageStore, type MessageStoreConfig, type NostrBotConfig, type NostrChannelConfig, NostrChannelConfigSchema, NostrPlugin, type OAuth2AuthConfig, type PartData, type PluginLoaderConfig, type PooledConnection, type PushEventType, type RouteResult, type RoutingConfig, SdkEventBridge, SdkEventBus, SdkEventType, SdkMessageCollector, type SdkSessionStatusProps, type SendMessageRequest, type SendMessageResponse, type SerializableSession, type ServerConnectedMessage, type ServerErrorMessage, type ServerEventMessage, type ServerInterruptedMessage, type ServerMessage, type ServerMessageType, type ServerPongMessage, type ServerResponseMessage, type ServerStatusResponse, type ServerSubscribedMessage, type ServerSubscriptionReleasedMessage, type ServerUnsubscribedMessage, type SessionChannelInfo, type SessionConfig$1 as SessionConfig, SessionConfigSchema, type SessionContext, type SessionEvent, type SessionEventPayload, type SessionEventType$1 as SessionEventType, type SessionFilter, type SessionManagerConfig, type SessionResetPolicy, type SessionState, type SessionStatusType, SessionStore, type SessionStoreConfig, type SignalBotConfig, type SignalChannelConfig, SignalChannelConfigSchema, SignalPlugin, type SlackBotConfig, type SlackChannelConfig, SlackChannelConfigSchema, SlackPlugin, type Subscriber, type SubscriberConnection, type SubscriberType, type Subscription, type SubscriptionOptions, type SubscriptionsResponse, type SyncConfig, type SyncMessage, type SyncMode, type SyncState, type SyncStats, type TelegramBotConfig, type TelegramChannelConfig, TelegramChannelConfigSchema, TelegramPlugin, type TokenAuthConfig, type TokenAuthItem, type TokenConfig, WEIXIN_PLATFORM, type WeChatBotConfig, type WeChatChannelConfig, WeChatChannelConfigSchema, WeChatPlugin, type WebChatChannelConfig, WebChatChannelConfigSchema, type WebChatConfig, WebChatPlugin, type WebSocketConnectionInfo, type WebSocketConnectionState, type WebSocketMessage, type WebSocketMessageBase, type WeixinBotConfig, WeixinPlugin, type WeixinServerDeps, clearConfigCache, convertToGatewayMessage, createChannelPlugin, createDefaultSessionState, createGatewayMessage, createTextMessage, ensureContact, ensureSession, ensureUser, generateSessionId, generateSubscriptionId, getAgentAdapter, getAgentRegistryConfig, getAuthConfig, getChannelConfig, getCircuitBreakerConfig, getClusterConfig, getConfig, getConfigDirectory, getConnectionPoolConfig, getDefaultAgent, getGatewayClientConfig, getGatewayClientUrl, getHTTPSConfig, getLogLevel, getMessageQueueConfig, getServerConfig, getSessionConfig, getSupportedPlatforms, handleWeixinCli, hasAgentAdapter, isConfigLoaded, listWeixinContacts, loadConfig, parsePartialConfig, removeUser, requireAgentAdapter, setAgentAdapter, validateConfig, setStateDir as weixinSetStateDir };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IGatewayServer, GatewayConfig as GatewayConfig$1, GatewayServerConfig as GatewayServerConfig$1, GatewayMessageReceiveInput, GatewayMessage, GatewayMessagePromptPart, PlatformType, SubAgentConfig, ChannelInfo, AgentPromptPart, AgentAdapter } from '@easbot/types';
|
|
2
2
|
export { AgentAdapter, AgentInfo, ChannelInfo, ChannelListResponse, GatewayMessage, GatewayMessagePromptPart, IGatewayServer, IGlobal, IHookRegistry, IInstance, ISubAgentRunner, MessageContext, MessageMetadata, MessageStorage, MessageType, PlatformType } from '@easbot/types';
|
|
3
3
|
import z, { z as z$1 } from 'zod';
|
|
4
|
-
import { WSContext } from '@easbot/utils';
|
|
4
|
+
import { WSContext, Log } from '@easbot/utils';
|
|
5
5
|
import { Command, EasbotClient } from '@easbot/sdk';
|
|
6
6
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
7
7
|
|
|
@@ -1645,41 +1645,6 @@ declare class AgentSyncManager {
|
|
|
1645
1645
|
removeRemoteNode(nodeId: string): void;
|
|
1646
1646
|
}
|
|
1647
1647
|
|
|
1648
|
-
declare namespace Log {
|
|
1649
|
-
const Level: z.ZodEnum<{
|
|
1650
|
-
DEBUG: "DEBUG";
|
|
1651
|
-
INFO: "INFO";
|
|
1652
|
-
WARN: "WARN";
|
|
1653
|
-
ERROR: "ERROR";
|
|
1654
|
-
}>;
|
|
1655
|
-
type Level = z.infer<typeof Level>;
|
|
1656
|
-
function getLevel(): Level;
|
|
1657
|
-
type Logger = {
|
|
1658
|
-
debug(message?: any, extra?: Record<string, any>): void;
|
|
1659
|
-
info(message?: any, extra?: Record<string, any>): void;
|
|
1660
|
-
error(message?: any, extra?: Record<string, any>): void;
|
|
1661
|
-
warn(message?: any, extra?: Record<string, any>): void;
|
|
1662
|
-
tag(key: string, value: string): Logger;
|
|
1663
|
-
clone(): Logger;
|
|
1664
|
-
time(message: string, extra?: Record<string, any>): {
|
|
1665
|
-
stop(): void;
|
|
1666
|
-
[Symbol.dispose](): void;
|
|
1667
|
-
};
|
|
1668
|
-
};
|
|
1669
|
-
const Default: Logger;
|
|
1670
|
-
interface Options {
|
|
1671
|
-
print: boolean;
|
|
1672
|
-
logDir: string;
|
|
1673
|
-
logFile?: string;
|
|
1674
|
-
dev?: boolean;
|
|
1675
|
-
level?: Level;
|
|
1676
|
-
}
|
|
1677
|
-
function file(): string;
|
|
1678
|
-
function init(options: Options): Promise<void>;
|
|
1679
|
-
function close(): Promise<void>;
|
|
1680
|
-
function create(tags?: Record<string, any>): Logger;
|
|
1681
|
-
}
|
|
1682
|
-
|
|
1683
1648
|
interface LocalCommandResult {
|
|
1684
1649
|
handled: boolean;
|
|
1685
1650
|
reply?: string;
|
|
@@ -3216,12 +3181,4 @@ declare function getAgentAdapter(): AgentAdapter | undefined;
|
|
|
3216
3181
|
declare function hasAgentAdapter(): boolean;
|
|
3217
3182
|
declare function requireAgentAdapter(): AgentAdapter;
|
|
3218
3183
|
|
|
3219
|
-
|
|
3220
|
-
print: boolean;
|
|
3221
|
-
logDir: string;
|
|
3222
|
-
logFile?: string;
|
|
3223
|
-
dev?: boolean;
|
|
3224
|
-
level?: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
|
|
3225
|
-
}): Promise<void>;
|
|
3226
|
-
|
|
3227
|
-
export { type AgentClientFilterConfig, type AgentDeregisterMessage, type AgentHealthStatus, type AgentHeartbeat, type AgentHeartbeatSyncMessage, type AgentListRequestMessage, type AgentListResponseMessage, type AgentMessage, type AgentRegisterMessage, type AgentRegistration, type AgentRegistrationRequest, AgentRegistry, type AgentRegistryConfig, AgentRegistryConfigSchema, type AgentRegistryStats, type AgentSelectionOptions, type AgentSelectionRecord, type AgentSelectionStrategy, type AgentStatusChangeMessage, type AgentSyncConfig, AgentSyncConfigSchema, type AgentSyncInfo, AgentSyncManager, type AuthConfig, AuthConfigSchema, type AuthResult, BaseChannelPlugin, type CancelEvent, type CancelEventHandler, type ChannelConfig, ChannelConfigSchema, type ChannelEvent, type ChannelEventType, type ChannelHealth, type ChannelPlugin, ChannelPluginLoader, ChannelPluginRegistry, type SessionConfig as ChannelSessionConfig, type ChannelStatus, type ChannelStatusType, type ChannelType, type CircuitBreakerConfig, CircuitBreakerConfigSchema, type ClientInterruptMessage, type ClientMessage, type ClientMessageMessage, type ClientMessageType, type ClientPingMessage, type ClientReleaseSubscriptionMessage, type ClientSubscribeMessage, type ClientSubscription, type ClientUnsubscribeMessage, type ConflictResolutionStrategy, type ConnectionCloser, type ConnectionFactory, type ConnectionHealthChecker, type ConnectionPoolConfig, ConnectionPoolConfigSchema, type ConnectionPoolEvent, type ConnectionPoolEventCallback, type ConnectionPoolEventType, type ConnectionPoolStats, type ConnectionState, type CreateSessionRequest, type CreateSessionResponse, DEBUG_AGENT_FILTER, DEFAULT_AGENT_FILTER, DEFAULT_AGENT_REGISTRY_CONFIG, DEFAULT_CONNECTION_POOL_CONFIG, DEFAULT_SYNC_CONFIG, DEFAULT_TOKEN_AUTH_CONFIG, DEFAULT_WEBSOCKET_SERVER_CONFIG, type DiscordBotConfig, DiscordPlugin, type EnsureUserOptions, type FeishuBotConfig, type FeishuChannelConfig, FeishuChannelConfigSchema, FeishuPlugin, Gateway, type GatewayClientConfig, GatewayClientConfigSchema, type GatewayClusterConfig, GatewayClusterConfigSchema, type GatewayConfig, GatewayConfigSchema, type GatewayNodeConfig, type GatewayNodeInfo, GatewayServer, type GatewayServerConfig, GatewayServerConfigSchema, type GatewaySession, GatewaySessionManager, type HTTPSConfig, HTTPSConfigSchema, type HealthCheckResponse, type IAuthProvider, type MessageHandler, type MessagePriority, type MessageQueueConfig, MessageQueueConfigSchema, type MessageRecord, MessageRouter, type MessageStatus, MessageStore, type MessageStoreConfig, type NostrBotConfig, type NostrChannelConfig, NostrChannelConfigSchema, NostrPlugin, type OAuth2AuthConfig, type PartData, type PluginLoaderConfig, type PooledConnection, type PushEventType, type RouteResult, type RoutingConfig, SdkEventBridge, SdkEventBus, SdkEventType, SdkMessageCollector, type SdkSessionStatusProps, type SendMessageRequest, type SendMessageResponse, type SerializableSession, type ServerConnectedMessage, type ServerErrorMessage, type ServerEventMessage, type ServerInterruptedMessage, type ServerMessage, type ServerMessageType, type ServerPongMessage, type ServerResponseMessage, type ServerStatusResponse, type ServerSubscribedMessage, type ServerSubscriptionReleasedMessage, type ServerUnsubscribedMessage, type SessionChannelInfo, type SessionConfig$1 as SessionConfig, SessionConfigSchema, type SessionContext, type SessionEvent, type SessionEventPayload, type SessionEventType$1 as SessionEventType, type SessionFilter, type SessionManagerConfig, type SessionResetPolicy, type SessionState, type SessionStatusType, SessionStore, type SessionStoreConfig, type SignalBotConfig, type SignalChannelConfig, SignalChannelConfigSchema, SignalPlugin, type SlackBotConfig, type SlackChannelConfig, SlackChannelConfigSchema, SlackPlugin, type Subscriber, type SubscriberConnection, type SubscriberType, type Subscription, type SubscriptionOptions, type SubscriptionsResponse, type SyncConfig, type SyncMessage, type SyncMode, type SyncState, type SyncStats, type TelegramBotConfig, type TelegramChannelConfig, TelegramChannelConfigSchema, TelegramPlugin, type TokenAuthConfig, type TokenAuthItem, type TokenConfig, WEIXIN_PLATFORM, type WeChatBotConfig, type WeChatChannelConfig, WeChatChannelConfigSchema, WeChatPlugin, type WebChatChannelConfig, WebChatChannelConfigSchema, type WebChatConfig, WebChatPlugin, type WebSocketConnectionInfo, type WebSocketConnectionState, type WebSocketMessage, type WebSocketMessageBase, type WeixinBotConfig, WeixinPlugin, type WeixinServerDeps, clearConfigCache, convertToGatewayMessage, createChannelPlugin, createDefaultSessionState, createGatewayMessage, createTextMessage, ensureContact, ensureSession, ensureUser, generateSessionId, generateSubscriptionId, getAgentAdapter, getAgentRegistryConfig, getAuthConfig, getChannelConfig, getCircuitBreakerConfig, getClusterConfig, getConfig, getConfigDirectory, getConnectionPoolConfig, getDefaultAgent, getGatewayClientConfig, getGatewayClientUrl, getHTTPSConfig, getLogLevel, getMessageQueueConfig, getServerConfig, getSessionConfig, getSupportedPlatforms, handleWeixinCli, hasAgentAdapter, initLog, isConfigLoaded, listWeixinContacts, loadConfig, parsePartialConfig, removeUser, requireAgentAdapter, setAgentAdapter, validateConfig, setStateDir as weixinSetStateDir };
|
|
3184
|
+
export { type AgentClientFilterConfig, type AgentDeregisterMessage, type AgentHealthStatus, type AgentHeartbeat, type AgentHeartbeatSyncMessage, type AgentListRequestMessage, type AgentListResponseMessage, type AgentMessage, type AgentRegisterMessage, type AgentRegistration, type AgentRegistrationRequest, AgentRegistry, type AgentRegistryConfig, AgentRegistryConfigSchema, type AgentRegistryStats, type AgentSelectionOptions, type AgentSelectionRecord, type AgentSelectionStrategy, type AgentStatusChangeMessage, type AgentSyncConfig, AgentSyncConfigSchema, type AgentSyncInfo, AgentSyncManager, type AuthConfig, AuthConfigSchema, type AuthResult, BaseChannelPlugin, type CancelEvent, type CancelEventHandler, type ChannelConfig, ChannelConfigSchema, type ChannelEvent, type ChannelEventType, type ChannelHealth, type ChannelPlugin, ChannelPluginLoader, ChannelPluginRegistry, type SessionConfig as ChannelSessionConfig, type ChannelStatus, type ChannelStatusType, type ChannelType, type CircuitBreakerConfig, CircuitBreakerConfigSchema, type ClientInterruptMessage, type ClientMessage, type ClientMessageMessage, type ClientMessageType, type ClientPingMessage, type ClientReleaseSubscriptionMessage, type ClientSubscribeMessage, type ClientSubscription, type ClientUnsubscribeMessage, type ConflictResolutionStrategy, type ConnectionCloser, type ConnectionFactory, type ConnectionHealthChecker, type ConnectionPoolConfig, ConnectionPoolConfigSchema, type ConnectionPoolEvent, type ConnectionPoolEventCallback, type ConnectionPoolEventType, type ConnectionPoolStats, type ConnectionState, type CreateSessionRequest, type CreateSessionResponse, DEBUG_AGENT_FILTER, DEFAULT_AGENT_FILTER, DEFAULT_AGENT_REGISTRY_CONFIG, DEFAULT_CONNECTION_POOL_CONFIG, DEFAULT_SYNC_CONFIG, DEFAULT_TOKEN_AUTH_CONFIG, DEFAULT_WEBSOCKET_SERVER_CONFIG, type DiscordBotConfig, DiscordPlugin, type EnsureUserOptions, type FeishuBotConfig, type FeishuChannelConfig, FeishuChannelConfigSchema, FeishuPlugin, Gateway, type GatewayClientConfig, GatewayClientConfigSchema, type GatewayClusterConfig, GatewayClusterConfigSchema, type GatewayConfig, GatewayConfigSchema, type GatewayNodeConfig, type GatewayNodeInfo, GatewayServer, type GatewayServerConfig, GatewayServerConfigSchema, type GatewaySession, GatewaySessionManager, type HTTPSConfig, HTTPSConfigSchema, type HealthCheckResponse, type IAuthProvider, type MessageHandler, type MessagePriority, type MessageQueueConfig, MessageQueueConfigSchema, type MessageRecord, MessageRouter, type MessageStatus, MessageStore, type MessageStoreConfig, type NostrBotConfig, type NostrChannelConfig, NostrChannelConfigSchema, NostrPlugin, type OAuth2AuthConfig, type PartData, type PluginLoaderConfig, type PooledConnection, type PushEventType, type RouteResult, type RoutingConfig, SdkEventBridge, SdkEventBus, SdkEventType, SdkMessageCollector, type SdkSessionStatusProps, type SendMessageRequest, type SendMessageResponse, type SerializableSession, type ServerConnectedMessage, type ServerErrorMessage, type ServerEventMessage, type ServerInterruptedMessage, type ServerMessage, type ServerMessageType, type ServerPongMessage, type ServerResponseMessage, type ServerStatusResponse, type ServerSubscribedMessage, type ServerSubscriptionReleasedMessage, type ServerUnsubscribedMessage, type SessionChannelInfo, type SessionConfig$1 as SessionConfig, SessionConfigSchema, type SessionContext, type SessionEvent, type SessionEventPayload, type SessionEventType$1 as SessionEventType, type SessionFilter, type SessionManagerConfig, type SessionResetPolicy, type SessionState, type SessionStatusType, SessionStore, type SessionStoreConfig, type SignalBotConfig, type SignalChannelConfig, SignalChannelConfigSchema, SignalPlugin, type SlackBotConfig, type SlackChannelConfig, SlackChannelConfigSchema, SlackPlugin, type Subscriber, type SubscriberConnection, type SubscriberType, type Subscription, type SubscriptionOptions, type SubscriptionsResponse, type SyncConfig, type SyncMessage, type SyncMode, type SyncState, type SyncStats, type TelegramBotConfig, type TelegramChannelConfig, TelegramChannelConfigSchema, TelegramPlugin, type TokenAuthConfig, type TokenAuthItem, type TokenConfig, WEIXIN_PLATFORM, type WeChatBotConfig, type WeChatChannelConfig, WeChatChannelConfigSchema, WeChatPlugin, type WebChatChannelConfig, WebChatChannelConfigSchema, type WebChatConfig, WebChatPlugin, type WebSocketConnectionInfo, type WebSocketConnectionState, type WebSocketMessage, type WebSocketMessageBase, type WeixinBotConfig, WeixinPlugin, type WeixinServerDeps, clearConfigCache, convertToGatewayMessage, createChannelPlugin, createDefaultSessionState, createGatewayMessage, createTextMessage, ensureContact, ensureSession, ensureUser, generateSessionId, generateSubscriptionId, getAgentAdapter, getAgentRegistryConfig, getAuthConfig, getChannelConfig, getCircuitBreakerConfig, getClusterConfig, getConfig, getConfigDirectory, getConnectionPoolConfig, getDefaultAgent, getGatewayClientConfig, getGatewayClientUrl, getHTTPSConfig, getLogLevel, getMessageQueueConfig, getServerConfig, getSessionConfig, getSupportedPlatforms, handleWeixinCli, hasAgentAdapter, isConfigLoaded, listWeixinContacts, loadConfig, parsePartialConfig, removeUser, requireAgentAdapter, setAgentAdapter, validateConfig, setStateDir as weixinSetStateDir };
|
package/dist/index.mjs
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import {b,c}from'./chunks/chunk-NXFFFRVB.mjs';import {Z,w,_,Ca,Ba,xa,ya,Ha,Da,Na,Ja,Ia,Ea,Qa,Oa,Ra,Fa,Ka,La,Ma,Pa}from'./chunks/chunk-
|
|
2
|
-
`);}async function
|
|
1
|
+
import {b,c}from'./chunks/chunk-NXFFFRVB.mjs';import {Z,w,_,Ca,Ba,xa,ya,Ha,Da,Na,Ja,Ia,Ea,Qa,Oa,Ra,Fa,Ka,La,Ma,Pa}from'./chunks/chunk-3EE2AOK7.mjs';export{Za as AgentRegistry,p as AgentRegistryConfigSchema,k as AgentSyncConfigSchema,_a as AgentSyncManager,j as AuthConfigSchema,qa as BaseChannelPlugin,h as ChannelConfigSchema,oa as ChannelPluginLoader,Xa as ChannelPluginRegistry,o as CircuitBreakerConfigSchema,m as ConnectionPoolConfigSchema,T as DEBUG_AGENT_FILTER,S as DEFAULT_AGENT_FILTER,ha as DEFAULT_AGENT_REGISTRY_CONFIG,ja as DEFAULT_CONNECTION_POOL_CONFIG,ia as DEFAULT_SYNC_CONFIG,ga as DEFAULT_TOKEN_AUTH_CONFIG,fa as DEFAULT_WEBSOCKET_SERVER_CONFIG,sa as DiscordPlugin,c as FeishuChannelConfigSchema,ua as FeishuPlugin,s as GatewayClientConfigSchema,l as GatewayClusterConfigSchema,t as GatewayConfigSchema,$a as GatewayServer,r as GatewayServerConfigSchema,na as GatewaySessionManager,i as HTTPSConfigSchema,n as MessageQueueConfigSchema,ka as MessageRouter,la as MessageStore,g as NostrChannelConfigSchema,Va as NostrPlugin,R as SdkEventBridge,Q as SdkEventBus,P as SdkEventType,U as SdkMessageCollector,q as SessionConfigSchema,ma as SessionStore,f as SignalChannelConfigSchema,Ua as SignalPlugin,b as SlackChannelConfigSchema,ta as SlackPlugin,a as TelegramChannelConfigSchema,ra as TelegramPlugin,wa as WEIXIN_PLATFORM,d as WeChatChannelConfigSchema,va as WeChatPlugin,e as WebChatChannelConfigSchema,Ta as WebChatPlugin,Sa as WeixinPlugin,z as clearConfigCache,ba as convertToGatewayMessage,Wa as createChannelPlugin,da as createDefaultSessionState,$ as createGatewayMessage,aa as createTextMessage,za as ensureContact,Aa as ensureSession,Ba as ensureUser,ca as generateSessionId,ea as generateSubscriptionId,W as getAgentAdapter,G as getAgentRegistryConfig,L as getAuthConfig,C as getChannelConfig,F as getCircuitBreakerConfig,M as getClusterConfig,x as getConfig,A as getConfigDirectory,D as getConnectionPoolConfig,N as getDefaultAgent,I as getGatewayClientConfig,J as getGatewayClientUrl,K as getHTTPSConfig,O as getLogLevel,E as getMessageQueueConfig,B as getServerConfig,H as getSessionConfig,Ya as getSupportedPlatforms,X as hasAgentAdapter,y as isConfigLoaded,Da as listWeixinContacts,w as loadConfig,v as parsePartialConfig,Ca as removeUser,Y as requireAgentAdapter,V as setAgentAdapter,u as validateConfig,Ga as weixinSetStateDir}from'./chunks/chunk-3EE2AOK7.mjs';import {a}from'./chunks/chunk-HQBRVVXS.mjs';import {Log,Fetch,formatLocalISO}from'@easbot/utils';import {toString}from'qrcode';import {existsSync}from'fs';import {Server}from'@modelcontextprotocol/sdk/server/index.js';import {StdioServerTransport}from'@modelcontextprotocol/sdk/server/stdio.js';import {ListToolsRequestSchema,CallToolRequestSchema}from'@modelcontextprotocol/sdk/types.js';var g=Log.create({service:"gateway"}),P=class t extends Error{constructor(e,n,o){super(e);a(this,"type");a(this,"stage");a(this,"cause");this.type="GatewayInitializationError",this.stage=n,this.cause=o,Error.captureStackTrace&&Error.captureStackTrace(this,t);}};function se(t){let r=["ECONNRESET","EPIPE","ETIMEDOUT","ECONNREFUSED","ENOTFOUND","EHOSTUNREACH","ENETUNREACH"],e=t.code;return r.includes(e??"")}function Wt(){process.on("unhandledRejection",t=>{let r=t instanceof Error?t:new Error(String(t));se(r)||g.error("unhandled promise rejection",{error:r.message,stack:r.stack});}),process.on("uncaughtException",t=>{se(t)||(g.error("uncaught exception",{error:t.message,stack:t.stack}),process.exit(1));});}var V;(nr=>{let t={initialized:false,initPromise:null,directory:".easbot",config:null},r,e={server:null,config:null,initialized:false,status:"stopped"};async function n(a={}){if(t.initialized)return;if(t.initPromise)return t.initPromise;let l={directory:a.directory??".easbot",printLogs:a.printLogs??false,logLevel:a.logLevel??"INFO"};return t.directory=l.directory,t.initPromise=(async()=>{Z();try{Wt();}catch(c){throw new P("Failed to install unhandled exception handlers","server",c instanceof Error?c:void 0)}Fetch.hasProxyConfigured()&&(Fetch.enableProxy({connectTimeout:1e4,keepAliveTimeout:3e4}),g.info("global proxy enabled",{proxyUrl:Fetch.getProxyUrl()}));try{t.config=await w(l.directory);}catch(c){throw new P("Failed to load gateway configuration","config",c instanceof Error?c:void 0)}t.initialized=true,g.info("gateway runtime initialized",{directory:l.directory,logLevel:l.logLevel});})(),t.initPromise}nr.init=n;function o(){return t.initialized}nr.isInitialized=o;function u(){return r||(r=async()=>{if(!t.initialized)throw new P("Gateway not initialized. Call init() first.","server");let a=_(),l=await w(a.directory);return l.server?.enabled?(e={server:null,config:l,initialized:true,status:"stopped"},g.info("gateway initialized",{port:l.server?.port,hostname:l.server?.hostname}),e):(g.debug("gateway server disabled or not configured"),{server:null,config:l,initialized:true,status:"stopped"})}),r}function d(){return u()()}nr.state=d;async function y(){return (await d()).server}nr.get=y;async function i(){return (await d()).config?.server?.enabled??false}nr.isEnabled=i;async function f(){return (await d()).config}nr.config=f;function p(){return e.status}nr.getStatus=p;async function s(a){g.debug("Gateway.start: called"),t.initialized||await n();let l=await d();if(!(l.config?.server?.enabled??true))throw g.warn("gateway server is disabled"),new Error("Gateway server is disabled");if(e.status==="running"){g.info("gateway server is already running");return}if(e.status==="starting"){g.info("gateway server is starting");return}e.status="starting";try{let c={...l.config?.server,...a};g.debug("gateway start: creating server with config",{port:c.port,hostname:c.hostname,path:c.path,https:c.https?.enabled});let T=await le(c);e.server=T,e.status="running",e.error=void 0,g.info("gateway server started",{port:c.port,hostname:c.hostname});}catch(c){throw e.status="error",e.error=c instanceof Error?c.message:String(c),g.error("failed to start gateway server",{error:e.error}),c}}nr.start=s;async function m(){if(e.status==="stopped"){g.info("gateway server is already stopped");return}if(e.status==="stopping"){g.info("gateway server is stopping");return}e.status="stopping";try{e.server&&await e.server.stop(),e.server=null,e.status="stopped",e.error=void 0,await Log.close(),g.info("gateway server stopped");}catch(a){throw e.status="error",e.error=a instanceof Error?a.message:String(a),g.error("failed to stop gateway server",{error:e.error}),a}}nr.stop=m;async function C(a){g.info("restarting gateway server"),(e.status==="running"||e.status==="starting")&&await m(),await s(a);}nr.restart=C;async function J(){let a=_(),l=await w(a.directory);return e.config=l,t.config=l,g.info("gateway config reloaded"),l}nr.reloadConfig=J;async function le(a,l){g.debug("createGatewayServer: starting");let{GatewayServer:L}=await import('./chunks/server-XGZGHXC5.mjs'),c=new L(a),T=l?.startupTimeout??3e4;if(await(async()=>{let S=new Promise((x,de)=>{setTimeout(()=>{de(new Error(`Gateway server startup timeout after ${T}ms`));},T);});try{await Promise.race([c.start(),S]);}catch(x){g.error("gateway server start failed, attempting cleanup",{error:x instanceof Error?x.message:String(x)});try{await c.stop();}catch{}throw x}})(),l?.onStarted)try{await l.onStarted(c);}catch(S){g.warn("server started but onStarted callback failed",{error:S instanceof Error?S.message:String(S)});}return g.info("gateway server created and started",{port:a.port,hostname:a.hostname}),c}nr.createGatewayServer=le;})(V||(V={}));async function Ot(t){let r=await toString(t,{type:"terminal",errorCorrectionLevel:"L",small:true});process.stderr.write(`${r}
|
|
2
|
+
`);}async function G(t){let r=await fetch(`${t}/ilink/bot/get_bot_qrcode?bot_type=3`);if(!r.ok)throw new Error(`Failed to get QR code: HTTP ${r.status}`);let e=await r.json();if(!e.qrcode)throw new Error("No qrcode in response");let n=e.qrcode_img_content||"";return n&&await Ot(n),{qrcodeUrl:n,qrcodeId:e.qrcode,message:"Scan the QR code with WeChat to connect."}}async function K(t){let{qrcodeId:r,apiBaseUrl:e,timeoutMs:n=48e4,maxRetries:o=3}=t,u=Date.now()+n,d=r,y=0;for(;Date.now()<u;){try{let i=new AbortController,f=setTimeout(()=>i.abort(),6e4),p=await fetch(`${e}/ilink/bot/get_qrcode_status?qrcode=${encodeURIComponent(d)}`,{headers:{"iLink-App-ClientVersion":"1"},signal:i.signal});if(clearTimeout(f),!p.ok)throw new Error(`HTTP ${p.status}`);let s=await p.json();switch(s.status){case "confirmed":return {connected:!0,token:s.bot_token,accountId:s.ilink_bot_id,baseUrl:s.baseurl,userId:s.ilink_user_id,message:"Connected to WeChat successfully!"};case "scaned":process.stderr.write(`QR code scanned, waiting for confirmation...
|
|
3
3
|
`);break;case "expired":{if(y+=1,y>=o)return {connected:!1,message:"QR code expired after maximum retries."};process.stderr.write(`QR code expired, refreshing...
|
|
4
|
-
`),d=(await
|
|
5
|
-
`);break;default:break}}catch(i){if(i instanceof Error&&i.name==="AbortError")continue;throw i}await new Promise(i=>setTimeout(i,1e3));}return {connected:false,message:"Login timed out."}}function Vt(
|
|
6
|
-
`)}function Kt(
|
|
7
|
-
`);}}),await n.connect(o);let u=
|
|
8
|
-
`),clearInterval(p),i();}},5e3);r.logForDebugging("[Weixin MCP] Starting poll loop"),await Ra({baseUrl:u,cdnBaseUrl:Fa,token:
|
|
4
|
+
`),d=(await G(e)).qrcodeId;break}case "wait":process.stderr.write(`QR code waiting, please wait...
|
|
5
|
+
`);break;default:break}}catch(i){if(i instanceof Error&&i.name==="AbortError")continue;throw i}await new Promise(i=>setTimeout(i,1e3));}return {connected:false,message:"Login timed out."}}function Vt(t){return ["Claude Code needs your approval.","",`Tool: ${t.tool_name}`,`Reason: ${t.description}`,`Input: ${t.input_preview}`,"",`Reply with: yes ${t.request_id}`,`Or deny with: no ${t.request_id}`].join(`
|
|
6
|
+
`)}function Kt(t){let r=new Server({name:"weixin",version:t},{capabilities:{experimental:{"claude/channel":{},"claude/channel/permission":{}},tools:{}},instructions:'Messages from WeChat arrive as <channel source="plugin:weixin:weixin" chat_id="..." sender_id="...">. Reply using the reply tool with the chat_id from the channel tag. Use absolute paths for file attachments.'});return r.setRequestHandler(ListToolsRequestSchema,async()=>({tools:[{name:"reply",description:"Reply to a WeChat message. Pass the chat_id from the channel tag.",inputSchema:{type:"object",properties:{chat_id:{type:"string",description:"The chat_id from the channel notification"},text:{type:"string",description:"The reply text"},files:{type:"array",items:{type:"string"},description:"Optional absolute file paths to attach"}},required:["chat_id","text"]}},{name:"send_typing",description:"Send a typing indicator to a WeChat user.",inputSchema:{type:"object",properties:{chat_id:{type:"string",description:"The chat_id (user ID)"}},required:["chat_id"]}}]})),r.setRequestHandler(CallToolRequestSchema,async e=>{let{name:n,arguments:o}=e.params,u=Ha();if(!u)return {content:[{type:"text",text:"WeChat not connected. Run `easbot weixin login` first."}],isError:true};let d=u.baseUrl||Ea,y=Fa;switch(n){case "reply":{let i=typeof o?.chat_id=="string"?o.chat_id:"",f=typeof o?.text=="string"?o.text:"",p=Array.isArray(o?.files)?o.files.filter(m=>typeof m=="string"):void 0;if(!i||!f)return {content:[{type:"text",text:"Missing chat_id or text parameter."}],isError:true};let s=Qa(i)||"";try{if(p&&p.length>0){for(let[m,C]of p.entries()){if(!existsSync(C))return {content:[{type:"text",text:`File not found: ${C}`}],isError:!0};await Pa({filePath:C,to:i,text:m===0?f:"",baseUrl:d,token:u.token,contextToken:s,cdnBaseUrl:y});}return {content:[{type:"text",text:"Message sent with attachments."}]}}return await Oa({to:i,text:f,baseUrl:d,token:u.token,contextToken:s}),{content:[{type:"text",text:"Message sent."}]}}catch(m){return {content:[{type:"text",text:`Failed to send: ${m}`}],isError:true}}}case "send_typing":{let i=typeof o?.chat_id=="string"?o.chat_id:"";if(!i)return {content:[{type:"text",text:"Missing chat_id parameter."}],isError:true};try{let f=Qa(i),p=await Ka(d,u.token,i,f);return p.typing_ticket&&await La(d,u.token,{ilink_user_id:i,typing_ticket:p.typing_ticket,status:Ma.TYPING}),{content:[{type:"text",text:"Typing indicator sent."}]}}catch(f){return {content:[{type:"text",text:`Failed to send typing: ${f}`}],isError:true}}}default:return {content:[{type:"text",text:`Unknown tool: ${n}`}],isError:true}}}),r}async function ae(t,r){r.enableConfigs(),r.initializeAnalyticsSink();let e=Ha();e||(process.stderr.write("[weixin] No account configured. Run `easbot weixin login` to connect your WeChat account.\n"),await Promise.all([r.shutdown1PEventLogging(),r.shutdownDatadog()]),process.exit(1));let n=Kt(t),o=new StdioServerTransport;r.registerPermissionHandler(n,async s=>{let m=s.channel_context?.chat_id,C=m?{chatId:m,contextToken:Qa(m)}:b();if(!C){r.logForDebugging(`[Weixin MCP] No active chat available for permission request ${s.request_id}`);return}try{c(s,C.chatId,C.contextToken),await Oa({to:C.chatId,text:Vt(s),baseUrl:u,token:e.token,contextToken:C.contextToken||""});}catch(J){process.stderr.write(`[weixin] Failed to relay permission request ${s.request_id}: ${J}
|
|
7
|
+
`);}}),await n.connect(o);let u=e.baseUrl||Ea,d=new AbortController,y=false,i=async()=>{y||(y=true,d.signal.aborted||d.abort(),await Promise.all([r.shutdown1PEventLogging(),r.shutdownDatadog()]),process.exit(0));};process.stdin.on("end",()=>{i();}),process.stdin.on("error",()=>{i();}),process.on("SIGINT",()=>{i();}),process.on("SIGTERM",()=>{i();}),process.on("SIGHUP",()=>{i();});let f=process.ppid,p=setInterval(()=>{try{process.kill(f,0);}catch{process.stderr.write(`[weixin] Parent process exited, shutting down...
|
|
8
|
+
`),clearInterval(p),i();}},5e3);r.logForDebugging("[Weixin MCP] Starting poll loop"),await Ra({baseUrl:u,cdnBaseUrl:Fa,token:e.token,onMessage:async s=>{await n.notification({method:"notifications/claude/channel",params:{content:s.text,meta:{chat_id:s.fromUserId,sender_id:s.fromUserId,message_id:s.messageId,...s.attachmentPath&&{attachment_path:s.attachmentPath},...s.attachmentType&&{attachment_type:s.attachmentType}}}});},onPermissionResponse:async s=>{await n.notification({method:"notifications/claude/channel/permission",params:{request_id:s.requestId,behavior:s.behavior}});},abortSignal:d.signal}),clearInterval(p),await i();}function ce(){process.stdout.write(["Usage:"," easbot weixin serve"," easbot weixin login"," easbot weixin login clear"," easbot weixin access pair <code>","","Current user (read from account.json):"," easbot weixin user",' easbot weixin ensure-user [--display-name "<name>"]'," easbot weixin remove-user"].join(`
|
|
9
9
|
`)+`
|
|
10
|
-
`);}async function Yt(
|
|
10
|
+
`);}async function Yt(t=false){if(t){Ja(),process.stdout.write(`WeChat account cleared.
|
|
11
11
|
`);return}let r=Ha();if(r){process.stdout.write(["Already connected:",` User ID: ${r.userId||"unknown"}`,` Connected since: ${formatLocalISO(new Date(r.savedAt))}`,"","Run `easbot weixin login clear` to disconnect."].join(`
|
|
12
12
|
`)+`
|
|
13
13
|
`);return}process.stdout.write(`Starting WeChat QR login...
|
|
14
14
|
|
|
15
|
-
`);let
|
|
15
|
+
`);let e=await G(Ea);process.stdout.write(`
|
|
16
16
|
Scan the QR code above with WeChat, or open this URL:
|
|
17
|
-
${
|
|
17
|
+
${e.qrcodeUrl||""}
|
|
18
18
|
|
|
19
|
-
`);let n=await
|
|
19
|
+
`);let n=await K({qrcodeId:e.qrcodeId,apiBaseUrl:Ea});(!n.connected||!n.token)&&(process.stderr.write(`Login failed: ${n.message}
|
|
20
20
|
`),process.exit(1)),Ia({token:n.token,baseUrl:n.baseUrl||Ea,userId:n.userId,savedAt:new Date().toISOString()}),process.stdout.write(["Connected successfully!",` User ID: ${n.userId||"unknown"}`,` Base URL: ${n.baseUrl||Ea}`].join(`
|
|
21
21
|
`)+`
|
|
22
|
-
`);}function Jt(
|
|
22
|
+
`);}function Jt(t){(t[0]!=="pair"||!t[1])&&(ce(),process.exit(1));let r=Na(t[1]);r||(process.stderr.write(`Invalid or expired pairing code.
|
|
23
23
|
`),process.exit(1)),process.stdout.write(`Paired successfully: ${r}
|
|
24
|
-
`);}function Xt(
|
|
24
|
+
`);}function Xt(t,r){let e={userId:r,channelId:"weixin-main"};for(let n=0;n<t.length;n++){let o=t[n];if(o==="--display-name"||o==="-d"){let u=t[++n];if(!u)return "--display-name requires a value";e.displayName=u;}else return `Unknown argument: ${o}`}return e}function ge(){let t=Ha();return t?.userId||(process.stderr.write("No weixin account logged in. Run `easbot weixin login` first.\n"),process.exit(1)),t.userId}async function Zt(){try{let t=Ha();if(!t){process.stdout.write(`No weixin account logged in.
|
|
25
25
|
`),process.stdout.write("Run `easbot weixin login` to bind your WeChat via iLink.\n");return}process.stdout.write(`weixin current user:
|
|
26
|
-
`),process.stdout.write(` userId: ${
|
|
27
|
-
`),process.stdout.write(` baseUrl: ${
|
|
28
|
-
`),process.stdout.write(` savedAt: ${formatLocalISO(new Date(
|
|
29
|
-
`);let
|
|
30
|
-
`),process.stdout.write(` uid: ${
|
|
31
|
-
`),
|
|
32
|
-
`),
|
|
33
|
-
`),process.stdout.write(` lastSeen: ${formatLocalISO(new Date(
|
|
26
|
+
`),process.stdout.write(` userId: ${t.userId??"(unknown)"}
|
|
27
|
+
`),process.stdout.write(` baseUrl: ${t.baseUrl}
|
|
28
|
+
`),process.stdout.write(` savedAt: ${formatLocalISO(new Date(t.savedAt))}
|
|
29
|
+
`);let e=(await Da()).find(n=>n.stableId===t.userId);e?(process.stdout.write(` contact: registered
|
|
30
|
+
`),process.stdout.write(` uid: ${e.uid}
|
|
31
|
+
`),e.profile.displayName&&process.stdout.write(` display: ${e.profile.displayName}
|
|
32
|
+
`),e.profile.username&&process.stdout.write(` username: ${e.profile.username}
|
|
33
|
+
`),process.stdout.write(` lastSeen: ${formatLocalISO(new Date(e.lastSeenAt))}
|
|
34
34
|
`)):(process.stdout.write(` contact: not registered
|
|
35
|
-
`),process.stdout.write(" hint: run `easbot weixin ensure-user` to register\n"));}catch(
|
|
36
|
-
`),process.exit(1);}}async function er(
|
|
37
|
-
`),process.exit(1));try{let n=await Ba(
|
|
35
|
+
`),process.stdout.write(" hint: run `easbot weixin ensure-user` to register\n"));}catch(t){process.stderr.write(`user failed: ${t}
|
|
36
|
+
`),process.exit(1);}}async function er(t){let r=ge(),e=Xt(t,r);typeof e=="string"&&(process.stderr.write(`${e}
|
|
37
|
+
`),process.exit(1));try{let n=await Ba(e),{contact:o,session:u,created:d}=n,y=d.contact&&d.session?"\u5DF2\u521B\u5EFA":"\u5DF2\u5B58\u5728\uFF08\u5DF2\u66F4\u65B0\uFF09";process.stdout.write([`[weixin routing] ${y} user: ${r}`,` contact.uid: ${o.uid}`,` contact.path: ${xa()}/contacts/${o.platform}/${o.stableId}.json`,` session.id: ${u.id}`,` session.path: ${ya()}/sessions.json`,` profile: ${JSON.stringify(o.profile)}`].join(`
|
|
38
38
|
`)+`
|
|
39
39
|
`);}catch(n){process.stderr.write(`ensure-user failed: ${n}
|
|
40
|
-
`),process.exit(1);}}async function tr(
|
|
40
|
+
`),process.exit(1);}}async function tr(t){let r=ge();t.length>0&&(process.stderr.write(`Unknown argument: ${t[0]}
|
|
41
41
|
`),process.stderr.write(`Usage: easbot weixin remove-user
|
|
42
|
-
`),process.exit(1));try{let
|
|
43
|
-
`);}catch(
|
|
44
|
-
`),process.exit(1);}}async function rr(
|
|
45
|
-
`),process.exit(1)),await ae(
|
|
42
|
+
`),process.exit(1));try{let e=await Ca(r,"weixin-main");process.stdout.write(`[weixin routing] removed user: ${r} contact=${e.removed.contact} session=${e.removed.session}
|
|
43
|
+
`);}catch(e){process.stderr.write(`remove-user failed: ${e}
|
|
44
|
+
`),process.exit(1);}}async function rr(t,r,e){let[n,...o]=t;switch(n){case "serve":r||(process.stderr.write(`[weixin] serve handler not available in this context.
|
|
45
|
+
`),process.exit(1)),await ae(e??"0.0.0",r);return;case "login":await Yt(o[0]==="clear");return;case "access":Jt(o);return;case "user":await Zt();return;case "ensure-user":await er(o);return;case "remove-user":await tr(o);return;default:ce();}}export{V as Gateway,rr as handleWeixinCli};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easbot/gateway",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "EASBot Gateway - AI Agent Server and Multi-channel Integration Platform - 支持 WebSocket、HTTP、Discord、Telegram、Slack 等多渠道集成",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -69,10 +69,10 @@
|
|
|
69
69
|
"ws": "^8.20.0",
|
|
70
70
|
"xdg-basedir": "^5.1.0",
|
|
71
71
|
"zod": "^4.4.3",
|
|
72
|
-
"@easbot/plugin": "0.
|
|
73
|
-
"@easbot/sdk": "0.
|
|
74
|
-
"@easbot/
|
|
75
|
-
"@easbot/
|
|
72
|
+
"@easbot/plugin": "0.3.0",
|
|
73
|
+
"@easbot/sdk": "0.3.0",
|
|
74
|
+
"@easbot/utils": "0.3.0",
|
|
75
|
+
"@easbot/types": "0.3.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/qrcode": "^1.5.6",
|