@easbot/gateway 0.2.43 → 0.2.45

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.
@@ -0,0 +1 @@
1
+ 'use strict';var chunkY6LH4FW3_cjs=require('./chunk-Y6LH4FW3.cjs');require('./chunk-3SBZTZXS.cjs');Object.defineProperty(exports,"ChannelPluginLoader",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.oa}});Object.defineProperty(exports,"GatewayServer",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.Ea}});Object.defineProperty(exports,"GatewayWebSocketServer",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.pa}});
@@ -0,0 +1 @@
1
+ export{oa as ChannelPluginLoader,Ea as GatewayServer,pa as GatewayWebSocketServer}from'./chunk-LQRPMD5X.mjs';import'./chunk-RGPJTZUB.mjs';
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkOKAA7SZE_cjs=require('./chunks/chunk-OKAA7SZE.cjs'),chunk3SBZTZXS_cjs=require('./chunks/chunk-3SBZTZXS.cjs'),utils=require('@easbot/utils');var a=chunk3SBZTZXS_cjs.b.create({service:"gateway"}),s=class t extends Error{constructor(e,d,v){super(e);chunk3SBZTZXS_cjs.a(this,"type");chunk3SBZTZXS_cjs.a(this,"stage");chunk3SBZTZXS_cjs.a(this,"cause");this.type="GatewayInitializationError",this.stage=d,this.cause=v,Error.captureStackTrace&&Error.captureStackTrace(this,t);}};function E(t){let i=["ECONNRESET","EPIPE","ETIMEDOUT","ECONNREFUSED","ENOTFOUND","EHOSTUNREACH","ENETUNREACH"],e=t.code;return i.includes(e??"")}function rt(){process.on("unhandledRejection",t=>{let i=t instanceof Error?t:new Error(String(t));E(i)||a.error("unhandled promise rejection",{error:i.message,stack:i.stack});}),process.on("uncaughtException",t=>{E(t)||(a.error("uncaught exception",{error:t.message,stack:t.stack}),process.exit(1));});}exports.Gateway=void 0;(lt=>{let t={initialized:false,initPromise:null,directory:".easbot",config:null},i,e={server:null,config:null,initialized:false,status:"stopped"};async function d(n={}){if(t.initialized)return;if(t.initPromise)return t.initPromise;let o={directory:n.directory??".easbot",printLogs:n.printLogs??false,logLevel:n.logLevel??"INFO"};return t.directory=o.directory,t.initPromise=(async()=>{let u=chunkOKAA7SZE_cjs.Z();try{await chunk3SBZTZXS_cjs.b.init({logDir:u.Path.log,print:o.printLogs,level:o.logLevel});}catch(r){throw new s("Failed to initialize log infrastructure","log",r instanceof Error?r:void 0)}try{rt();}catch(r){throw new s("Failed to install unhandled exception handlers","server",r instanceof Error?r:void 0)}utils.Fetch.hasProxyConfigured()&&(utils.Fetch.enableProxy({connectTimeout:1e4,keepAliveTimeout:3e4}),a.info("global proxy enabled",{proxyUrl:utils.Fetch.getProxyUrl()}));try{t.config=await chunkOKAA7SZE_cjs.w(o.directory);}catch(r){throw new s("Failed to load gateway configuration","config",r instanceof Error?r:void 0)}t.initialized=true,a.info("gateway runtime initialized",{directory:o.directory,logLevel:o.logLevel});})(),t.initPromise}lt.init=d;function v(){return t.initialized}lt.isInitialized=v;function b(){return i||(i=async()=>{if(!t.initialized)throw new s("Gateway not initialized. Call init() first.","server");let n=chunkOKAA7SZE_cjs._(),o=await chunkOKAA7SZE_cjs.w(n.directory);return o.server?.enabled?(e={server:null,config:o,initialized:true,status:"stopped"},a.info("gateway initialized",{port:o.server?.port,hostname:o.server?.hostname}),e):(a.debug("gateway server disabled or not configured"),{server:null,config:o,initialized:true,status:"stopped"})}),i}function f(){return b()()}lt.state=f;async function nt(){return (await f()).server}lt.get=nt;async function ot(){return (await f()).config?.server?.enabled??false}lt.isEnabled=ot;async function at(){return (await f()).config}lt.config=at;function it(){return e.status}lt.getStatus=it;async function P(n){a.debug("Gateway.start: called"),t.initialized||await d();let o=await f();if(!(o.config?.server?.enabled??true))throw a.warn("gateway server is disabled"),new Error("Gateway server is disabled");if(e.status==="running"){a.info("gateway server is already running");return}if(e.status==="starting"){a.info("gateway server is starting");return}e.status="starting";try{let r={...o.config?.server,...n};a.debug("gateway start: creating server with config",{port:r.port,hostname:r.hostname,path:r.path,https:r.https?.enabled});let C=await G(r);e.server=C,e.status="running",e.error=void 0,a.info("gateway server started",{port:r.port,hostname:r.hostname});}catch(r){throw e.status="error",e.error=r instanceof Error?r.message:String(r),a.error("failed to start gateway server",{error:e.error}),r}}lt.start=P;async function A(){if(e.status==="stopped"){a.info("gateway server is already stopped");return}if(e.status==="stopping"){a.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 chunk3SBZTZXS_cjs.b.close(),a.info("gateway server stopped");}catch(n){throw e.status="error",e.error=n instanceof Error?n.message:String(n),a.error("failed to stop gateway server",{error:e.error}),n}}lt.stop=A;async function st(n){a.info("restarting gateway server"),(e.status==="running"||e.status==="starting")&&await A(),await P(n);}lt.restart=st;async function gt(){let n=chunkOKAA7SZE_cjs._(),o=await chunkOKAA7SZE_cjs.w(n.directory);return e.config=o,t.config=o,a.info("gateway config reloaded"),o}lt.reloadConfig=gt;async function G(n,o){a.debug("createGatewayServer: starting");let{GatewayServer:u}=await import('./chunks/server-IEPHSA6A.cjs'),r=new u(n),C=o?.startupTimeout??3e4;if(await(async()=>{let g=new Promise((l,T)=>{setTimeout(()=>{T(new Error(`Gateway server startup timeout after ${C}ms`));},C);});try{await Promise.race([r.start(),g]);}catch(l){a.error("gateway server start failed, attempting cleanup",{error:l instanceof Error?l.message:String(l)});try{await r.stop();}catch{}throw l}})(),o?.onStarted)try{await o.onStarted(r);}catch(g){a.warn("server started but onStarted callback failed",{error:g instanceof Error?g.message:String(g)});}return a.info("gateway server created and started",{port:n.port,hostname:n.hostname}),r}lt.createGatewayServer=G;})(exports.Gateway||(exports.Gateway={}));async function ht(t){let{Log:i}=await import('./chunks/log-VLMXTUPA.cjs'),e=false;await i.init({logDir:t.logDir??process.env.EASBOT_LOG_PATH??process.cwd(),print:t.print??false,dev:t.dev??e,level:t.level??("INFO")});}Object.defineProperty(exports,"AgentRegistry",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.Ca}});Object.defineProperty(exports,"AgentRegistryConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.p}});Object.defineProperty(exports,"AgentSyncConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.k}});Object.defineProperty(exports,"AgentSyncManager",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.Da}});Object.defineProperty(exports,"AuthConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.j}});Object.defineProperty(exports,"BaseChannelPlugin",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.qa}});Object.defineProperty(exports,"ChannelConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.h}});Object.defineProperty(exports,"ChannelPluginLoader",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.oa}});Object.defineProperty(exports,"ChannelPluginRegistry",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.Aa}});Object.defineProperty(exports,"CircuitBreakerConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.o}});Object.defineProperty(exports,"ConnectionPoolConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.m}});Object.defineProperty(exports,"DEBUG_AGENT_FILTER",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.T}});Object.defineProperty(exports,"DEFAULT_AGENT_FILTER",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.S}});Object.defineProperty(exports,"DEFAULT_AGENT_REGISTRY_CONFIG",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.ha}});Object.defineProperty(exports,"DEFAULT_CONNECTION_POOL_CONFIG",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.ja}});Object.defineProperty(exports,"DEFAULT_SYNC_CONFIG",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.ia}});Object.defineProperty(exports,"DEFAULT_TOKEN_AUTH_CONFIG",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.ga}});Object.defineProperty(exports,"DEFAULT_WEBSOCKET_SERVER_CONFIG",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.fa}});Object.defineProperty(exports,"DiscordPlugin",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.sa}});Object.defineProperty(exports,"FeishuChannelConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.c}});Object.defineProperty(exports,"FeishuPlugin",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.ua}});Object.defineProperty(exports,"GatewayClientConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.s}});Object.defineProperty(exports,"GatewayClusterConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.l}});Object.defineProperty(exports,"GatewayConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.t}});Object.defineProperty(exports,"GatewayServer",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.Ea}});Object.defineProperty(exports,"GatewayServerConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.r}});Object.defineProperty(exports,"GatewaySessionManager",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.na}});Object.defineProperty(exports,"HTTPSConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.i}});Object.defineProperty(exports,"MessageQueueConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.n}});Object.defineProperty(exports,"MessageRouter",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.ka}});Object.defineProperty(exports,"MessageStore",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.la}});Object.defineProperty(exports,"NostrChannelConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.g}});Object.defineProperty(exports,"NostrPlugin",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.ya}});Object.defineProperty(exports,"SdkEventBridge",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.R}});Object.defineProperty(exports,"SdkEventBus",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.Q}});Object.defineProperty(exports,"SdkEventType",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.P}});Object.defineProperty(exports,"SdkMessagetCollector",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.U}});Object.defineProperty(exports,"SessionConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.q}});Object.defineProperty(exports,"SessionStore",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.ma}});Object.defineProperty(exports,"SignalChannelConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.f}});Object.defineProperty(exports,"SignalPlugin",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.xa}});Object.defineProperty(exports,"SlackChannelConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.b}});Object.defineProperty(exports,"SlackPlugin",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.ta}});Object.defineProperty(exports,"TelegramChannelConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.a}});Object.defineProperty(exports,"TelegramPlugin",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.ra}});Object.defineProperty(exports,"WeChatChannelConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.d}});Object.defineProperty(exports,"WeChatPlugin",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.va}});Object.defineProperty(exports,"WebChatChannelConfigSchema",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.e}});Object.defineProperty(exports,"WebChatPlugin",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.wa}});Object.defineProperty(exports,"clearConfigCache",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.z}});Object.defineProperty(exports,"convertToGatewayMessage",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.ba}});Object.defineProperty(exports,"createChannelPlugin",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.za}});Object.defineProperty(exports,"createDefaultSessionState",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.da}});Object.defineProperty(exports,"createGatewayMessage",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.$}});Object.defineProperty(exports,"createTextMessage",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.aa}});Object.defineProperty(exports,"generateSessionId",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.ca}});Object.defineProperty(exports,"generateSubscriptionId",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.ea}});Object.defineProperty(exports,"getAgentAdapter",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.W}});Object.defineProperty(exports,"getAgentRegistryConfig",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.G}});Object.defineProperty(exports,"getAuthConfig",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.L}});Object.defineProperty(exports,"getChannelConfig",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.C}});Object.defineProperty(exports,"getCircuitBreakerConfig",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.F}});Object.defineProperty(exports,"getClusterConfig",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.M}});Object.defineProperty(exports,"getConfig",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.x}});Object.defineProperty(exports,"getConfigDirectory",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.A}});Object.defineProperty(exports,"getConnectionPoolConfig",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.D}});Object.defineProperty(exports,"getDefaultAgent",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.N}});Object.defineProperty(exports,"getGatewayClientConfig",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.I}});Object.defineProperty(exports,"getGatewayClientUrl",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.J}});Object.defineProperty(exports,"getHTTPSConfig",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.K}});Object.defineProperty(exports,"getLogLevel",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.O}});Object.defineProperty(exports,"getMessageQueueConfig",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.E}});Object.defineProperty(exports,"getServerConfig",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.B}});Object.defineProperty(exports,"getSessionConfig",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.H}});Object.defineProperty(exports,"getSupportedPlatforms",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.Ba}});Object.defineProperty(exports,"hasAgentAdapter",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.X}});Object.defineProperty(exports,"isConfigLoaded",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.y}});Object.defineProperty(exports,"loadConfig",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.w}});Object.defineProperty(exports,"parsePartialConfig",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.v}});Object.defineProperty(exports,"requireAgentAdapter",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.Y}});Object.defineProperty(exports,"setAgentAdapter",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.V}});Object.defineProperty(exports,"validateConfig",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.u}});exports.initLog=ht;
1
+ 'use strict';var chunkY6LH4FW3_cjs=require('./chunks/chunk-Y6LH4FW3.cjs'),chunk3SBZTZXS_cjs=require('./chunks/chunk-3SBZTZXS.cjs'),utils=require('@easbot/utils');var a=chunk3SBZTZXS_cjs.b.create({service:"gateway"}),s=class t extends Error{constructor(e,d,v){super(e);chunk3SBZTZXS_cjs.a(this,"type");chunk3SBZTZXS_cjs.a(this,"stage");chunk3SBZTZXS_cjs.a(this,"cause");this.type="GatewayInitializationError",this.stage=d,this.cause=v,Error.captureStackTrace&&Error.captureStackTrace(this,t);}};function E(t){let i=["ECONNRESET","EPIPE","ETIMEDOUT","ECONNREFUSED","ENOTFOUND","EHOSTUNREACH","ENETUNREACH"],e=t.code;return i.includes(e??"")}function rt(){process.on("unhandledRejection",t=>{let i=t instanceof Error?t:new Error(String(t));E(i)||a.error("unhandled promise rejection",{error:i.message,stack:i.stack});}),process.on("uncaughtException",t=>{E(t)||(a.error("uncaught exception",{error:t.message,stack:t.stack}),process.exit(1));});}exports.Gateway=void 0;(lt=>{let t={initialized:false,initPromise:null,directory:".easbot",config:null},i,e={server:null,config:null,initialized:false,status:"stopped"};async function d(n={}){if(t.initialized)return;if(t.initPromise)return t.initPromise;let o={directory:n.directory??".easbot",printLogs:n.printLogs??false,logLevel:n.logLevel??"INFO"};return t.directory=o.directory,t.initPromise=(async()=>{let u=chunkY6LH4FW3_cjs.Z();try{await chunk3SBZTZXS_cjs.b.init({logDir:u.Path.log,print:o.printLogs,level:o.logLevel});}catch(r){throw new s("Failed to initialize log infrastructure","log",r instanceof Error?r:void 0)}try{rt();}catch(r){throw new s("Failed to install unhandled exception handlers","server",r instanceof Error?r:void 0)}utils.Fetch.hasProxyConfigured()&&(utils.Fetch.enableProxy({connectTimeout:1e4,keepAliveTimeout:3e4}),a.info("global proxy enabled",{proxyUrl:utils.Fetch.getProxyUrl()}));try{t.config=await chunkY6LH4FW3_cjs.w(o.directory);}catch(r){throw new s("Failed to load gateway configuration","config",r instanceof Error?r:void 0)}t.initialized=true,a.info("gateway runtime initialized",{directory:o.directory,logLevel:o.logLevel});})(),t.initPromise}lt.init=d;function v(){return t.initialized}lt.isInitialized=v;function b(){return i||(i=async()=>{if(!t.initialized)throw new s("Gateway not initialized. Call init() first.","server");let n=chunkY6LH4FW3_cjs._(),o=await chunkY6LH4FW3_cjs.w(n.directory);return o.server?.enabled?(e={server:null,config:o,initialized:true,status:"stopped"},a.info("gateway initialized",{port:o.server?.port,hostname:o.server?.hostname}),e):(a.debug("gateway server disabled or not configured"),{server:null,config:o,initialized:true,status:"stopped"})}),i}function f(){return b()()}lt.state=f;async function nt(){return (await f()).server}lt.get=nt;async function ot(){return (await f()).config?.server?.enabled??false}lt.isEnabled=ot;async function at(){return (await f()).config}lt.config=at;function it(){return e.status}lt.getStatus=it;async function P(n){a.debug("Gateway.start: called"),t.initialized||await d();let o=await f();if(!(o.config?.server?.enabled??true))throw a.warn("gateway server is disabled"),new Error("Gateway server is disabled");if(e.status==="running"){a.info("gateway server is already running");return}if(e.status==="starting"){a.info("gateway server is starting");return}e.status="starting";try{let r={...o.config?.server,...n};a.debug("gateway start: creating server with config",{port:r.port,hostname:r.hostname,path:r.path,https:r.https?.enabled});let C=await G(r);e.server=C,e.status="running",e.error=void 0,a.info("gateway server started",{port:r.port,hostname:r.hostname});}catch(r){throw e.status="error",e.error=r instanceof Error?r.message:String(r),a.error("failed to start gateway server",{error:e.error}),r}}lt.start=P;async function A(){if(e.status==="stopped"){a.info("gateway server is already stopped");return}if(e.status==="stopping"){a.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 chunk3SBZTZXS_cjs.b.close(),a.info("gateway server stopped");}catch(n){throw e.status="error",e.error=n instanceof Error?n.message:String(n),a.error("failed to stop gateway server",{error:e.error}),n}}lt.stop=A;async function st(n){a.info("restarting gateway server"),(e.status==="running"||e.status==="starting")&&await A(),await P(n);}lt.restart=st;async function gt(){let n=chunkY6LH4FW3_cjs._(),o=await chunkY6LH4FW3_cjs.w(n.directory);return e.config=o,t.config=o,a.info("gateway config reloaded"),o}lt.reloadConfig=gt;async function G(n,o){a.debug("createGatewayServer: starting");let{GatewayServer:u}=await import('./chunks/server-YANYGRJZ.cjs'),r=new u(n),C=o?.startupTimeout??3e4;if(await(async()=>{let g=new Promise((l,T)=>{setTimeout(()=>{T(new Error(`Gateway server startup timeout after ${C}ms`));},C);});try{await Promise.race([r.start(),g]);}catch(l){a.error("gateway server start failed, attempting cleanup",{error:l instanceof Error?l.message:String(l)});try{await r.stop();}catch{}throw l}})(),o?.onStarted)try{await o.onStarted(r);}catch(g){a.warn("server started but onStarted callback failed",{error:g instanceof Error?g.message:String(g)});}return a.info("gateway server created and started",{port:n.port,hostname:n.hostname}),r}lt.createGatewayServer=G;})(exports.Gateway||(exports.Gateway={}));async function ht(t){let{Log:i}=await import('./chunks/log-VLMXTUPA.cjs'),e=false;await i.init({logDir:t.logDir??process.env.EASBOT_LOG_PATH??process.cwd(),print:t.print??false,dev:t.dev??e,level:t.level??("INFO")});}Object.defineProperty(exports,"AgentRegistry",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.Ca}});Object.defineProperty(exports,"AgentRegistryConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.p}});Object.defineProperty(exports,"AgentSyncConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.k}});Object.defineProperty(exports,"AgentSyncManager",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.Da}});Object.defineProperty(exports,"AuthConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.j}});Object.defineProperty(exports,"BaseChannelPlugin",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.qa}});Object.defineProperty(exports,"ChannelConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.h}});Object.defineProperty(exports,"ChannelPluginLoader",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.oa}});Object.defineProperty(exports,"ChannelPluginRegistry",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.Aa}});Object.defineProperty(exports,"CircuitBreakerConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.o}});Object.defineProperty(exports,"ConnectionPoolConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.m}});Object.defineProperty(exports,"DEBUG_AGENT_FILTER",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.T}});Object.defineProperty(exports,"DEFAULT_AGENT_FILTER",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.S}});Object.defineProperty(exports,"DEFAULT_AGENT_REGISTRY_CONFIG",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.ha}});Object.defineProperty(exports,"DEFAULT_CONNECTION_POOL_CONFIG",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.ja}});Object.defineProperty(exports,"DEFAULT_SYNC_CONFIG",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.ia}});Object.defineProperty(exports,"DEFAULT_TOKEN_AUTH_CONFIG",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.ga}});Object.defineProperty(exports,"DEFAULT_WEBSOCKET_SERVER_CONFIG",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.fa}});Object.defineProperty(exports,"DiscordPlugin",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.sa}});Object.defineProperty(exports,"FeishuChannelConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.c}});Object.defineProperty(exports,"FeishuPlugin",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.ua}});Object.defineProperty(exports,"GatewayClientConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.s}});Object.defineProperty(exports,"GatewayClusterConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.l}});Object.defineProperty(exports,"GatewayConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.t}});Object.defineProperty(exports,"GatewayServer",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.Ea}});Object.defineProperty(exports,"GatewayServerConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.r}});Object.defineProperty(exports,"GatewaySessionManager",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.na}});Object.defineProperty(exports,"HTTPSConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.i}});Object.defineProperty(exports,"MessageQueueConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.n}});Object.defineProperty(exports,"MessageRouter",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.ka}});Object.defineProperty(exports,"MessageStore",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.la}});Object.defineProperty(exports,"NostrChannelConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.g}});Object.defineProperty(exports,"NostrPlugin",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.ya}});Object.defineProperty(exports,"SdkEventBridge",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.R}});Object.defineProperty(exports,"SdkEventBus",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.Q}});Object.defineProperty(exports,"SdkEventType",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.P}});Object.defineProperty(exports,"SdkMessagetCollector",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.U}});Object.defineProperty(exports,"SessionConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.q}});Object.defineProperty(exports,"SessionStore",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.ma}});Object.defineProperty(exports,"SignalChannelConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.f}});Object.defineProperty(exports,"SignalPlugin",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.xa}});Object.defineProperty(exports,"SlackChannelConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.b}});Object.defineProperty(exports,"SlackPlugin",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.ta}});Object.defineProperty(exports,"TelegramChannelConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.a}});Object.defineProperty(exports,"TelegramPlugin",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.ra}});Object.defineProperty(exports,"WeChatChannelConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.d}});Object.defineProperty(exports,"WeChatPlugin",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.va}});Object.defineProperty(exports,"WebChatChannelConfigSchema",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.e}});Object.defineProperty(exports,"WebChatPlugin",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.wa}});Object.defineProperty(exports,"clearConfigCache",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.z}});Object.defineProperty(exports,"convertToGatewayMessage",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.ba}});Object.defineProperty(exports,"createChannelPlugin",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.za}});Object.defineProperty(exports,"createDefaultSessionState",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.da}});Object.defineProperty(exports,"createGatewayMessage",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.$}});Object.defineProperty(exports,"createTextMessage",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.aa}});Object.defineProperty(exports,"generateSessionId",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.ca}});Object.defineProperty(exports,"generateSubscriptionId",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.ea}});Object.defineProperty(exports,"getAgentAdapter",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.W}});Object.defineProperty(exports,"getAgentRegistryConfig",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.G}});Object.defineProperty(exports,"getAuthConfig",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.L}});Object.defineProperty(exports,"getChannelConfig",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.C}});Object.defineProperty(exports,"getCircuitBreakerConfig",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.F}});Object.defineProperty(exports,"getClusterConfig",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.M}});Object.defineProperty(exports,"getConfig",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.x}});Object.defineProperty(exports,"getConfigDirectory",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.A}});Object.defineProperty(exports,"getConnectionPoolConfig",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.D}});Object.defineProperty(exports,"getDefaultAgent",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.N}});Object.defineProperty(exports,"getGatewayClientConfig",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.I}});Object.defineProperty(exports,"getGatewayClientUrl",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.J}});Object.defineProperty(exports,"getHTTPSConfig",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.K}});Object.defineProperty(exports,"getLogLevel",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.O}});Object.defineProperty(exports,"getMessageQueueConfig",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.E}});Object.defineProperty(exports,"getServerConfig",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.B}});Object.defineProperty(exports,"getSessionConfig",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.H}});Object.defineProperty(exports,"getSupportedPlatforms",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.Ba}});Object.defineProperty(exports,"hasAgentAdapter",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.X}});Object.defineProperty(exports,"isConfigLoaded",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.y}});Object.defineProperty(exports,"loadConfig",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.w}});Object.defineProperty(exports,"parsePartialConfig",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.v}});Object.defineProperty(exports,"requireAgentAdapter",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.Y}});Object.defineProperty(exports,"setAgentAdapter",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.V}});Object.defineProperty(exports,"validateConfig",{enumerable:true,get:function(){return chunkY6LH4FW3_cjs.u}});exports.initLog=ht;
package/dist/index.d.cts CHANGED
@@ -1975,14 +1975,14 @@ declare class WebSocketServerAgentSync {
1975
1975
  getSubscribers(): string[];
1976
1976
  private sendMessage;
1977
1977
  handleAgentRegister(clientId: string, payload: {
1978
- agentId: string;
1979
- name: string;
1980
- address: string;
1978
+ agentId?: string;
1979
+ name?: string;
1980
+ address?: string;
1981
1981
  capabilities?: string[];
1982
1982
  metadata?: Record<string, unknown>;
1983
1983
  }): Promise<void>;
1984
1984
  handleAgentDeregister(clientId: string, payload: {
1985
- agentId: string;
1985
+ agentId?: string;
1986
1986
  }): Promise<void>;
1987
1987
  cleanupClient(clientId: string): Promise<void>;
1988
1988
  }
@@ -2924,6 +2924,7 @@ declare class SdkEventBridge {
2924
2924
  private abortController;
2925
2925
  private started;
2926
2926
  private readonly sessionFilter?;
2927
+ private _cachedPrimaryAgents;
2927
2928
  constructor(sdk: EasbotClient, localEventBus?: SdkEventBus, sessionFilter?: (sessionId: string) => boolean);
2928
2929
  private pushEvent;
2929
2930
  start(): Promise<void>;
@@ -2940,6 +2941,7 @@ declare class SdkEventBridge {
2940
2941
  private handleStepFinishPart;
2941
2942
  private handleReasoningPart;
2942
2943
  private handleSessionStatus;
2944
+ private shouldFilterAgent;
2943
2945
  }
2944
2946
 
2945
2947
  interface AgentClientFilterConfig {
package/dist/index.d.ts CHANGED
@@ -1975,14 +1975,14 @@ declare class WebSocketServerAgentSync {
1975
1975
  getSubscribers(): string[];
1976
1976
  private sendMessage;
1977
1977
  handleAgentRegister(clientId: string, payload: {
1978
- agentId: string;
1979
- name: string;
1980
- address: string;
1978
+ agentId?: string;
1979
+ name?: string;
1980
+ address?: string;
1981
1981
  capabilities?: string[];
1982
1982
  metadata?: Record<string, unknown>;
1983
1983
  }): Promise<void>;
1984
1984
  handleAgentDeregister(clientId: string, payload: {
1985
- agentId: string;
1985
+ agentId?: string;
1986
1986
  }): Promise<void>;
1987
1987
  cleanupClient(clientId: string): Promise<void>;
1988
1988
  }
@@ -2924,6 +2924,7 @@ declare class SdkEventBridge {
2924
2924
  private abortController;
2925
2925
  private started;
2926
2926
  private readonly sessionFilter?;
2927
+ private _cachedPrimaryAgents;
2927
2928
  constructor(sdk: EasbotClient, localEventBus?: SdkEventBus, sessionFilter?: (sessionId: string) => boolean);
2928
2929
  private pushEvent;
2929
2930
  start(): Promise<void>;
@@ -2940,6 +2941,7 @@ declare class SdkEventBridge {
2940
2941
  private handleStepFinishPart;
2941
2942
  private handleReasoningPart;
2942
2943
  private handleSessionStatus;
2944
+ private shouldFilterAgent;
2943
2945
  }
2944
2946
 
2945
2947
  interface AgentClientFilterConfig {
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import {Z,w,_}from'./chunks/chunk-MURSGSGX.mjs';export{Ca as AgentRegistry,p as AgentRegistryConfigSchema,k as AgentSyncConfigSchema,Da as AgentSyncManager,j as AuthConfigSchema,qa as BaseChannelPlugin,h as ChannelConfigSchema,oa as ChannelPluginLoader,Aa 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,Ea as GatewayServer,r as GatewayServerConfigSchema,na as GatewaySessionManager,i as HTTPSConfigSchema,n as MessageQueueConfigSchema,ka as MessageRouter,la as MessageStore,g as NostrChannelConfigSchema,ya as NostrPlugin,R as SdkEventBridge,Q as SdkEventBus,P as SdkEventType,U as SdkMessagetCollector,q as SessionConfigSchema,ma as SessionStore,f as SignalChannelConfigSchema,xa as SignalPlugin,b as SlackChannelConfigSchema,ta as SlackPlugin,a as TelegramChannelConfigSchema,ra as TelegramPlugin,d as WeChatChannelConfigSchema,va as WeChatPlugin,e as WebChatChannelConfigSchema,wa as WebChatPlugin,z as clearConfigCache,ba as convertToGatewayMessage,za as createChannelPlugin,da as createDefaultSessionState,$ as createGatewayMessage,aa as createTextMessage,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,Ba as getSupportedPlatforms,X as hasAgentAdapter,y as isConfigLoaded,w as loadConfig,v as parsePartialConfig,Y as requireAgentAdapter,V as setAgentAdapter,u as validateConfig}from'./chunks/chunk-MURSGSGX.mjs';import {b,a as a$1}from'./chunks/chunk-RGPJTZUB.mjs';import {Fetch}from'@easbot/utils';var a=b.create({service:"gateway"}),s=class t extends Error{constructor(e,d,v){super(e);a$1(this,"type");a$1(this,"stage");a$1(this,"cause");this.type="GatewayInitializationError",this.stage=d,this.cause=v,Error.captureStackTrace&&Error.captureStackTrace(this,t);}};function E(t){let i=["ECONNRESET","EPIPE","ETIMEDOUT","ECONNREFUSED","ENOTFOUND","EHOSTUNREACH","ENETUNREACH"],e=t.code;return i.includes(e??"")}function nt(){process.on("unhandledRejection",t=>{let i=t instanceof Error?t:new Error(String(t));E(i)||a.error("unhandled promise rejection",{error:i.message,stack:i.stack});}),process.on("uncaughtException",t=>{E(t)||(a.error("uncaught exception",{error:t.message,stack:t.stack}),process.exit(1));});}var m;(ct=>{let t={initialized:false,initPromise:null,directory:".easbot",config:null},i,e={server:null,config:null,initialized:false,status:"stopped"};async function d(n={}){if(t.initialized)return;if(t.initPromise)return t.initPromise;let o={directory:n.directory??".easbot",printLogs:n.printLogs??false,logLevel:n.logLevel??"INFO"};return t.directory=o.directory,t.initPromise=(async()=>{let u=Z();try{await b.init({logDir:u.Path.log,print:o.printLogs,level:o.logLevel});}catch(r){throw new s("Failed to initialize log infrastructure","log",r instanceof Error?r:void 0)}try{nt();}catch(r){throw new s("Failed to install unhandled exception handlers","server",r instanceof Error?r:void 0)}Fetch.hasProxyConfigured()&&(Fetch.enableProxy({connectTimeout:1e4,keepAliveTimeout:3e4}),a.info("global proxy enabled",{proxyUrl:Fetch.getProxyUrl()}));try{t.config=await w(o.directory);}catch(r){throw new s("Failed to load gateway configuration","config",r instanceof Error?r:void 0)}t.initialized=true,a.info("gateway runtime initialized",{directory:o.directory,logLevel:o.logLevel});})(),t.initPromise}ct.init=d;function v(){return t.initialized}ct.isInitialized=v;function b$1(){return i||(i=async()=>{if(!t.initialized)throw new s("Gateway not initialized. Call init() first.","server");let n=_(),o=await w(n.directory);return o.server?.enabled?(e={server:null,config:o,initialized:true,status:"stopped"},a.info("gateway initialized",{port:o.server?.port,hostname:o.server?.hostname}),e):(a.debug("gateway server disabled or not configured"),{server:null,config:o,initialized:true,status:"stopped"})}),i}function f(){return b$1()()}ct.state=f;async function ot(){return (await f()).server}ct.get=ot;async function at(){return (await f()).config?.server?.enabled??false}ct.isEnabled=at;async function it(){return (await f()).config}ct.config=it;function st(){return e.status}ct.getStatus=st;async function P(n){a.debug("Gateway.start: called"),t.initialized||await d();let o=await f();if(!(o.config?.server?.enabled??true))throw a.warn("gateway server is disabled"),new Error("Gateway server is disabled");if(e.status==="running"){a.info("gateway server is already running");return}if(e.status==="starting"){a.info("gateway server is starting");return}e.status="starting";try{let r={...o.config?.server,...n};a.debug("gateway start: creating server with config",{port:r.port,hostname:r.hostname,path:r.path,https:r.https?.enabled});let C=await G(r);e.server=C,e.status="running",e.error=void 0,a.info("gateway server started",{port:r.port,hostname:r.hostname});}catch(r){throw e.status="error",e.error=r instanceof Error?r.message:String(r),a.error("failed to start gateway server",{error:e.error}),r}}ct.start=P;async function A(){if(e.status==="stopped"){a.info("gateway server is already stopped");return}if(e.status==="stopping"){a.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 b.close(),a.info("gateway server stopped");}catch(n){throw e.status="error",e.error=n instanceof Error?n.message:String(n),a.error("failed to stop gateway server",{error:e.error}),n}}ct.stop=A;async function gt(n){a.info("restarting gateway server"),(e.status==="running"||e.status==="starting")&&await A(),await P(n);}ct.restart=gt;async function lt(){let n=_(),o=await w(n.directory);return e.config=o,t.config=o,a.info("gateway config reloaded"),o}ct.reloadConfig=lt;async function G(n,o){a.debug("createGatewayServer: starting");let{GatewayServer:u}=await import('./chunks/server-3EDAJA5R.mjs'),r=new u(n),C=o?.startupTimeout??3e4;if(await(async()=>{let g=new Promise((l,T)=>{setTimeout(()=>{T(new Error(`Gateway server startup timeout after ${C}ms`));},C);});try{await Promise.race([r.start(),g]);}catch(l){a.error("gateway server start failed, attempting cleanup",{error:l instanceof Error?l.message:String(l)});try{await r.stop();}catch{}throw l}})(),o?.onStarted)try{await o.onStarted(r);}catch(g){a.warn("server started but onStarted callback failed",{error:g instanceof Error?g.message:String(g)});}return a.info("gateway server created and started",{port:n.port,hostname:n.hostname}),r}ct.createGatewayServer=G;})(m||(m={}));async function mt(t){let{Log:i}=await import('./chunks/log-FQII2FT4.mjs'),e=false;await i.init({logDir:t.logDir??process.env.EASBOT_LOG_PATH??process.cwd(),print:t.print??false,dev:t.dev??e,level:t.level??("INFO")});}export{m as Gateway,mt as initLog};
1
+ import {Z,w,_}from'./chunks/chunk-LQRPMD5X.mjs';export{Ca as AgentRegistry,p as AgentRegistryConfigSchema,k as AgentSyncConfigSchema,Da as AgentSyncManager,j as AuthConfigSchema,qa as BaseChannelPlugin,h as ChannelConfigSchema,oa as ChannelPluginLoader,Aa 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,Ea as GatewayServer,r as GatewayServerConfigSchema,na as GatewaySessionManager,i as HTTPSConfigSchema,n as MessageQueueConfigSchema,ka as MessageRouter,la as MessageStore,g as NostrChannelConfigSchema,ya as NostrPlugin,R as SdkEventBridge,Q as SdkEventBus,P as SdkEventType,U as SdkMessagetCollector,q as SessionConfigSchema,ma as SessionStore,f as SignalChannelConfigSchema,xa as SignalPlugin,b as SlackChannelConfigSchema,ta as SlackPlugin,a as TelegramChannelConfigSchema,ra as TelegramPlugin,d as WeChatChannelConfigSchema,va as WeChatPlugin,e as WebChatChannelConfigSchema,wa as WebChatPlugin,z as clearConfigCache,ba as convertToGatewayMessage,za as createChannelPlugin,da as createDefaultSessionState,$ as createGatewayMessage,aa as createTextMessage,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,Ba as getSupportedPlatforms,X as hasAgentAdapter,y as isConfigLoaded,w as loadConfig,v as parsePartialConfig,Y as requireAgentAdapter,V as setAgentAdapter,u as validateConfig}from'./chunks/chunk-LQRPMD5X.mjs';import {b,a as a$1}from'./chunks/chunk-RGPJTZUB.mjs';import {Fetch}from'@easbot/utils';var a=b.create({service:"gateway"}),s=class t extends Error{constructor(e,d,v){super(e);a$1(this,"type");a$1(this,"stage");a$1(this,"cause");this.type="GatewayInitializationError",this.stage=d,this.cause=v,Error.captureStackTrace&&Error.captureStackTrace(this,t);}};function E(t){let i=["ECONNRESET","EPIPE","ETIMEDOUT","ECONNREFUSED","ENOTFOUND","EHOSTUNREACH","ENETUNREACH"],e=t.code;return i.includes(e??"")}function nt(){process.on("unhandledRejection",t=>{let i=t instanceof Error?t:new Error(String(t));E(i)||a.error("unhandled promise rejection",{error:i.message,stack:i.stack});}),process.on("uncaughtException",t=>{E(t)||(a.error("uncaught exception",{error:t.message,stack:t.stack}),process.exit(1));});}var m;(ct=>{let t={initialized:false,initPromise:null,directory:".easbot",config:null},i,e={server:null,config:null,initialized:false,status:"stopped"};async function d(n={}){if(t.initialized)return;if(t.initPromise)return t.initPromise;let o={directory:n.directory??".easbot",printLogs:n.printLogs??false,logLevel:n.logLevel??"INFO"};return t.directory=o.directory,t.initPromise=(async()=>{let u=Z();try{await b.init({logDir:u.Path.log,print:o.printLogs,level:o.logLevel});}catch(r){throw new s("Failed to initialize log infrastructure","log",r instanceof Error?r:void 0)}try{nt();}catch(r){throw new s("Failed to install unhandled exception handlers","server",r instanceof Error?r:void 0)}Fetch.hasProxyConfigured()&&(Fetch.enableProxy({connectTimeout:1e4,keepAliveTimeout:3e4}),a.info("global proxy enabled",{proxyUrl:Fetch.getProxyUrl()}));try{t.config=await w(o.directory);}catch(r){throw new s("Failed to load gateway configuration","config",r instanceof Error?r:void 0)}t.initialized=true,a.info("gateway runtime initialized",{directory:o.directory,logLevel:o.logLevel});})(),t.initPromise}ct.init=d;function v(){return t.initialized}ct.isInitialized=v;function b$1(){return i||(i=async()=>{if(!t.initialized)throw new s("Gateway not initialized. Call init() first.","server");let n=_(),o=await w(n.directory);return o.server?.enabled?(e={server:null,config:o,initialized:true,status:"stopped"},a.info("gateway initialized",{port:o.server?.port,hostname:o.server?.hostname}),e):(a.debug("gateway server disabled or not configured"),{server:null,config:o,initialized:true,status:"stopped"})}),i}function f(){return b$1()()}ct.state=f;async function ot(){return (await f()).server}ct.get=ot;async function at(){return (await f()).config?.server?.enabled??false}ct.isEnabled=at;async function it(){return (await f()).config}ct.config=it;function st(){return e.status}ct.getStatus=st;async function P(n){a.debug("Gateway.start: called"),t.initialized||await d();let o=await f();if(!(o.config?.server?.enabled??true))throw a.warn("gateway server is disabled"),new Error("Gateway server is disabled");if(e.status==="running"){a.info("gateway server is already running");return}if(e.status==="starting"){a.info("gateway server is starting");return}e.status="starting";try{let r={...o.config?.server,...n};a.debug("gateway start: creating server with config",{port:r.port,hostname:r.hostname,path:r.path,https:r.https?.enabled});let C=await G(r);e.server=C,e.status="running",e.error=void 0,a.info("gateway server started",{port:r.port,hostname:r.hostname});}catch(r){throw e.status="error",e.error=r instanceof Error?r.message:String(r),a.error("failed to start gateway server",{error:e.error}),r}}ct.start=P;async function A(){if(e.status==="stopped"){a.info("gateway server is already stopped");return}if(e.status==="stopping"){a.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 b.close(),a.info("gateway server stopped");}catch(n){throw e.status="error",e.error=n instanceof Error?n.message:String(n),a.error("failed to stop gateway server",{error:e.error}),n}}ct.stop=A;async function gt(n){a.info("restarting gateway server"),(e.status==="running"||e.status==="starting")&&await A(),await P(n);}ct.restart=gt;async function lt(){let n=_(),o=await w(n.directory);return e.config=o,t.config=o,a.info("gateway config reloaded"),o}ct.reloadConfig=lt;async function G(n,o){a.debug("createGatewayServer: starting");let{GatewayServer:u}=await import('./chunks/server-ZXWPGT6C.mjs'),r=new u(n),C=o?.startupTimeout??3e4;if(await(async()=>{let g=new Promise((l,T)=>{setTimeout(()=>{T(new Error(`Gateway server startup timeout after ${C}ms`));},C);});try{await Promise.race([r.start(),g]);}catch(l){a.error("gateway server start failed, attempting cleanup",{error:l instanceof Error?l.message:String(l)});try{await r.stop();}catch{}throw l}})(),o?.onStarted)try{await o.onStarted(r);}catch(g){a.warn("server started but onStarted callback failed",{error:g instanceof Error?g.message:String(g)});}return a.info("gateway server created and started",{port:n.port,hostname:n.hostname}),r}ct.createGatewayServer=G;})(m||(m={}));async function mt(t){let{Log:i}=await import('./chunks/log-FQII2FT4.mjs'),e=false;await i.init({logDir:t.logDir??process.env.EASBOT_LOG_PATH??process.cwd(),print:t.print??false,dev:t.dev??e,level:t.level??("INFO")});}export{m as Gateway,mt as initLog};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easbot/gateway",
3
- "version": "0.2.43",
3
+ "version": "0.2.45",
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",
@@ -67,10 +67,10 @@
67
67
  "ws": "^8.20.0",
68
68
  "xdg-basedir": "^5.1.0",
69
69
  "zod": "^4.4.3",
70
- "@easbot/plugin": "0.2.43",
71
- "@easbot/sdk": "0.2.43",
72
- "@easbot/types": "0.2.43",
73
- "@easbot/utils": "0.2.43"
70
+ "@easbot/plugin": "0.2.45",
71
+ "@easbot/sdk": "0.2.45",
72
+ "@easbot/utils": "0.2.45",
73
+ "@easbot/types": "0.2.45"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@biomejs/biome": "^2.4.14",
@@ -1 +0,0 @@
1
- export{oa as ChannelPluginLoader,Ea as GatewayServer,pa as GatewayWebSocketServer}from'./chunk-MURSGSGX.mjs';import'./chunk-RGPJTZUB.mjs';
@@ -1 +0,0 @@
1
- 'use strict';var chunkOKAA7SZE_cjs=require('./chunk-OKAA7SZE.cjs');require('./chunk-3SBZTZXS.cjs');Object.defineProperty(exports,"ChannelPluginLoader",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.oa}});Object.defineProperty(exports,"GatewayServer",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.Ea}});Object.defineProperty(exports,"GatewayWebSocketServer",{enumerable:true,get:function(){return chunkOKAA7SZE_cjs.pa}});