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

@zhin.js/adapter-milky

v0.0.9

Published

Zhin.js adapter for Milky protocol

Readme

@zhin.js/adapter-milky

Zhin.js Milky 协议适配器,一个适配器支持 WebSocket 正向/反向、SSE、Webhook 四种连接方式,由配置项 connection 区分;支持 HTTP API 调用与 access_token 鉴权。

功能特性

  • 🔌 Milky 协议兼容(通信说明
  • 📦 单一适配器context: milky,通过 connection 选择连接方式
  • 🌐 WebSocket 正向connection: ws):应用连协议端 ws(s)://baseUrl/event
  • 📡 SSEconnection: sse):应用 GET 协议端 /event
  • 📮 Webhookconnection: webhook):应用提供 POST 端点收事件
  • 🔄 WebSocket 反向connection: wss):应用开 WS 服务端,协议端来连
  • 🔐 access_token 鉴权(Header 或 query)
  • 📨 群聊 / 私聊消息收发与消息段映射
  • 🛠️ HTTP API 封装,供发消息、撤回、群管等复用

安装

pnpm add @zhin.js/adapter-milky ws eventsource

适配器依赖 @zhin.js/http 提供的 router 才能注册(Webhook/反向 WS 需挂路由),请同时启用 HTTP 服务:

pnpm add @zhin.js/http

配置

所有 Bot 使用 同一 context:milky,通过 connection 区分连接方式。

WebSocket 正向

plugins:
  - "@zhin.js/http"
  - "@zhin.js/adapter-milky"

bots:
  - context: milky
    connection: ws
    name: milky-bot
    baseUrl: "http://127.0.0.1:8080"
    access_token: "${MILKY_ACCESS_TOKEN}"
    reconnect_interval: 5000
    heartbeat_interval: 30000

SSE

bots:
  - context: milky
    connection: sse
    name: milky-sse-bot
    baseUrl: "http://127.0.0.1:8080"
    access_token: "${MILKY_ACCESS_TOKEN}"

Webhook

bots:
  - context: milky
    connection: webhook
    name: milky-webhook-bot
    baseUrl: "http://协议端地址"
    path: "/milky/webhook"               # 应用接收事件的 POST 路径
    access_token: "${MILKY_ACCESS_TOKEN}"

WebSocket 反向

bots:
  - context: milky
    connection: wss
    name: milky-wss-bot
    baseUrl: "http://协议端地址"
    path: "/milky/event"                 # 应用 WS 服务端路径
    access_token: "${MILKY_ACCESS_TOKEN}"
    heartbeat_interval: 30000

鉴权

所有连接方式统一支持:

  • HeaderAuthorization: Bearer {access_token}
  • Queryaccess_token=xxx

建议配置 access_token,并与协议端一致。

连接方式对比

| connection | 说明 | |------------|--------------------------------| | ws | 应用主动连协议端 /event | | sse | 应用 GET /event 拉取事件流 | | webhook | 协议端 POST 到应用配置的 path | | wss | 协议端连应用提供的 WS path |

使用示例

消息处理

import { addCommand, MessageCommand } from 'zhin.js'

addCommand(new MessageCommand('hello <name:text>')
  .action(async (message, result) => {
    return `你好,${result.params.name}!`
  })
)

发送消息段

addCommand(new MessageCommand('pic')
  .action(async () => {
    return [
      { type: 'text', data: { text: '图片:' } },
      { type: 'image', data: { url: 'https://example.com/img.png' } }
    ]
  })
)

发消息、撤回、群管等通过适配器封装的 HTTP API 完成。群管能力通过 IGroupManagement 自动注册为工具,详见 工具与技能

消息 ID 格式

{message_scene}:{peer_id}:{message_seq}(如 group:123456:10001)。撤回时使用该 ID。

协议与 API 参考

依赖项

  • ws - WebSocket 客户端/服务端
  • eventsource - SSE 客户端
  • zhin.js - Zhin 核心
  • @zhin.js/http - 提供 router,适配器注册依赖

开发

pnpm build   # 构建
pnpm clean   # 清理

许可证

MIT License