npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ai-agent-router

v0.2.3

Published

A unified API gateway for managing multiple AI model providers (Anthropic, OpenAI, Gemini, etc.)

Readme

AI Agent Router

一个统一的 API 网关,用于管理多个 AI 模型供应商(Anthropic、OpenAI、Gemini 等),为 Claude Code、OpenCode、OpenClaw、PicoClaw 等 AI 编程助手提供统一接口。

功能特性

  • ✅ 支持多种 AI 模型协议(OpenAI、Anthropic、Gemini)
  • ✅ 一键启动:前台 Web UI + 网关服务,默认后台运行
  • ✅ Web 管理界面,可视化配置和管理
  • ✅ 模型供应商管理(添加、编辑、删除)
  • ✅ 模型管理(手动添加、自动拉取模型列表)
  • ✅ 请求日志记录和查看(支持流式响应的美化展示)
  • ✅ 双端点支持(/v1/*/api/gateway/*
  • ✅ API Key 认证保护网关服务(自动生成随机默认密码)
  • ✅ CLI 工具(aar),支持后台运行与 aar stop 停止
  • ✅ SQLite 数据库,数据存储在 ~/.aar/
  • IDE 深度集成:一键配置 Claude Code、OpenCode、OpenClaw 等编程助手
  • 配置备份:自动备份配置到 ~/.aar/backups/,支持一键还原

安装

npm install -g ai-agent-router

安装后可使用命令 aarnpx ai-agent-router

使用方法

启动服务(默认:后台运行 Web UI + 网关)

aar start
  • 默认行为:在后台同时启动 Web 管理界面和网关服务,关闭终端后进程继续运行。
  • 前台 UI:http://localhost:9527
  • 网关地址:http://localhost:1357(端口可在 Web 界面中配置)

启动后控制台会输出访问地址与网关状态,例如:

-------------------------------------------
  AI Agent Router
-------------------------------------------
  前台 UI:     http://localhost:9527
  网关地址:   http://localhost:1357
  网关状态:   运行中
  运行模式:   后台运行(关闭终端不影响)
  停止服务:   aar stop
-------------------------------------------

停止后台服务

aar stop

会停止由 aar start 在后台启动的 Web UI 与网关进程。

前台运行(附着当前终端)

若希望在前台运行、用 Ctrl+C 结束:

aar start --no-background

仅启动 Web UI(不启动网关)

aar start --no-gateway

仅启动管理界面,网关可在 Web 界面里再手动启动。

配置选项

# 指定 Web UI 端口(默认 9527)
aar start -p 8080

# 指定网关端口(默认从配置或 1357)
aar start -g 3000

# 组合:前台运行 + 自定义端口
aar start --no-background -p 9527 -g 1357

配置管理

# 获取配置
aar config --get port

# 设置配置(key 与 value 用空格分隔)
aar config --set port 1357
aar config --set api_key "your-secret-key"

常用配置项:port(网关端口)、api_key(网关 API Key,用于客户端认证)。

Web 管理界面

启动后访问 http://localhost:9527,可以:

  1. 配置网关:端口、API Key 等
  2. 管理供应商:添加、编辑、删除模型供应商
  3. 管理模型:手动添加或一键拉取模型列表
  4. 查看日志:API 请求日志,含流式响应美化
  5. 服务管理:在界面内启动/停止网关(使用 aar start 时通常已自动启动)
  6. IDE 集成:一键配置各类 AI 编程助手
    • Claude Code:配置模型映射(haiku/sonnet/opus)、自动处理 onboarding
    • OpenCode:配置默认模型
    • OpenClaw:配置默认模型和 fallback 模型
    • PicoClaw:即将支持

添加供应商与模型

  1. 打开 Web 界面 →「供应商」→「添加供应商」
  2. 填写:名称、协议(OpenAI / Anthropic / Gemini)、Base URL、API Key
  3. 在「模型」页可手动添加模型,或使用「拉取模型列表」从供应商拉取

使用网关 API

配置好供应商和模型后,客户端可请求网关(默认 http://localhost:1357)。

OpenAI 兼容

POST http://localhost:1357/v1/chat/completions
Content-Type: application/json
Authorization: Bearer your-gateway-api-key

{
  "model": "gpt-4",
  "messages": [...],
  "stream": true
}

网关路径形式

POST http://localhost:1357/api/gateway/v1/chat/completions
GET  http://localhost:1357/v1/models
GET  http://localhost:1357/api/gateway/models

Anthropic 兼容

POST http://localhost:1357/api/gateway/v1/messages
Content-Type: application/json
x-api-key: your-gateway-api-key

{
  "model": "claude-3-5-sonnet-20241022",
  "messages": [...]
}

认证:若在配置中设置了 API Key,请求头需带 x-api-keyAuthorization: Bearer <key>

开发

# 安装依赖
npm install

# 开发模式(仅 Next 前台,端口 9527)
npm run dev

# 构建
npm run build

# 生产启动(等同 aar start,需先 build)
npm start

项目结构

src/
├── server/                 # 网关与后端
│   ├── gateway.ts          # 网关请求处理
│   ├── gateway-server.ts   # 独立网关 HTTP 服务
│   ├── service-manager.ts  # 进程/服务管理
│   ├── providers/          # 各协议适配
│   └── logger.ts           # 请求日志
├── db/                     # SQLite(~/.aar/gateway.db)
│   ├── database.ts
│   ├── schema.ts
│   └── queries.ts
├── app/                    # Next.js App Router
│   ├── api/                # API 路由
│   │   ├── gateway/        # 网关转发
│   │   ├── config/         # 配置管理
│   │   ├── service/        # 服务管理
│   │   └── ide/            # IDE 集成 API
│   │       ├── claude/     # Claude Code 配置
│   │       ├── opencode/   # OpenCode 配置
│   │       └── openclaw/   # OpenClaw 配置
│   ├── ide/                # IDE 集成页面
│   ├── components/         # 通用组件
│   └── (其他页面)
└── cli/                    # CLI
    ├── index.ts            # aar start / stop / config
    └── gateway-server.ts   # 独立网关进程入口

数据目录

~/.aar/
├── gateway.db              # SQLite 数据库
├── backups/                # 配置备份目录
│   ├── settings-*.json     # Claude settings.json 备份
│   └── claude-*.json       # .claude.json 备份
└── settings.tmp.json       # 临时配置(未应用时)

技术栈

  • Next.js - 全栈与 Web UI
  • TypeScript - 类型安全
  • Tailwind CSS - 样式
  • SQLite (sql.js) - 本地存储
  • Commander.js - CLI

许可证

MIT

贡献

欢迎提交 Issue 与 Pull Request。