Add QQ gateway runtime support
This commit is contained in:
+26
-5
@@ -11,10 +11,16 @@ import type { PlatformAdapter } from "./core/adapter.js";
|
||||
import { FeishuAdapter } from "./platforms/feishu/adapter.js";
|
||||
import { WeComAdapter } from "./platforms/wecom/adapter.js";
|
||||
import { QqAdapter } from "./platforms/qq/adapter.js";
|
||||
import { QqGatewayClient } from "./platforms/qq/gateway-client.js";
|
||||
import { GenericWebhookAdapter } from "./platforms/webhook/adapter.js";
|
||||
import { WeixinAdapter } from "./platforms/weixin/adapter.js";
|
||||
|
||||
export function createApp(config: AppConfig): express.Express {
|
||||
export interface GatewayRuntime {
|
||||
app: express.Express;
|
||||
qqGatewayClient?: QqGatewayClient;
|
||||
}
|
||||
|
||||
export function createGatewayRuntime(config: AppConfig): GatewayRuntime {
|
||||
const sessions = new SessionStore();
|
||||
const agents = new AgentRegistry(config.defaultAgent);
|
||||
for (const agentConfig of config.agents) {
|
||||
@@ -23,10 +29,11 @@ export function createApp(config: AppConfig): express.Express {
|
||||
|
||||
const gateway = new Gateway(config.policy, agents, sessions);
|
||||
const platforms = new PlatformRegistry();
|
||||
const qqAdapter = new QqAdapter(config.platforms.qq, gateway);
|
||||
const adapters: PlatformAdapter[] = [
|
||||
new FeishuAdapter(config.platforms.feishu, gateway),
|
||||
new WeComAdapter(config.platforms.wecom),
|
||||
new QqAdapter(config.platforms.qq, gateway),
|
||||
qqAdapter,
|
||||
new GenericWebhookAdapter(config.platforms.webhook, gateway),
|
||||
new WeixinAdapter(config.platforms.weixin, gateway)
|
||||
];
|
||||
@@ -75,14 +82,28 @@ export function createApp(config: AppConfig): express.Express {
|
||||
}
|
||||
mountWebhook("generic", "webhook");
|
||||
|
||||
return app;
|
||||
const qqGatewayClient = config.platforms.qq.enabled && config.platforms.qq.connectionMode === "websocket"
|
||||
? new QqGatewayClient(config.platforms.qq, qqAdapter)
|
||||
: undefined;
|
||||
|
||||
return { app, qqGatewayClient };
|
||||
}
|
||||
|
||||
export function createApp(config: AppConfig): express.Express {
|
||||
return createGatewayRuntime(config).app;
|
||||
}
|
||||
|
||||
export function startServer(config: AppConfig): Server {
|
||||
const app = createApp(config);
|
||||
return app.listen(config.server.port, config.server.host, () => {
|
||||
const runtime = createGatewayRuntime(config);
|
||||
const server = runtime.app.listen(config.server.port, config.server.host, () => {
|
||||
console.log(`gori-agent-gateway listening on ${config.server.host}:${config.server.port}`);
|
||||
if (runtime.qqGatewayClient) {
|
||||
console.log("QQ websocket gateway enabled; connecting to QQ...");
|
||||
runtime.qqGatewayClient.start();
|
||||
}
|
||||
});
|
||||
server.on("close", () => runtime.qqGatewayClient?.stop());
|
||||
return server;
|
||||
}
|
||||
|
||||
if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
|
||||
|
||||
Reference in New Issue
Block a user