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

@cometchat/vercel-adapter

v0.0.1-beta

Published

A TypeScript library for CometChat integration with Vercel

Readme

CometChat Vercel AI SDK Adapter

A TypeScript adapter library that enables seamless integration between CometChat and Vercel's AI SDK. This library provides conversion utilities to bridge the gap between CometChat's messaging format and Vercel AI SDK's expected data structures.

Installation

Install the package using npm:

npm install @cometchat/vercel-adapter

Or using yarn:

yarn add @cometchat/vercel-adapter

What is this library?

This adapter library facilitates the integration of CometChat's AI capabilities with Vercel's AI SDK by providing:

  • Message Format Conversion: Converts CometChat messages to Vercel AI SDK compatible format
  • Tool Integration: Adapts CometChat tools to work with Vercel AI SDK's tool system
  • Stream Event Mapping: Maps Vercel AI SDK streaming events to CometChat event format
  • Type Safety: Full TypeScript support with proper type definitions

Functions Exposed

convertCometChatMessagesToVercelMessages(messages: Message[]): ModelMessage[]

Converts an array of CometChat messages to Vercel AI SDK compatible ModelMessage format.

Parameters:

  • messages: Array of CometChat Message objects

Returns:

  • Array of ModelMessage objects compatible with Vercel AI SDK

Example:

import { convertCometChatMessagesToVercelMessages } from '@cometchat/vercel-adapter';

const cometChatMessages = [
  { role: 'user', content: 'Hello, how can you help me?' },
  { role: 'assistant', content: 'I can help you with various tasks!', toolCalls: [] }
];

const vercelMessages = convertCometChatMessagesToVercelMessages(cometChatMessages);

convertCometChatToolsToVercelAISDKTools(tools: RunAgentInput["tools"]): any

Converts CometChat tools to Vercel AI SDK compatible tool format with Zod schema validation.

Parameters:

  • tools: Array of CometChat tool definitions

Returns:

  • Object containing Vercel AI SDK compatible tools

Example:

import { convertCometChatToolsToVercelAISDKTools } from '@cometchat/vercel-adapter';

const cometChatTools = [
  {
    name: 'search',
    description: 'Search for information',
    parameters: {
      type: 'object',
      properties: {
        query: { type: 'string', description: 'Search query' }
      },
      required: ['query']
    }
  }
];

const vercelTools = convertCometChatToolsToVercelAISDKTools(cometChatTools);

mapVercelStreamChunkToCometChatEvent(chunk: TextStreamPart<any>): CometChatStreamEvent[]

Maps Vercel AI SDK streaming chunks to CometChat event format for real-time communication.

Parameters:

  • chunk: A TextStreamPart from Vercel AI SDK stream

Returns:

  • Array of CometChatStreamEvent objects

Supported Stream Events:

  • text-start, text-delta, text-end - Text message events
  • tool-call, tool-result, tool-error - Tool execution events
  • reasoning-start, reasoning-delta, reasoning-end - AI reasoning events
  • error, finish, start - Stream lifecycle events

Example:

import { mapVercelStreamChunkToCometChatEvent } from '@cometchat/vercel-adapter';

// During streaming from Vercel AI SDK
streamResult.onTextChunk((chunk) => {
  const cometChatEvents = mapVercelStreamChunkToCometChatEvent(chunk);
  // Process CometChat events
  cometChatEvents.forEach(event => {
    console.log('CometChat event:', event);
  });
});

Usage Example

Here's a complete example showing how to use the adapter in a typical integration:

import { 
  convertCometChatMessagesToVercelMessages,
  convertCometChatToolsToVercelAISDKTools,
  mapVercelStreamChunkToCometChatEvent 
} from '@cometchat/vercel-adapter';
import { streamText } from 'ai';

// Convert CometChat messages and tools
const vercelMessages = convertCometChatMessagesToVercelMessages(cometChatMessages);
const vercelTools = convertCometChatToolsToVercelAISDKTools(cometChatTools);

// Use with Vercel AI SDK
const result = await streamText({
  model: yourModel,
  messages: vercelMessages,
  tools: vercelTools,
});

// Handle streaming responses
for await (const chunk of result.textStream) {
  const cometChatEvents = mapVercelStreamChunkToCometChatEvent(chunk);
  // Process events in your CometChat integration
}

Development

Building the Library

npm run build

Running Tests

npm run test

Development Mode

npm run dev