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

@hd-front-end/ai-assistant-sdk-vue2

v0.0.2

Published

AI Assistant SDK for Vue 2 with TypeScript

Readme

@hd-front-end/ai-assistant-sdk-vue2

AI助手SDK的Vue 2版本,提供完整的AI对话、数据可视化和页面交互能力。

特性

  • 双重API导出:同时支持Composable API和Mixin API
  • TypeScript支持:完整的类型定义
  • 声明式命令系统:通过$_hdAiCommands选项优雅地注册AI命令
  • 样式隔离:BEM命名规范,零污染
  • Vue版本兼容:支持Vue 2.6/2.7
  • 渐进增强:为Vue 3迁移铺路

安装

pnpm add @hd-front-end/ai-assistant-sdk-vue2

Vue 2.6项目需要额外安装

pnpm add @vue/composition-api

Vue 2.7项目无需额外依赖

Vue 2.7已内置Composition API。

使用方式

方式1: Composable API(推荐 - 现代Vue2项目)

适用于TypeScript 4.0+、vue-class-component v7+的项目。

// main.ts - 注册插件
import Vue from 'vue';
import { AIAssistantPlugin } from '@hd-front-end/ai-assistant-sdk-vue2';

Vue.use(AIAssistantPlugin, {
  apiUrl: 'http://localhost:8080/api/chat',
  botId: 'your-bot-id'
});

// 组件中使用Composable API
import { useAIChat } from '@hd-front-end/ai-assistant-sdk-vue2/composable';

export default {
  setup() {
    const { chatList, isLoading, sendMessage } = useAIChat();
    
    return {
      chatList,
      isLoading,
      sendMessage
    };
  }
};

方式2: Mixin API(兼容 - 遗留Vue2项目)

适用于TypeScript 3.0+、vue-class-component v6的项目。

// main.ts - 注册插件
import Vue from 'vue';
import { AIAssistantPlugin } from '@hd-front-end/ai-assistant-sdk-vue2';

Vue.use(AIAssistantPlugin, {
  apiUrl: 'http://localhost:8080/api/chat',
  botId: 'your-bot-id'
});

// 组件中使用Mixin API
import { AiChatMixin } from '@hd-front-end/ai-assistant-sdk-vue2/mixin';

export default {
  mixins: [AiChatMixin],
  
  // 声明式注册AI命令
  $_hdAiCommands: {
    'navigation.nextPage': function(params) {
      this.$router.push({ name: 'nextPage' });
    },
    'data.export': function(params) {
      this.exportData(params.format);
    }
  },
  
  methods: {
    async handleSend() {
      await this.$_hdAi_sendMessage('你好');
    }
  }
};

声明式命令系统

通过$_hdAiCommands选项优雅地注册AI命令:

export default {
  mixins: [AiChatMixin],
  
  $_hdAiCommands: {
    // 命令会自动绑定this到组件实例
    'navigation.go': function(params: { page: string }) {
      this.$router.push({ name: params.page });
    },
    
    'data.refresh': function() {
      this.loadData();
    }
  },
  
  methods: {
    loadData() {
      // 业务逻辑
    }
  }
};

优势

  • ✅ 声明式配置,符合Vue开发者习惯
  • ✅ 自动生命周期管理(注册和清理)
  • ✅ this自动绑定到组件实例
  • ✅ 支持多个Mixin的命令合并
  • ✅ TypeScript类型安全

样式定制

方式1: CSS变量(运行时)

:root {
  --hd-ai-primary-color: #1890ff;
  --hd-ai-border-radius: 4px;
  --hd-ai-spacing-unit: 8px;
}

方式2: SCSS变量(编译时)

// 在项目的全局SCSS文件中
$hd-ai-primary-color: $--color-primary; // 映射到Element UI主色

@import "~@hd-front-end/ai-assistant-sdk-vue2/src/assets/styles/variables";

API文档

详细API文档请参考:API Documentation

示例项目

许可证

MIT