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

mia21

v1.3.3

Published

Official JavaScript/TypeScript SDK for Mia21 Chat API - Build AI chatbots in minutes with tool calling support

Readme

🟨 Mia21 JavaScript/TypeScript SDK

Official JavaScript and TypeScript client library for the Mia21 Chat API.

npm version TypeScript License


🚀 Quick Start

Installation

npm install mia21
# or
yarn add mia21

Basic Usage (JavaScript)

const { Mia21Client } = require('mia21');

const client = new Mia21Client({ apiKey: 'your-api-key-here' });

async function main() {
  // Initialize chat
  await client.initialize({ spaceId: 'customer_support' });
  
  // Send message
  const response = await client.chat('How do I reset my password?');
  console.log(response.message);
  
  // Close session
  await client.close();
}

main();

TypeScript

import { Mia21Client, ChatResponse } from 'mia21';

const client = new Mia21Client({ apiKey: 'your-api-key-here' });

async function main(): Promise<void> {
  await client.initialize({ spaceId: 'customer_support' });
  
  const response: ChatResponse = await client.chat('Hello!');
  console.log(response.message);
  
  await client.close();
}

main();

Streaming Chat

import { Mia21Client } from 'mia21';

const client = new Mia21Client({ apiKey: 'your-api-key-here' });

async function streamExample() {
  await client.initialize();
  
  process.stdout.write('AI: ');
  await client.streamChat('Tell me a story', (chunk) => {
    process.stdout.write(chunk);
  });
  console.log();
  
  await client.close();
}

streamExample();

📚 API Reference

Constructor

const client = new Mia21Client({
  apiKey: string;              // Required: Your Mia21 API key
  baseUrl?: string;            // Optional: API base URL
  userId?: string;             // Optional: User ID (auto-generated)
  timeout?: number;            // Optional: Request timeout (ms)
});

Methods

listSpaces()

const spaces = await client.listSpaces();
// Returns: Promise<Space[]>

spaces.forEach(space => {
  console.log(`${space.id}: ${space.name}`);
});

initialize(options)

const response = await client.initialize({
  spaceId: 'customer_support',    // Optional
  llmType: 'openai',              // Optional: 'openai' | 'gemini'
  userName: 'John',               // Optional
  language: 'en',                 // Optional
  generateFirstMessage: true,     // Optional
  incognitoMode: false            // Optional
});
// Returns: Promise<InitializeResponse>

console.log(response.message);  // AI greeting

chat(message, options)

const response = await client.chat(
  'How do I reset my password?',  // Required: User message
  {
    spaceId: 'support',           // Optional
    temperature: 0.7,             // Optional: 0.0-2.0
    maxTokens: 1024               // Optional
  }
);
// Returns: Promise<ChatResponse>

console.log(response.message);
console.log(response.tool_calls);

streamChat(message, onChunk, options)

await client.streamChat(
  'Tell me a story',              // Required: User message
  (chunk) => {                    // Required: Callback for each chunk
    process.stdout.write(chunk);
  },
  {
    spaceId: 'storyteller',       // Optional
    temperature: 0.9              // Optional
  }
);
// Returns: Promise<void>

close(spaceId)

await client.close('customer_support');  // Optional: space ID
// Returns: Promise<void>

🎯 Usage Examples

React Component

import { useState, useEffect } from 'react';
import { Mia21Client } from 'mia21';

function ChatComponent() {
  const [client] = useState(() => new Mia21Client({ apiKey: process.env.REACT_APP_MIA21_API_KEY! }));
  const [message, setMessage] = useState('');
  const [response, setResponse] = useState('');
  const [isStreaming, setIsStreaming] = useState(false);

  useEffect(() => {
    client.initialize({ spaceId: 'customer_support' });
    return () => {
      client.close();
    };
  }, []);

  const sendMessage = async () => {
    setIsStreaming(true);
    setResponse('');
    
    await client.streamChat(message, (chunk) => {
      setResponse(prev => prev + chunk);
    });
    
    setIsStreaming(false);
    setMessage('');
  };

  return (
    <div>
      <div className="chat-output">{response}</div>
      <input 
        value={message} 
        onChange={(e) => setMessage(e.target.value)} 
        placeholder="Type a message..."
        disabled={isStreaming}
      />
      <button onClick={sendMessage} disabled={isStreaming || !message}>
        {isStreaming ? 'Sending...' : 'Send'}
      </button>
    </div>
  );
}

export default ChatComponent;

Vue.js Component

<template>
  <div>
    <div class="chat-output">{{ response }}</div>
    <input 
      v-model="message" 
      @keyup.enter="sendMessage"
      placeholder="Type a message..."
      :disabled="isStreaming"
    />
    <button @click="sendMessage" :disabled="isStreaming || !message">
      {{ isStreaming ? 'Sending...' : 'Send' }}
    </button>
  </div>
</template>

<script>
import { Mia21Client } from 'mia21';

export default {
  data() {
    return {
      client: new Mia21Client({ apiKey: process.env.VUE_APP_MIA21_API_KEY }),
      message: '',
      response: '',
      isStreaming: false
    };
  },
  async mounted() {
    await this.client.initialize({ spaceId: 'customer_support' });
  },
  async beforeUnmount() {
    await this.client.close();
  },
  methods: {
    async sendMessage() {
      this.isStreaming = true;
      this.response = '';
      
      await this.client.streamChat(this.message, (chunk) => {
        this.response += chunk;
      });
      
      this.isStreaming = false;
      this.message = '';
    }
  }
};
</script>

Node.js Server

import express from 'express';
import { Mia21Client } from 'mia21';

const app = express();
app.use(express.json());

const client = new Mia21Client({ apiKey: process.env.MIA21_API_KEY! });

app.post('/api/chat', async (req, res) => {
  const { userId, message } = req.body;
  
  try {
    // Initialize if not already
    await client.initialize({ spaceId: 'customer_support' });
    
    // Get response
    const response = await client.chat(message);
    
    res.json({ message: response.message });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});

app.listen(3000);

🛠️ Configuration

Environment Variables

# .env file
MIA21_API_KEY=your-api-key-here
MIA21_BASE_URL=https://mia-api-staging-795279012747.us-central1.run.app
import { Mia21Client } from 'mia21';

const client = new Mia21Client({
  apiKey: process.env.MIA21_API_KEY!,
  baseUrl: process.env.MIA21_BASE_URL
});

🧪 Testing

# Install dependencies
npm install

# Build TypeScript
npm run build

# Run tests
npm test

📄 License

MIT License - see LICENSE file for details.


🆘 Support

  • Documentation: https://docs.mia21.com
  • API Reference: https://docs.mia21.com/api
  • GitHub Issues: https://github.com/mia21/javascript-sdk/issues
  • Discord: https://discord.gg/mia21
  • Email: [email protected]

🎉 Examples

See the examples/ directory for complete working examples:

  • basic-chat.ts - Simple chat example
  • streaming-chat.ts - Streaming response example
  • react-component.tsx - React integration
  • vue-component.vue - Vue.js integration
  • express-server.ts - Node.js server

Made with ❤️ by Mia21