npm.io
0.2.47 • Published yesterday

@easbot/gateway

Licence
MIT
Version
0.2.47
Deps
25
Size
1002 kB
Vulns
0
Weekly
465

English | 中文

@easbot/gateway

EASBot Gateway - AI Agent 服务器与多渠道集成平台

特性

  • 多渠道集成:支持 WebSocket、HTTP、Discord、Telegram、Slack、飞书、微信等
  • Agent 核心:基于 AI SDK 的 Agent 运行时
  • 会话管理:支持多会话、多 Agent 并发
  • 消息路由:智能消息路由和格式转换
  • 事件系统:完善的事件驱动架构
  • 插件系统:可扩展的插件机制

安装

pnpm add @easbot/gateway

快速开始

启动服务器
import { createGateway } from '@easbot/gateway';

const gateway = createGateway({
  server: {
    port: 4096,
    websocket: true,
  },
  agents: [
    {
      id: 'main',
      model: 'anthropic/claude-3-5-sonnet',
    },
  ],
});

await gateway.start();
WebSocket 客户端
import { GatewayClient } from '@easbot/gateway';

const client = new GatewayClient('ws://localhost:4096');
await client.connect();

await client.sendMessage({
  agent: 'main',
  message: '你好!',
});

client.on('message', (msg) => {
  console.log('收到:', msg.content);
});
Telegram Bot
const gateway = createGateway({
  telegram: {
    botToken: process.env.TELEGRAM_BOT_TOKEN,
  },
  agents: [{ id: 'main' }],
});

await gateway.start();

渠道配置

WebSocket
{
  server: {
    port: 4096,
    path: '/ws',
  }
}
HTTP
{
  server: {
    http: {
      port: 4097,
      path: '/api',
    }
  }
}
Discord
{
  discord: {
    botToken: 'YOUR_BOT_TOKEN',
    guildId: 'YOUR_GUILD_ID',
  }
}
Telegram
{
  telegram: {
    botToken: 'YOUR_BOT_TOKEN',
  }
}
Slack
{
  slack: {
    botToken: 'xoxb-...',
    signingSecret: 'YOUR_SIGNING_SECRET',
  }
}

API 文档

Gateway

主网关类,管理所有渠道和 Agent。

const gateway = createGateway(config);
await gateway.start();
await gateway.stop();
GatewayClient

WebSocket 客户端,用于连接 Gateway。

const client = new GatewayClient(url);
await client.connect();
await client.sendMessage(message);
client.disconnect();
Agent

Agent 实例配置。

interface AgentConfig {
  id: string;
  model: string;
  systemPrompt?: string;
  tools?: Tool[];
}

开发

# 安装依赖
pnpm install

# 构建
pnpm build

# 测试
pnpm test

# 类型检查
pnpm type-check

许可证

MIT

Keywords