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

@tantianyi/openclaw-demo-plugin

v1.0.0

Published

OpenClaw demo plugin with CRM QR-code authentication

Readme

openclaw-demo-plugin

CRM 扫码登录的 OpenClaw 插件 demo,包含 3 个 tools、4 个 commands 和完整的 JWT 鉴权流程。


项目结构

openclaw-demo-plugin/
├── openclaw.plugin.json        # 插件清单(含 configSchema)
├── package.json                # openclaw.extensions 入口声明
├── tsconfig.json
├── src/
│   ├── index.ts                # 插件入口:注册 tools / commands / hook
│   ├── auth/
│   │   ├── client.ts           # JSON-RPC 客户端(fetchQrcode、pollScanCallback、validateToken)
│   │   ├── tokenStore.ts       # Token 持久化到 ~/.openclaw/crm-auth.json
│   │   └── qrLogin.ts          # 扫码登录流程编排(生成→展示→轮询→保存)
│   └── tools/
│       ├── weather.ts          # get_weather 工具
│       └── notes.ts            # save_note / list_notes 工具
└── skills/
    └── demo-assistant/
        └── SKILL.md            # Skill 定义

鉴权流程

用户首次发起请求
        │
        ▼
before_tool_call Hook
    loadToken() → null?
        │  是
        ▼
 返回 { block: true }
 提示用户运行 /crm-login
        │
        ▼ 用户运行 /crm-login
        │
        ▼
POST /web/user/login  (method: qrcode)
←─── { url: "https://oss.xxx/qr.png", qrCodeId: "uuid" }
        │
        ▼
插件返回图片 URL 到聊天界面
用户用 CRM App 扫码
        │
        ▼
轮询 POST /web/user/login  (method: scanCallback)
    每 2 秒 / 最长 170 秒
        │
        ▼ status=1 (COMPLETE)
saveToken(accessToken) → ~/.openclaw/crm-auth.json
        │
        ▼
后续所有工具调用自动携带 token ✓

Tools

| Tool 名称 | 说明 | 需要登录 | |--------------|---------------------------------|---------| | get_weather | 查询城市天气(mock 数据) | ✅ | | save_note | 保存笔记(标题、内容、标签) | ✅ | | list_notes | 列出笔记,支持按 tag 过滤 | ✅ | | ask_agent | 向「小钱钱」提问,获取销售支撑知识 | ❌ |

Commands(不经过 AI,直接执行)

| 命令 | 说明 | |----------------|-----------------------------------| | /crm-login | 启动扫码登录,返回二维码图片 URL | | /crm-logout | 清除本地存储的 Token | | /crm-status | 显示当前登录状态和 Token 有效期 | | /demo-status | 插件健康检查(无需登录) |


配置

~/.openclaw/openclaw.json 中添加:

{
  "plugins": {
    "enabled": true,
    "allow": ["demo-plugin"],
    "load": {
      "paths": ["/path/to/openclaw-demo-plugin"]
    },
    "entries": {
      "demo-plugin": {
        "enabled": true,
        "config": {
          "serverUrl": "https://crm.shouqianba.com",
          "defaultCity": "Beijing",
          "cozeOAuthClientId": "你的 OAuth App Client ID",
          "cozeOAuthPublicKeyId": "你的 Public Key ID",
          "cozeOAuthPrivateKey": "-----BEGIN PRIVATE KEY-----\\nMIIEv...\\n-----END PRIVATE KEY-----",
          "cozeBotId": "你的 Coze bot id",
          "cozeApiBase": "https://api.coze.cn",
          "cozeUserId": "openclaw-user"
        }
      }
    }
  }
}

serverUrl 为必填项,填写您公司 CRM 登录服务的地址。

如需使用智能体功能,还需配置 Coze OAuth(扣子 JWT 认证相关的密钥)。私钥中的换行符可以采用字面量 \n 进行转义,如示例所示,插件会自动处理。


Token 存储

Token 保存在 ~/.openclaw/crm-auth.json,格式如下:

{
  "accessToken": "eyJ...",
  "savedAt": "2026-03-30T10:00:00.000Z",
  "expiresAt": "2026-04-02T10:00:00.000Z"
}
  • 有效期与服务端 web_login_expired_time 对齐(默认 3 天)
  • 插件启动后首次工具调用会向服务器验证一次 token 有效性
  • Token 过期或服务端强制下线后,下次工具调用会自动引导重新登录

安装 & 类型检查

npm install
npm run typecheck

典型使用流程

用户:帮我查一下上海的天气

assistant(插件 Hook 拦截):
  🔒 您尚未登录 CRM 系统。
  请先运行 /crm-login 命令完成扫码认证,之后再重试您的请求。

用户:/crm-login

assistant:
  🔐 请扫描下方二维码完成登录
  📷 二维码图片:https://oss.example.com/qr/xxx.png
  请使用 CRM 手机 App 扫码确认,二维码有效期 3 分钟。
  扫码完成后系统将自动继续执行您的请求。

(用户扫码确认 → Token 自动保存)

用户:帮我查一下上海的天气

assistant(get_weather 工具):
  Weather in Shanghai:
    Temperature : 26°C
    Condition   : Cloudy
    Humidity    : 65%