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

@ai-chat-ui-kit/core

v0.1.3

Published

Core logic layer for AI Chat UI Kit (Headless)

Readme

@ai-chat-ui-kit/core

Core logic layer for AI Chat UI Kit - Headless mode state management, API adapters, and plugin system.

Version License TypeScript

✨ Features

  • 🎯 Headless Mode - Use only the logic layer, build your own UI
  • 📦 State Management - Predictable state container with createChatStore()
  • 🌐 API Adapters - Built-in adapters for OpenAI, Anthropic, and custom APIs
  • 🔌 Plugin System - Extend functionality with custom plugins
  • 🎯 TypeScript Support - Complete type definitions included

📦 Installation

pnpm add @ai-chat-ui-kit/core
# or
npm install @ai-chat-ui-kit/core
# or
yarn add @ai-chat-ui-kit/core

🚀 Quick Start

Headless Mode (No UI)

import { createChatStore, createAPIAdapter } from '@ai-chat-ui-kit/core';

// Create state store
const store = createChatStore({
  initialState: {
    messages: [],
    loading: false
  }
});

// Subscribe to state changes
store.subscribe((state) => {
  console.log('Messages:', state.messages);
  console.log('Loading:', state.loading);
  // Update your custom UI here
});

// Create API adapter
const adapter = createAPIAdapter({
  type: 'openai',
  apiKey: process.env.OPENAI_API_KEY,
  model: 'gpt-4'
});

// Handle user input
async function handleUserMessage(message: string) {
  // Add user message
  store.dispatch({
    type: 'ADD_MESSAGE',
    payload: { role: 'user', content: message }
  });

  // Set loading
  store.dispatch({ type: 'SET_LOADING', payload: true });

  // Get AI response
  const response = await adapter.sendMessage(message);

  // Add AI response
  store.dispatch({
    type: 'ADD_MESSAGE',
    payload: { role: 'assistant', content: response }
  });

  // Clear loading
  store.dispatch({ type: 'SET_LOADING', payload: false });
}

📖 API Reference

createChatStore(config?)

Create a chat state management store.

const store = createChatStore({
  initialState?: Partial<ChatState>,
  middleware?: Middleware[]
});

interface ChatState {
  messages: Message[];
  loading: boolean;
  error: string | null;
  theme: string;
}

interface ChatStore {
  getState(): ChatState;
  dispatch(action: Action): void;
  subscribe(listener: (state: ChatState) => void): () => void;
}

createAPIAdapter(config)

Create an API adapter for different AI backends.

// OpenAI
const openai = createAPIAdapter({
  type: 'openai',
  apiKey: 'your-api-key',
  model: 'gpt-4'
});

// Anthropic (Claude)
const anthropic = createAPIAdapter({
  type: 'anthropic',
  apiKey: 'your-api-key',
  model: 'claude-3-opus'
});

// Custom API
const custom = createAPIAdapter({
  type: 'custom',
  endpoint: 'https://your-api.com/chat',
  headers: { 'Authorization': 'Bearer token' }
});

interface APIAdapter {
  sendMessage(message: string, history?: Message[]): Promise<string>;
  streamMessage?(message: string, history?: Message[]): AsyncIterable<string>;
}

createPluginSystem()

Create a plugin system to extend functionality.

import { createPluginSystem, Plugin } from '@ai-chat-ui-kit/core';

const myPlugin: Plugin = {
  name: 'my-plugin',
  install: (context) => {
    const store = context.getStore();
    store.subscribe((state) => {
      console.log('State changed:', state);
    });
  }
};

const pluginSystem = createPluginSystem();
pluginSystem.register(myPlugin);

📖 Examples

Custom UI with React

import React, { useState, useEffect } from 'react';
import { createChatStore } from '@ai-chat-ui-kit/core';

const ChatApp: React.FC = () => {
  const [store] = useState(() => createChatStore());
  const [messages, setMessages] = useState<Message[]>([]);
  const [loading, setLoading] = useState(false);

  useEffect(() => {
    const unsubscribe = store.subscribe((state) => {
      setMessages([...state.messages]);
      setLoading(state.loading);
    });
    return unsubscribe;
  }, [store]);

  const sendMessage = async (content: string) => {
    await handleUserMessage(content);
  };

  return (
    <div>
      {messages.map((msg, i) => (
        <div key={i} className={msg.role}>
          {msg.content}
        </div>
      ))}
      {loading && <div>Loading...</div>}
    </div>
  );
};

Persistence Plugin

const persistencePlugin: Plugin = {
  name: 'persistence',
  install: (context) => {
    const store = context.getStore();
    
    // Load saved messages
    const saved = localStorage.getItem('chat-messages');
    if (saved) {
      JSON.parse(saved).forEach((msg: Message) => {
        store.dispatch({ type: 'ADD_MESSAGE', payload: msg });
      });
    }
    
    // Save messages on change
    store.subscribe((state) => {
      localStorage.setItem('chat-messages', JSON.stringify(state.messages));
    });
  }
};

📦 Dependencies

  • marked - Markdown parsing
  • marked-highlight - Code highlighting
  • highlight.js - Syntax highlighting
  • mermaid - Mermaid diagram support
  • katex - LaTeX math rendering

🤝 Contributing

Contributions welcome! Please read our contributing guidelines.

📄 License

MIT License

👤 Author

edenxpzhang

🔗 Links