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

yz-uniapp-ai-agent

v1.0.3

Published

微信小程序 UniApp AI 智能客服弹窗组件,支持对话、语音识别、图片上传、人工客服转接

Readme

yz-uniapp-ai-agent

微信小程序 UniApp AI 智能客服弹窗组件,支持智能对话、语音识别、图片上传、人工客服转接等功能。

安装

方式一:npm 安装(推荐)

npm install yz-uniapp-ai-agent --ignore-scripts=false

--ignore-scripts=false 确保 postinstall 脚本执行,自动将组件复制到 uni_modules/ 目录。如果未加此参数,安装后需手动执行:

cd node_modules/yz-uniapp-ai-agent && npm run setup

方式二:HBuilderX 插件市场安装

通过 HBuilderX 的插件市场一键安装到 uni_modules/ 目录。

前置依赖

快速开始

1. 全局注册配置

main.js 中注入全局配置:

import { AiAgentPlugin } from '@/uni_modules/yz-uniapp-ai-agent/index.js'

// Vue 3
const app = createSSRApp(App)
app.use(AiAgentPlugin, {
  baseUrl: 'https://your-ai-service.com',   // 必填:AI 服务基础地址
  getToken: () => uni.getStorageSync('token'), // 必填:获取认证 token
  getUserKey: () => uni.getStorageSync('userKey') // 必填:获取用户标识
})
app.mount('#app')

2. 在页面中使用

组件通过 easycom 自动注册为 <ai-agent>,无需手动 import:

<template>
  <view>
    <button @tap="showAgent = true">打开AI客服</button>
    <ai-agent :show="showAgent" @close="showAgent = false" />
  </view>
</template>

<script>
export default {
  data() {
    return {
      showAgent: false
    }
  }
}
</script>

配置项

Plugin 全局配置

通过 app.use(AiAgentPlugin, options) 注入:

| 参数 | 类型 | 必填 | 说明 | |------|------|:----:|------| | baseUrl | String | 是 | AI 服务基础地址,WebSocket 地址自动从 http 转换为 ws | | appId | String | 否 | 微信小程序 appId,不填则自动获取 | | getToken | Function | 是 | 获取认证 token 的函数,返回 string | | getUserKey | Function | 是 | 获取用户标识的函数,返回 string | | defaultAvatar | String | 否 | AI 默认头像地址 | | copyrightName | String | 否 | 版权名称 |

Props

Props 传入的配置优先级高于 Plugin 全局配置。

| Prop | 类型 | 必填 | 默认值 | 说明 | |------|------|:----:|--------|------| | show | Boolean | 是 | false | 控制弹窗显示/隐藏 | | baseUrl | String | 否 | - | AI 服务地址,覆盖全局配置 | | appId | String | 否 | - | 小程序 appId,覆盖全局配置 | | getToken | Function | 否 | - | 获取 token 函数,覆盖全局配置 | | getUserKey | Function | 否 | - | 获取用户标识函数,覆盖全局配置 | | defaultAvatar | String | 否 | - | AI 默认头像 | | copyrightName | String | 否 | - | 版权名称 |

Events

| 事件 | 参数 | 说明 | |------|------|------| | close | - | 弹窗关闭时触发 | | open | - | 弹窗打开时触发 |

功能特性

  • 智能对话 — WebSocket 实时流式对话,支持 Markdown 渲染
  • 语音识别 — 按住说话,自动录音转文字发送
  • 图片上传 — 支持拍照/相册选择,图片消息发送
  • 人工客服 — 自动转接微信客服,工作时间判断
  • 表情面板 — 内置常用表情选择
  • 常见问题 — 自动展示 FAQ 快捷选项
  • 消息状态 — 已读/未读状态显示,消息滑入动画

组件结构

uni_modules/yz-uniapp-ai-agent/
├── package.json                    # 包配置
├── index.js                        # AiAgentPlugin 入口
├── changelog.md                    # 更新日志
├── common/
│   ├── api.js                      # API 接口封装
│   └── request.js                  # 基于 uni.request 的请求模块
├── components/
│   └── ai-agent/
│       └── ai-agent.vue            # 核心组件
└── scripts/
    └── postinstall.js              # npm 安装后自动复制脚本

注意事项

  • 本组件仅支持微信小程序
  • baseUrl 需配置为 AI 服务地址,WebSocket 地址自动从 http 转换为 ws
  • getTokengetUserKey 函数在组件内部被调用,需确保返回有效的认证信息
  • 组件依赖 uview-plusup-popup,请确保项目已安装
  • npm 安装时需加 --ignore-scripts=false 参数,否则需手动执行 npm run setup

更新日志

changelog.md