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 🙏

© 2025 – Pkg Stats / Ryan Hefner

dai-bot

v0.1.9

Published

A TypeScript chatbot plugin for web applications

Readme

Dai Bot

一个轻量级的 TypeScript 聊天机器人插件,可以轻松集成到任何 Web 应用中。

特性

  • 🚀 轻量级,无依赖
  • 🎯 TypeScript 支持,完整的类型定义
  • 🎨 可自定义样式和配置
  • 📱 响应式设计,支持拖拽
  • 🔒 安全的 iframe 沙箱
  • 📦 支持 CommonJS、ESM 和 UMD 模块
  • 🔐 代码混淆和加密保护
  • 🛡️ 环境变量安全配置
  • 🚫 调试保护和反逆向工程

安装

npm install dai-bot

或者使用 yarn:

yarn add dai-bot

使用方法

基本用法

import DaiBot from "dai-bot";

// 创建机器人实例
const bot = new DaiBot({
  botButtonConfig: {
    position: "bottom-right",
    size: 60,
    backgroundColor: "#007bff",
    icon: "🤖",
  },
  iframeConfig: {
    url: "https://your-chatbot-url.com",
    width: 400,
    height: 600,
    position: "bottom-right",
  },
});

配置选项

BotButtonConfig

| 属性 | 类型 | 默认值 | 描述 | | ----------------- | -------- | ---------------- | ----------------------------------------------------------------- | | position | string | 'bottom-right' | 按钮位置 (top-left, top-right, bottom-left, bottom-right) | | size | number | 60 | 按钮大小(像素) | | backgroundColor | string | '#007bff' | 按钮背景色 | | icon | string | '🤖' | 按钮图标 |

IframeConfig

| 属性 | 类型 | 默认值 | 描述 | | ---------- | -------- | ---------------- | ------------- | | url | string | '' | iframe 源地址 | | width | number | 400 | iframe 宽度 | | height | number | 600 | iframe 高度 | | position | string | 'bottom-right' | iframe 位置 |

完整示例

<!DOCTYPE html>
<html>
  <head>
    <title>Dai Bot Demo</title>
  </head>
  <body>
    <h1>欢迎使用 Dai Bot</h1>

    <script type="module">
      import DaiBot from "./node_modules/dai-bot/dist/index.esm.js";

      const bot = new DaiBot({
        botButtonConfig: {
          position: "bottom-right",
          size: 70,
          backgroundColor: "#28a745",
          icon: "💬",
        },
        iframeConfig: {
          url: "https://example.com/chat",
          width: 450,
          height: 650,
          position: "bottom-right",
        },
      });

      // 获取机器人信息
      console.log(bot.getInfo());

      // 更新配置
      bot.updateConfig({
        botButtonConfig: {
          position: "bottom-left",
          size: 80,
          backgroundColor: "#dc3545",
          icon: "🤖",
        },
        iframeConfig: {
          url: "https://example.com/chat",
          width: 500,
          height: 700,
          position: "bottom-left",
        },
      });

      // 销毁机器人(在页面卸载时)
      window.addEventListener("beforeunload", () => {
        bot.destroy();
      });
    </script>
  </body>
</html>

API 参考

DaiBot 类

构造函数

constructor(config: DaiBotConfig)

方法

  • destroy(): 销毁机器人实例,移除 DOM 元素
  • updateConfig(config: DaiBotConfig): 更新机器人配置
  • getInfo(): 获取机器人当前状态和配置信息

类型定义

interface DaiBotConfig {
  botButtonConfig: BotButtonConfig;
  iframeConfig: IframeConfig;
}

interface BotButtonConfig {
  position: string;
  size: number;
  backgroundColor: string;
  icon: string;
}

interface IframeConfig {
  url: string;
  width: number;
  height: number;
  position: string;
}

开发

构建

# 开发构建
npm run build

# 生产构建(移除调试信息)
npm run build:prod

# 混淆构建(最大安全保护)
npm run build:obfuscated

开发模式

npm run dev:rollup

类型检查

npm run type-check

测试

npm test

发布

发布到 npm

# 发布最新版本
npm run publish:npm:latest

# 发布 beta 版本
npm run publish:npm:beta

安全特性

🔐 代码混淆

DaiBot 提供了多层代码保护机制:

  • 标识符混淆: 变量名和函数名被转换为十六进制
  • 字符串加密: 敏感字符串使用 XOR 加密和 Base64 编码
  • 控制流混淆: 代码执行流程被重新组织
  • 死代码注入: 增加虚假代码增加分析难度
  • 调试保护: 防止调试工具分析代码

🛡️ 环境变量保护

  • 支持通过环境变量配置敏感信息
  • 生产环境强制要求设置加密密钥
  • 浏览器和 Node.js 环境自适应

📦 构建版本

  • index.js - 原始版本(开发用)
  • index.min.js - 压缩版本(生产用)
  • index.obfuscated.js - 混淆版本(最大安全保护)

🔑 加密配置

# 设置环境变量
NODE_ENV=production
ENCRYPTION_KEY=your-32-char-secret-key
API_BASE_URL=https://your-api.com

许可证

MIT License

贡献

欢迎提交 Issue 和 Pull Request!

更新日志

1.0.0

  • 初始版本发布
  • 支持基本的聊天机器人功能
  • 可拖拽的机器人按钮
  • 可配置的 iframe 聊天窗口