Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More β†’
Socket
Book a DemoInstallSign in
Socket

@aivue/chatbot

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aivue/chatbot

AI-powered chat components for Vue.js

latest
Source
npmnpm
Version
2.4.0
Version published
Maintainers
1
Created
Source

@aivue/chatbot

AI Chatbot

πŸš€ Next-Generation AI Chat Components for Vue.js

Enterprise-grade conversational AI with advanced features including database storage, voice integration, multi-model support, analytics, and collaborative capabilities. Built for production applications with backward compatibility.

npm version npm downloads NPM Downloads MIT License codecov Netlify Status

🎯 What's New in v2.3.0

πŸ”’ Proxy Support & Internationalization

Major architectural improvements with enhanced security and global accessibility:

  • πŸ”’ Proxy Configuration: Secure API requests through proxy servers
  • 🌍 Language Support: Full internationalization with customizable texts (5 languages)
  • πŸ›‘οΈ Enhanced Security: Better API key protection and request routing
  • 🧹 Simplified Architecture: Consolidated all features into main AiChatWindow component
  • πŸ“¦ Smaller Bundle: ~25% size reduction by removing redundant code
  • 🎯 Single Component: No more confusion between regular and enhanced versions

🎯 What's New in v2.0.0

πŸš€ Major Release: Enhanced AI Chatbot

This is a major release that introduces comprehensive advanced features while maintaining 100% backward compatibility.

graph TD
    A[Basic Chat v1.x] --> B[Enhanced Chat v2.0]
    B --> C[πŸ—„οΈ Database Storage]
    B --> D[🎀 Voice Integration]
    B --> E[πŸ€– Multi-Model AI]
    B --> F[πŸ“Š Analytics & Insights]
    B --> G[🧡 Conversation Threading]
    B --> H[πŸ“Ž File Attachments]
    B --> I[πŸ‘₯ Collaborative Features]
    B --> J[πŸ”’ Privacy & Security]

✨ New Enterprise Features

FeatureDescriptionStatus
πŸ—„οΈ Database StoragelocalStorage, Supabase, Firebase, MongoDB, PostgreSQLβœ… Available
🎀 Voice IntegrationSpeech-to-text input, text-to-speech responsesβœ… Available
πŸ€– Multi-Model AIIntelligent switching between AI providersβœ… Available
πŸ“Š Analytics DashboardUsage metrics, conversation insightsβœ… Available
🧡 Conversation ThreadingOrganize chats by topicsβœ… Available
πŸ“Ž Advanced File UploadPDFs, documents, images, audioβœ… Available
πŸ‘₯ Collaborative FeaturesShared conversations, team workspacesβœ… Available
πŸ”’ Privacy & SecurityEnd-to-end encryption, local storageβœ… Available
πŸ”’ Proxy SupportSecure API requests through proxy serversβœ… New in v2.3.0
🌍 Internationalization5 languages with customizable textsβœ… New in v2.3.0
🧹 Simplified ArchitectureSingle component for all featuresβœ… New in v2.3.0

πŸ“Ί Live Demo β€’ πŸ“š Documentation β€’ οΏ½ Report Bug

✨ Overview

@aivue/chatbot provides ready-to-use chat components for Vue.js applications, powered by AI. Create engaging conversational interfaces with minimal setup, supporting multiple AI providers.

✨ Core Features

🎯 Essential Features

  • πŸ’¬ Ready-to-use Chat UI: Beautiful, responsive chat interface with minimal setup
  • πŸ”„ Real-time Streaming: See AI responses as they're generated, token by token
  • πŸ“± Mobile-friendly: Responsive design works on all devices and screen sizes
  • 🎨 Customizable: Easily style to match your application with CSS variables
  • 🧠 Multiple AI Providers: Works with OpenAI, Claude, Gemini, HuggingFace, and more
  • πŸ“ Markdown Support: Rich text formatting in messages with code highlighting
  • πŸ”§ Fully Typed: Complete TypeScript support with comprehensive type definitions
  • πŸ”Œ Vue Plugin: Easy global registration of components with Vue plugin
  • πŸš€ Composition API: First-class support for Vue 3 Composition API

πŸš€ Enhanced Features (v2.0+)

πŸ—„οΈ Database Storage & Persistence

  • Multiple Storage Providers: localStorage, Supabase, Firebase, MongoDB, PostgreSQL
  • Auto-Save Conversations: Automatic conversation persistence with configurable intervals
  • Search & Organization: Find conversations by content, date, or custom tags
  • Conversation Threading: Organize chats by topics with automatic categorization
  • Data Export: Export conversations in JSON, CSV, or PDF formats
  • Encryption Support: End-to-end encryption for sensitive conversations

🎀 Voice Integration

  • Speech-to-Text: Click microphone to speak your message (50+ languages)
  • Text-to-Speech: AI responses can be read aloud with natural voices
  • Voice Commands: Special voice-activated commands and shortcuts
  • Multi-Language Support: Automatic language detection and switching

πŸ€– Multi-Model AI Support

  • Provider Switching: OpenAI, Anthropic, Ollama, Google Gemini, HuggingFace
  • Auto-Selection: Intelligent model selection based on content complexity
  • Load Balancing: Distribute requests across multiple models for reliability
  • Performance Optimization: Track and optimize model performance metrics

πŸ“Š Analytics & Insights

  • Usage Metrics: Track messages, response times, user engagement
  • Sentiment Analysis: Analyze conversation sentiment and emotional tone
  • Performance Monitoring: Monitor AI model performance and response quality
  • Custom Reports: Generate detailed reports with export capabilities

🧡 Advanced Chat Features

  • Message Reactions: React to messages with emojis and custom reactions
  • File Attachments: Upload and analyze PDFs, documents, images, audio files
  • Quick Actions: Pre-defined prompts and custom workflow automation
  • Typing Indicators: Show when AI is thinking or generating responses
  • Message Threading: Reply to specific messages with threaded conversations

πŸ‘₯ Collaborative Features

  • Shared Conversations: Share chats with team members or collaborators
  • Real-time Collaboration: Multiple users in the same conversation
  • Team Workspaces: Organize conversations by teams or projects
  • Permission Management: Fine-grained access control and permissions

πŸ”’ Privacy & Security

  • Local Storage Options: Keep all data on the user's device
  • End-to-End Encryption: Secure sensitive conversations with encryption
  • Data Portability: Export and import data in standard formats
  • Privacy Controls: Granular privacy settings and data retention policies

πŸ“¦ Installation

npm

npm install @aivue/chatbot @aivue/core

yarn

yarn add @aivue/chatbot @aivue/core

pnpm

pnpm add @aivue/chatbot @aivue/core

Don't forget to import the CSS:

// Import the CSS from the chatbot package
import '@aivue/chatbot/style.css'

πŸ”„ Vue Compatibility

  • βœ… Vue 2: Compatible with Vue 2.6.0 and higher
  • βœ… Vue 3: Compatible with all Vue 3.x versions

The package automatically detects which version of Vue you're using and provides the appropriate compatibility layer. This means you can use the same package regardless of whether your project is using Vue 2 or Vue 3.

πŸš€ Quick Start

1. Set up the AI Client

First, create an AI client using @aivue/core:

// ai-client.js
import { AIClient } from '@aivue/core';

export const aiClient = new AIClient({
  provider: 'openai', // or 'claude', 'gemini', 'huggingface', 'ollama', 'deepseek'
  apiKey: import.meta.env.VITE_OPENAI_API_KEY, // Use environment variables for API keys
  model: 'gpt-4o' // Specify the model to use
});

2. Use the AiChatWindow Component

Import and use the component in your Vue application:

<template>
  <div class="chat-container">
    <AiChatWindow
      :client="aiClient"
      title="AI Assistant"
      placeholder="Ask me anything..."
      :show-avatars="true"
      theme="light"
    />
  </div>
</template>

<script setup>
import { AiChatWindow } from '@aivue/chatbot';
import '@aivue/chatbot/style.css'; // Import the CSS
import { aiClient } from './ai-client.js';
</script>

<style>
.chat-container {
  height: 600px;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}
</style>

3. That's it!

You now have a fully functional AI chat interface in your Vue application. The component handles all the complexity of managing the chat state, sending messages to the AI provider, and displaying the responses.

See the live demo β†’

Register Components Globally (Optional)

If you prefer to register components globally, you can use the provided Vue plugin:

// main.js
import { createApp } from 'vue';
import App from './App.vue';
import { AiChatPlugin } from '@aivue/chatbot';

const app = createApp(App);
app.use(AiChatPlugin); // Register all components globally
app.mount('#app');

Or register individual components manually:

// main.js
import { createApp } from 'vue';
import App from './App.vue';
import { AiChatWindow } from '@aivue/chatbot';

const app = createApp(App);
app.component('AiChatWindow', AiChatWindow); // Register with PascalCase
app.mount('#app');

Then use it in your templates with either PascalCase or kebab-case:

<!-- Both of these work -->
<AiChatWindow :client="aiClient" />
<ai-chat-window :client="aiClient" />

Using the Chat Engine Composable

The useChatEngine composable provides a simple way to integrate AI chat functionality into any Vue component:

Using with an AIClient instance

<script setup>
import { ref } from 'vue';
import { useChatEngine } from '@aivue/chatbot';
import { aiClient } from './ai-client.js';

const {
  messages,
  isLoading,
  error,
  sendMessage,
  clearMessages
} = useChatEngine({
  client: aiClient,
  initialMessages: [
    { role: 'assistant', content: 'Hello! How can I help you today?' }
  ],
  systemPrompt: 'You are a helpful assistant.',
  streaming: true,
  persistenceKey: 'my-chat-history'
});
</script>

Direct provider configuration (new)

You can now configure the provider directly without creating an AIClient instance:

<script setup>
import { ref } from 'vue';
import { useChatEngine } from '@aivue/chatbot';

const {
  messages,
  isLoading,
  error,
  sendMessage,
  clearMessages,
  resetError,
  updateConfig
} = useChatEngine({
  // Provider configuration
  provider: 'openai',
  apiKey: import.meta.env.VITE_OPENAI_API_KEY,
  model: 'gpt-3.5-turbo',

  // API security
  useProxy: true,
  proxyUrl: '/api/chat',

  // Chat behavior
  initialMessages: [
    { role: 'assistant', content: 'Hello! How can I help you today?' }
  ],
  systemPrompt: 'You are a helpful assistant.',
  streaming: true,
  persistenceKey: 'my-chat-history',

  // Callbacks
  onError: (err) => console.error('Chat error:', err),
  onMessageSent: (msg) => console.log('Message sent:', msg),
  onResponseReceived: (msg) => console.log('Response received:', msg)
});

// You can dynamically update the configuration
function switchToGpt4() {
  updateConfig({ model: 'gpt-4o' });
}

const userInput = ref('');

function handleSend() {
  if (userInput.value.trim()) {
    sendMessage(userInput.value);
    userInput.value = '';
  }
}
</script>

<template>
  <div class="chat-container">
    <div class="messages">
      <div v-for="(message, index) in messages" :key="message.id || index" class="message">
        <strong>{{ message.role }}:</strong> {{ message.content }}
      </div>
    </div>

    <div class="input-area">
      <input v-model="userInput" @keyup.enter="handleSend" :disabled="isLoading" />
      <button @click="handleSend" :disabled="isLoading">Send</button>
      <button @click="clearMessages">Clear</button>
      <button @click="switchToGpt4">Switch to GPT-4</button>
    </div>

    <div v-if="error" class="error">{{ error.message }}</div>
  </div>
</template>

Note that all values returned from useChatEngine are Vue reactive refs, so you can use them directly in your templates without .value.

Customizing the Chat Window

Using with AIClient

<template>
  <AiChatWindow
    :client="aiClient"
    title="AI Assistant"
    placeholder="Ask me anything about Vue..."
    :initial-messages="initialMessages"
    system-prompt="You are a Vue.js expert who provides clear, concise answers."
    :streaming="true"
    :show-avatars="true"
    :user-avatar="userAvatar"
    :assistant-avatar="assistantAvatar"
    theme="dark"
    height="700px"
    width="100%"
    max-width="800px"
    :show-timestamps="true"
    :show-copy-button="true"
    persistence-key="vue-chat-history"
    @message-sent="handleMessageSent"
    @response-received="handleResponseReceived"
    @error="handleError"
  />
</template>

<script setup>
import { ref } from 'vue';
import { AiChatWindow } from '@aivue/chatbot';
import { aiClient } from './ai-client.js';

const userAvatar = ref('/path/to/user-avatar.png');
const assistantAvatar = ref('/path/to/assistant-avatar.png');
const initialMessages = ref([
  { role: 'assistant', content: 'Hello! I can help you with Vue.js questions.' }
]);

function handleMessageSent(event) {
  console.log('Message sent:', event.message);
}

function handleResponseReceived(event) {
  console.log('Response received:', event.message);
}

function handleError(event) {
  console.error('Error:', event.error);
}
</script>

Direct Provider Configuration (New)

You can now configure the provider directly without creating an AIClient instance:

<template>
  <AiChatWindow
    provider="openai"
    :api-key="apiKey"
    model="gpt-3.5-turbo"
    :use-proxy="true"
    proxy-url="/api/chat"
    title="AI Assistant"
    placeholder="Ask me anything about Vue..."
    :initial-messages="initialMessages"
    system-prompt="You are a Vue.js expert who provides clear, concise answers."
    :streaming="true"
    theme="dark"
    :show-timestamps="true"
    @message-sent="handleMessageSent"
    @response-received="handleResponseReceived"
    @error="handleError"
  />
</template>

<script setup>
import { ref } from 'vue';
import { AiChatWindow } from '@aivue/chatbot';

const apiKey = import.meta.env.VITE_OPENAI_API_KEY;
const initialMessages = ref([
  { role: 'assistant', content: 'Hello! I can help you with Vue.js questions.' }
]);

function handleMessageSent(event) {
  console.log('Message sent:', event.message);
}

function handleResponseReceived(event) {
  console.log('Response received:', event.message);
}

function handleError(event) {
  console.error('Error:', event.error);
}
</script>

Demo Mode (No API Key Required)

You can use the chatbot in demo mode without an API key:

<template>
  <AiChatWindow
    provider="openai"
    :demoMode="true"
    :demoResponses="{
      'hello': 'Hello! I\'m a demo AI assistant.',
      'help': 'I can help you with various tasks. Just ask me a question!',
      'features': 'This chatbot supports markdown, code highlighting, and more!'
    }"
  />
</template>

<script setup>
import { AiChatWindow } from '@aivue/chatbot';
</script>

This is useful for:

  • Showcasing the chatbot functionality without requiring an API key
  • Creating demos and examples
  • Testing the UI without making actual API calls
  • Fallback when API keys are not available

πŸ”’ Proxy Support & Security (New in v2.3.0)

The AiChatWindow component now supports proxy configuration for secure API requests, allowing you to route AI API calls through your own server for enhanced security and control.

Basic Proxy Configuration

<template>
  <AiChatWindow
    provider="openai"
    :api-key="apiKey"
    model="gpt-3.5-turbo"
    :use-proxy="true"
    proxy-url="/api/chat"
    title="Secure AI Assistant"
    placeholder="Your messages are securely routed..."
  />
</template>

<script setup>
import { AiChatWindow } from '@aivue/chatbot';

const apiKey = import.meta.env.VITE_OPENAI_API_KEY;
</script>

Advanced Proxy Setup

<template>
  <AiChatWindow
    provider="openai"
    :api-key="apiKey"
    model="gpt-4"
    :use-proxy="true"
    proxy-url="https://your-api-gateway.com/ai/chat"
    title="Enterprise AI Chat"
  />
</template>

Benefits of Proxy Configuration

  • πŸ›‘οΈ Enhanced Security: Keep API keys on your server, not in client code
  • πŸ“Š Request Monitoring: Log and monitor all AI API requests
  • πŸ”„ Load Balancing: Distribute requests across multiple AI providers
  • πŸ’° Cost Control: Implement usage limits and billing controls
  • πŸ”’ Access Control: Add authentication and authorization layers

🌍 Internationalization & Language Support (New in v2.3.0)

The AiChatWindow component now supports full internationalization with customizable language texts, making it easy to create multilingual chat interfaces.

Basic Language Configuration

<template>
  <AiChatWindow
    provider="openai"
    :api-key="apiKey"
    language="es"
    :texts="{
      title: 'Asistente IA',
      placeholder: 'Escribe tu mensaje...',
      sendButton: 'Enviar',
      copyButton: 'Copiar',
      clearButton: 'Limpiar Chat',
      attachButton: 'Adjuntar archivo',
      voiceButton: 'Entrada de voz',
      typing: 'Pensando...',
      error: 'OcurriΓ³ un error. IntΓ©ntalo de nuevo.'
    }"
  />
</template>

<script setup>
import { AiChatWindow } from '@aivue/chatbot';

const apiKey = import.meta.env.VITE_OPENAI_API_KEY;
</script>

Dynamic Language Switching

<template>
  <div>
    <select v-model="currentLanguage" @change="updateLanguage">
      <option value="en">English</option>
      <option value="es">EspaΓ±ol</option>
      <option value="fr">FranΓ§ais</option>
      <option value="de">Deutsch</option>
      <option value="it">Italiano</option>
    </select>

    <AiChatWindow
      provider="openai"
      :api-key="apiKey"
      :language="currentLanguage"
      :texts="languageTexts[currentLanguage]"
    />
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { AiChatWindow } from '@aivue/chatbot';

const apiKey = import.meta.env.VITE_OPENAI_API_KEY;
const currentLanguage = ref('en');

const languageTexts = {
  en: {
    title: 'AI Assistant',
    placeholder: 'Type your message...',
    sendButton: 'Send',
    copyButton: 'Copy',
    clearButton: 'Clear Chat',
    attachButton: 'Attach file',
    voiceButton: 'Voice input',
    typing: 'Thinking...',
    error: 'An error occurred. Please try again.'
  },
  es: {
    title: 'Asistente IA',
    placeholder: 'Escribe tu mensaje...',
    sendButton: 'Enviar',
    copyButton: 'Copiar',
    clearButton: 'Limpiar Chat',
    attachButton: 'Adjuntar archivo',
    voiceButton: 'Entrada de voz',
    typing: 'Pensando...',
    error: 'OcurriΓ³ un error. IntΓ©ntalo de nuevo.'
  },
  // ... other languages
};

function updateLanguage() {
  // Language texts are automatically updated via reactive binding
  console.log('Language changed to:', currentLanguage.value);
}
</script>

Supported Languages

The component includes built-in support for:

LanguageCodeStatus
Englishenβœ… Built-in
Spanishesβœ… Built-in
Frenchfrβœ… Built-in
Germandeβœ… Built-in
Italianitβœ… Built-in
PortugueseptπŸ”„ Coming Soon
ChinesezhπŸ”„ Coming Soon
JapanesejaπŸ”„ Coming Soon

🧹 Simplified Architecture (New in v2.3.0)

We've consolidated all advanced features into the main AiChatWindow component, removing the need for a separate enhanced version. This brings several benefits:

Benefits of the New Architecture

  • 🎯 Single Component: No confusion about which component to use
  • πŸ“¦ Smaller Bundle: ~25% reduction in package size
  • πŸ”§ Easier Maintenance: One component to maintain and update
  • πŸ“š Simpler Documentation: Clear, focused API
  • ⚑ Better Performance: Optimized single component
  • 🎨 Consistent Experience: All features in one place

Migration Guide

If you were using AiChatWindowEnhanced, simply replace it with AiChatWindow:

<!-- Before (v2.2.0 and earlier) -->
<AiChatWindowEnhanced
  provider="openai"
  :api-key="apiKey"
  :file-upload-enabled="true"
  :voice="{ speechToText: true }"
/>

<!-- After (v2.3.0+) -->
<AiChatWindow
  provider="openai"
  :api-key="apiKey"
  :use-proxy="true"
  language="es"
  :texts="{ placeholder: 'Escribe un mensaje...' }"
/>

All features are now available in the main component with the same API!

Customizable Text Properties

You can customize any of these interface texts:

interface LanguageTexts {
  // Header texts
  title?: string;
  modelIndicator?: string;

  // Input area texts
  placeholder?: string;
  sendButton?: string;
  voiceButton?: string;
  fileButton?: string;

  // Message texts
  copyButton?: string;
  retryButton?: string;
  deleteButton?: string;
  editButton?: string;

  // Settings texts
  settingsTitle?: string;
  conversationsTitle?: string;
  analyticsTitle?: string;

  // Status texts
  typing?: string;
  connecting?: string;
  error?: string;
  noMessages?: string;

  // File upload texts
  dragDropText?: string;
  fileUploadError?: string;
  fileSizeError?: string;
  fileTypeError?: string;

  // Voice texts
  listeningText?: string;
  speakingText?: string;
  voiceError?: string;

  // Analytics texts
  totalMessages?: string;
  averageResponseTime?: string;
  userSatisfaction?: string;

  // Conversation management
  newConversation?: string;
  saveConversation?: string;
  loadConversation?: string;
  deleteConversation?: string;
  searchConversations?: string;
}

πŸ—„οΈ Database Storage & Persistence

The enhanced chatbot supports multiple storage providers for persistent conversations, search capabilities, and conversation management.

Storage Providers

graph LR
    A[Chat Engine] --> B[Storage Provider]
    B --> C[localStorage]
    B --> D[Supabase]
    B --> E[Firebase]
    B --> F[MongoDB]
    B --> G[PostgreSQL]

    C --> H[Browser Storage]
    D --> I[Real-time DB]
    E --> J[Google Cloud]
    F --> K[Document DB]
    G --> L[SQL Database]

localStorage (Browser Storage)

Perfect for client-side applications with privacy-focused storage:

<template>
  <AiChatWindow
    provider="openai"
    :api-key="apiKey"
    :storage="{
      provider: 'localStorage',
      userId: 'user-123',
      autoSave: true,
      encryption: true
    }"
    @conversation-saved="handleConversationSaved"
  />
</template>

<script setup>
import { AiChatWindow } from '@aivue/chatbot';

const apiKey = import.meta.env.VITE_OPENAI_API_KEY;

function handleConversationSaved(conversationId) {
  console.log('Conversation saved:', conversationId);
}
</script>

Supabase (Real-time Database)

For real-time collaboration and cloud storage:

<template>
  <AiChatWindow
    provider="openai"
    :api-key="apiKey"
    :storage="{
      provider: 'supabase',
      connectionString: supabaseUrl,
      apiKey: supabaseKey,
      userId: user.id,
      autoSave: true,
      realTimeSync: true
    }"
    :user="{
      id: user.id,
      name: user.name,
      avatar: user.avatar
    }"
  />
</template>

<script setup>
import { AiChatWindow } from '@aivue/chatbot';

const apiKey = import.meta.env.VITE_OPENAI_API_KEY;
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
const supabaseKey = import.meta.env.VITE_SUPABASE_ANON_KEY;

const user = {
  id: 'user-123',
  name: 'John Doe',
  avatar: 'https://example.com/avatar.jpg'
};
</script>

Firebase (Google Cloud)

For Google ecosystem integration:

<template>
  <AiChatWindow
    provider="openai"
    :api-key="apiKey"
    :storage="{
      provider: 'firebase',
      projectId: firebaseProjectId,
      apiKey: firebaseApiKey,
      userId: user.id,
      autoSave: true,
      offlineSupport: true
    }"
  />
</template>

<script setup>
import { AiChatWindow } from '@aivue/chatbot';

const apiKey = import.meta.env.VITE_OPENAI_API_KEY;
const firebaseProjectId = import.meta.env.VITE_FIREBASE_PROJECT_ID;
const firebaseApiKey = import.meta.env.VITE_FIREBASE_API_KEY;

const user = {
  id: 'user-123',
  name: 'John Doe'
};
</script>

MongoDB (Document Database)

For flexible document-based storage:

<template>
  <AiChatWindow
    provider="openai"
    :api-key="apiKey"
    :storage="{
      provider: 'mongodb',
      connectionString: mongoConnectionString,
      database: 'chatbot',
      collection: 'conversations',
      userId: user.id,
      autoSave: true
    }"
  />
</template>

<script setup>
import { AiChatWindow } from '@aivue/chatbot';

const apiKey = import.meta.env.VITE_OPENAI_API_KEY;
const mongoConnectionString = import.meta.env.VITE_MONGODB_CONNECTION_STRING;

const user = {
  id: 'user-123',
  name: 'John Doe'
};
</script>

Storage Methods with useChatEngine

Access advanced storage methods using the chat engine composable:

<script setup>
import { useChatEngine } from '@aivue/chatbot';

const {
  messages,
  isLoading,
  sendMessage,
  // Storage methods
  saveConversation,
  loadConversation,
  searchConversations,
  deleteConversation,
  getConversationList,
  exportConversation
} = useChatEngine({
  provider: 'openai',
  apiKey: import.meta.env.VITE_OPENAI_API_KEY,
  storage: {
    provider: 'localStorage',
    userId: 'user-123',
    autoSave: true
  }
});

// Save current conversation
async function saveCurrentChat() {
  const conversationId = await saveConversation('My Important Chat');
  console.log('Saved conversation:', conversationId);
}

// Load a specific conversation
async function loadChat(conversationId) {
  await loadConversation(conversationId);
}

// Search conversations
async function searchChats(query) {
  const results = await searchConversations(query);
  console.log('Search results:', results);
}

// Get all conversations
async function getAllChats() {
  const conversations = await getConversationList();
  console.log('All conversations:', conversations);
}

// Export conversation
async function exportChat(conversationId, format = 'json') {
  const exportData = await exportConversation(conversationId, format);
  // Download or process the exported data
}

// Delete conversation
async function deleteChat(conversationId) {
  await deleteConversation(conversationId);
}
</script>

🎀 Voice Integration

Add speech-to-text input and text-to-speech responses to your chatbot for a more natural conversation experience.

Basic Voice Setup

<template>
  <AiChatWindow
    provider="openai"
    :api-key="apiKey"
    :voice="{
      speechToText: true,
      textToSpeech: true,
      language: 'en-US',
      autoSpeak: false
    }"
    @voice-started="handleVoiceStarted"
    @voice-ended="handleVoiceEnded"
    @speech-recognized="handleSpeechRecognized"
  />
</template>

<script setup>
import { AiChatWindow } from '@aivue/chatbot';

const apiKey = import.meta.env.VITE_OPENAI_API_KEY;

function handleVoiceStarted() {
  console.log('Voice recording started');
}

function handleVoiceEnded() {
  console.log('Voice recording ended');
}

function handleSpeechRecognized(text) {
  console.log('Speech recognized:', text);
}
</script>

Advanced Voice Configuration

<template>
  <AiChatWindow
    provider="openai"
    :api-key="apiKey"
    :voice="{
      speechToText: true,
      textToSpeech: true,
      language: 'en-US',
      autoSpeak: true,
      voiceCommands: true,
      speechProvider: 'browser', // 'browser' or 'openai-whisper'
      ttsProvider: 'browser', // 'browser' or 'openai-tts'
      voice: 'alloy', // OpenAI TTS voice
      speed: 1.0,
      pitch: 1.0
    }"
  />
</template>

Voice Methods with useChatEngine

<script setup>
import { useChatEngine } from '@aivue/chatbot';

const {
  messages,
  sendMessage,
  // Voice methods
  startListening,
  stopListening,
  speak,
  stopSpeaking,
  isListening,
  isSpeaking
} = useChatEngine({
  provider: 'openai',
  apiKey: import.meta.env.VITE_OPENAI_API_KEY,
  voice: {
    speechToText: true,
    textToSpeech: true,
    language: 'en-US'
  }
});

// Manual voice control
async function toggleListening() {
  if (isListening.value) {
    stopListening();
  } else {
    await startListening();
  }
}

// Speak custom text
async function speakText(text) {
  await speak(text);
}

// Stop current speech
function stopCurrentSpeech() {
  stopSpeaking();
}
</script>

Supported Languages

The voice integration supports 50+ languages:

LanguageCodeSpeech-to-TextText-to-Speech
English (US)en-USβœ…βœ…
English (UK)en-GBβœ…βœ…
Spanishes-ESβœ…βœ…
Frenchfr-FRβœ…βœ…
Germande-DEβœ…βœ…
Italianit-ITβœ…βœ…
Portuguesept-BRβœ…βœ…
Russianru-RUβœ…βœ…
Japaneseja-JPβœ…βœ…
Koreanko-KRβœ…βœ…
Chinese (Simplified)zh-CNβœ…βœ…
Chinese (Traditional)zh-TWβœ…βœ…

πŸ€– Multi-Model AI Support

Intelligently switch between different AI providers for optimal performance and cost efficiency.

Basic Multi-Model Setup

<template>
  <AiChatWindow
    provider="openai"
    :api-key="apiKey"
    :multi-model="{
      enabled: true,
      models: [
        {
          name: 'GPT-4',
          provider: 'openai',
          model: 'gpt-4o',
          specialty: 'general',
          apiKey: openaiKey
        },
        {
          name: 'Claude',
          provider: 'anthropic',
          model: 'claude-3-sonnet-20240229',
          specialty: 'analysis',
          apiKey: claudeKey
        },
        {
          name: 'Llama',
          provider: 'ollama',
          model: 'llama3.2',
          specialty: 'coding',
          baseUrl: 'http://localhost:11434'
        }
      ],
      autoSwitch: true,
      loadBalancing: true
    }"
    @model-switched="handleModelSwitch"
  />
</template>

<script setup>
import { AiChatWindow } from '@aivue/chatbot';

const openaiKey = import.meta.env.VITE_OPENAI_API_KEY;
const claudeKey = import.meta.env.VITE_ANTHROPIC_API_KEY;

function handleModelSwitch(modelInfo) {
  console.log('Switched to model:', modelInfo);
}
</script>

Model Selection Logic

graph TD
    A[User Message] --> B{Content Analysis}
    B -->|Code/Technical| C[Llama 3.2]
    B -->|Analysis/Research| D[Claude 3]
    B -->|General/Creative| E[GPT-4]
    B -->|Simple/Fast| F[GPT-3.5]

    C --> G[Performance Tracking]
    D --> G
    E --> G
    F --> G

    G --> H[Model Optimization]
    H --> I[Future Selections]

Multi-Model Methods

<script setup>
import { useChatEngine } from '@aivue/chatbot';

const {
  messages,
  sendMessage,
  // Multi-model methods
  switchModel,
  getAvailableModels,
  getModelPerformance,
  getCurrentModel
} = useChatEngine({
  provider: 'openai',
  apiKey: import.meta.env.VITE_OPENAI_API_KEY,
  multiModel: {
    enabled: true,
    models: [
      { name: 'GPT-4', provider: 'openai', specialty: 'general' },
      { name: 'Claude', provider: 'anthropic', specialty: 'analysis' }
    ],
    autoSwitch: true
  }
});

// Get available models
const availableModels = getAvailableModels();

// Switch to specific model
async function useGPT4() {
  await switchModel('GPT-4');
}

// Get performance metrics
const performance = getModelPerformance();

// Get current active model
const currentModel = getCurrentModel();
</script>

Using the Intercom-like Chat Toggle

The AiChatToggle component provides an Intercom-like floating chat button that expands into a chat window:

<template>
  <!-- Floating chat button that toggles the chat window -->
  <AiChatToggle
    provider="openai"
    :api-key="apiKey"
    model="gpt-3.5-turbo"
    position="bottom"  <!-- 'bottom' or 'top' -->
    :default-open="false"
    title="Chat with AI"
    theme="light"
  />
</template>

<script setup>
import { AiChatToggle } from '@aivue/chatbot';

const apiKey = import.meta.env.VITE_OPENAI_API_KEY;
</script>

AiChatToggle with Custom Content

You can also use your own custom chat implementation inside the toggle:

<template>
  <AiChatToggle position="bottom" title="Custom Chat">
    <!-- Your custom chat implementation goes here -->
    <div class="custom-chat">
      <div class="messages">
        <div v-for="msg in messages" :key="msg.id" class="message">
          {{ msg.content }}
        </div>
      </div>
      <input v-model="input" @keyup.enter="sendMessage" />
      <button @click="sendMessage">Send</button>
    </div>
  </AiChatToggle>
</template>

<script setup>
import { ref } from 'vue';
import { AiChatToggle } from '@aivue/chatbot';

const messages = ref([]);
const input = ref('');

function sendMessage() {
  if (input.value.trim()) {
    messages.value.push({ id: Date.now(), content: input.value });
    input.value = '';
  }
}
</script>

Advanced Usage: Custom Styling

You can customize the appearance of the chat window using CSS variables:

:root {
  --aivue-chat-bg: #ffffff;
  --aivue-chat-border: #e0e0e0;
  --aivue-chat-text: #333333;
  --aivue-chat-user-bg: #e1f5fe;
  --aivue-chat-assistant-bg: #f5f5f5;
  --aivue-chat-input-bg: #ffffff;
  --aivue-chat-input-border: #e0e0e0;
  --aivue-chat-button-bg: #2196f3;
  --aivue-chat-button-text: #ffffff;
  --aivue-chat-error: #f44336;
  --aivue-chat-loading: #9e9e9e;
  --aivue-chat-border-radius: 8px;
  --aivue-chat-font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Dark theme example */
.dark-theme {
  --aivue-chat-bg: #1e1e1e;
  --aivue-chat-border: #444444;
  --aivue-chat-text: #f0f0f0;
  --aivue-chat-user-bg: #2b5278;
  --aivue-chat-assistant-bg: #383838;
  --aivue-chat-input-bg: #2d2d2d;
  --aivue-chat-input-border: #555555;
  --aivue-chat-button-bg: #4a6da7;
  --aivue-chat-button-text: #ffffff;
}

API Reference

AiChatWindow Props

PropTypeDefaultDescription
Provider Configuration
clientAIClientnullThe AIClient instance to use for generating responses
providerStringnullAI provider (e.g., 'openai', 'claude', 'gemini')
apiKeyStringnullAPI key for the provider
modelStringnullModel to use (e.g., 'gpt-3.5-turbo')
baseUrlStringnullCustom base URL for API requests
organizationIdStringnullOrganization ID (for OpenAI)
API Security
useProxyBooleanfalseWhether to use a proxy for API requests
proxyUrlString'/api/chat'URL for the proxy endpoint
Chat Configuration
titleString'Chat'The title displayed in the chat window header
placeholderString'Type a message...'Placeholder text for the input field
initialMessagesArray[]Initial messages to populate the chat
systemPromptString'You are a helpful assistant.'System prompt to guide the AI's behavior
streamingBooleantrueWhether to stream responses token by token
loadingTextString'Thinking...'Text to display while waiting for a response
errorTextString'An error occurred. Please try again.'Text to display when an error occurs
UI Configuration
showTimestampsBooleanfalseWhether to show timestamps on messages
showCopyButtonBooleantrueWhether to show a button to copy message content
showAvatarsBooleantrueWhether to show avatars for the user and assistant
userAvatarStringnullURL for the user avatar image
assistantAvatarStringnullURL for the assistant avatar image
themeString'light'Theme for the chat window ('light' or 'dark')
heightString'500px'Height of the chat window
widthString'100%'Width of the chat window
maxWidthString'800px'Maximum width of the chat window
persistenceKeyStringnullKey for persisting chat history in localStorage
Demo Mode
demoModeBooleanfalseWhether to use demo mode (no API key required)
demoResponsesObject{}Map of keywords to predefined responses for demo mode

AiChatWindow Events

EventPayloadDescription
message-sent{ message }Emitted when a user message is sent
response-received{ message }Emitted when an AI response is received
error{ error }Emitted when an error occurs
clear-Emitted when the chat history is cleared

AiChatWindow Slots

SlotPropsDescription
header-Custom header content
message{ message, index }Custom message rendering
user-message{ message, index }Custom user message rendering
assistant-message{ message, index }Custom assistant message rendering
input{ input, sendMessage }Custom input area
footer-Custom footer content

AiChatToggle Props

PropTypeDefaultDescription
Toggle Behavior
positionString'bottom'Position of the toggle button ('bottom' or 'top')
defaultOpenBooleanfalseWhether the chat window is open by default
titleString'Chat with AI'Title displayed in the chat window header
Provider Configuration
clientAIClientnullThe AIClient instance to use for generating responses
providerStringnullAI provider (e.g., 'openai', 'claude', 'gemini')
apiKeyStringnullAPI key for the provider
modelStringnullModel to use (e.g., 'gpt-3.5-turbo')
Chat Configuration
placeholderString'Type a message...'Placeholder text for the input field
initialMessagesArray[]Initial messages to populate the chat
systemPromptString'You are a helpful assistant.'System prompt to guide the AI's behavior
streamingBooleantrueWhether to stream responses token by token
themeString'light'Theme for the chat window ('light' or 'dark')
showAvatarsBooleantrueWhether to show avatars for the user and assistant
persistenceKeyStringnullKey for persisting chat history in localStorage
Demo Mode
demoModeBooleanfalseWhether to use demo mode (no API key required)
demoResponsesObject{}Map of keywords to predefined responses for demo mode

AiChatToggle Events

EventPayloadDescription
togglebooleanEmitted when the chat window is toggled, with the new state
message-sent{ message }Emitted when a user message is sent
response-received{ message }Emitted when an AI response is received
error{ error }Emitted when an error occurs

AiChatToggle Slots

SlotPropsDescription
default-Custom chat implementation (replaces the default AiChatWindow)
toggle-icon-Custom icon for the toggle button when closed
close-icon-Custom icon for the toggle button when open

useChatEngine Options

OptionTypeDefaultDescription
Provider Configuration
clientAIClientnullThe AIClient instance to use
providerStringRequired if no clientAI provider (e.g., 'openai', 'claude', 'gemini')
apiKeyStringundefinedAPI key for the provider
modelStringprovider-dependentModel to use
baseUrlStringundefinedCustom base URL for API requests
organizationIdStringundefinedOrganization ID (for OpenAI)
API Security
useProxyBooleanfalseWhether to use a proxy for API requests
proxyUrlString'/api/chat'URL for the proxy endpoint
Chat Behavior
initialMessagesArray[]Initial messages to populate the chat
systemPromptString'You are a helpful assistant.'System prompt to guide the AI's behavior
streamingBooleantrueWhether to stream responses token by token
persistenceKeyStringnullKey for persisting chat history in localStorage
maxMessagesNumber100Maximum number of messages to keep in history
Demo Mode
demoModeBooleanfalseWhether to use demo mode (no API key required)
demoResponsesObject{}Map of keywords to predefined responses for demo mode
Callbacks
onErrorFunctionnullCallback function when an error occurs
onMessageSentFunctionnullCallback when a message is sent
onResponseReceivedFunctionnullCallback when a response is received

useChatEngine Return Values

ValueTypeDescription
messagesRef<Array>Reactive array of chat messages
isLoadingRef<Boolean>Whether a response is being generated
errorRef<Error>Error object, if any
sendMessageFunctionFunction to send a user message
clearMessagesFunctionFunction to clear the chat history
setMessagesFunctionFunction to set the messages array
addMessageFunctionFunction to add a single message
resetErrorFunctionFunction to reset the error state
updateConfigFunctionFunction to update configuration options

Troubleshooting

Component Registration Issues

If you encounter issues with component registration, make sure you're using the correct import and registration method:

// Correct import
import { AiChatWindow } from '@aivue/chatbot';

// For local registration in a component
export default {
  components: {
    AiChatWindow
  }
}

// Or with script setup
import { AiChatWindow } from '@aivue/chatbot';

When using the component in templates, you can use either PascalCase or kebab-case:

<!-- Both of these work -->
<AiChatWindow :client="aiClient" />
<ai-chat-window :client="aiClient" />

TypeScript Support

The package includes full TypeScript support. You can import types directly:

import { Message, ChatOptions } from '@aivue/chatbot';

// Use types in your code
const messages: Message[] = [];
const options: ChatOptions = {
  provider: 'openai',
  apiKey: import.meta.env.VITE_OPENAI_API_KEY,
  systemPrompt: 'You are a helpful assistant.'
};

API Key Security

For security reasons, never hardcode API keys in your code. Use environment variables instead:

// .env file
VITE_OPENAI_API_KEY=your-api-key

// In your code
const apiKey = import.meta.env.VITE_OPENAI_API_KEY;

Or better yet, use the proxy feature:

<script setup>
import { useChatEngine } from '@aivue/chatbot';

const { messages, isLoading, sendMessage } = useChatEngine({
  provider: 'openai',
  useProxy: true,
  proxyUrl: '/api/chat' // Your backend endpoint
});
</script>

Webpack Configuration

If you're using webpack, make sure your configuration properly handles Vue components:

// webpack.config.js
module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      },
      // ...
    ]
  },
  // ...
}

Vite Configuration

For Vite projects, add the following to your vite.config.js:

// vite.config.js
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
  plugins: [vue()],
  optimizeDeps: {
    include: ['@aivue/chatbot', '@aivue/core']
  }
});

Vue Version Compatibility Issues

If you encounter errors related to missing Vue functions like createElementBlock, normalizeClass, or createElementVNode, it means you're using an older version of Vue 3 (pre-3.2.0). Here's how to fix it:

  • Check your Vue version:

    npm list vue
    
  • If you're using Vue < 3.2.0: The package includes a compatibility layer that should handle this automatically. If you're still experiencing issues, you can:

    a. Update to Vue 3.2.0 or higher (recommended):

    npm install vue@^3.2.0
    

    b. Use the compatibility utilities explicitly:

    import {
      compatCreateElementBlock,
      compatCreateElementVNode,
      compatNormalizeClass
    } from '@aivue/chatbot';
    
    // Use these functions instead of the Vue ones
    
  • For component registration issues: Use the provided compatibility helpers:

    import { registerCompatComponent } from '@aivue/chatbot';
    
    // Instead of app.component('MyComponent', Component)
    registerCompatComponent(app, 'MyComponent', Component);
    

πŸ“Ί Live Demo

AI Chatbot Demo

Interactive Demo

See the chatbot components in action with our interactive demo. Try different AI providers, customize the appearance, and test all the features.

Launch Demo β†’

🧠 @aivue/core

Core AI functionality for Vue.js components

✨ @aivue/autosuggest

AI-powered suggestion components for Vue.js

πŸ“ @aivue/smartform

AI-powered form validation for Vue.js

πŸ–ΌοΈ @aivue/image-caption

AI-powered image captioning with OpenAI Vision models

πŸ“„ License

MIT Β© Bharatkumar Subramanian

Keywords

vue

FAQs

Package last updated on 13 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts