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

genkit-aisdk-converter

v0.1.0

Published

Convert between Genkit and AI SDK UI message stream protocols

Readme

genkit-aisdk-converter

Convert between Genkit generateStream output and the AI SDK UI message stream protocol. Use Genkit on the server for generation while staying compatible with AI SDK clients (useChat, AIChatAgent, etc.).

Overview

  • Incoming (client → server): AI SDK UI messages → Genkit MessageData[] so your endpoint can pass them into Genkit.
  • Outgoing (server → client): Genkit GenerateResponseChunk stream → AI SDK UI message stream so the same endpoint can return a Response that useChat() and other AI SDK clients consume.

Installation

npm install genkit-aisdk-converter

Peer dependencies: ai (≥6.0.0) and @genkit-ai/ai (≥1.0.0). Install them if not already present:

npm install ai @genkit-ai/ai

Usage

Outgoing: Genkit stream → AI SDK response

Turn a Genkit generateStream() result into a streaming Response for useChat():

import { ai } from "@genkit-ai/ai";
import {
  genkitStreamToUIMessageStreamResponse,
  uiMessagesToGenkitMessages,
} from "genkit-aisdk-converter";

// In your route/handler:
const genkitStream = await ai.generateStream({
  model: "your-model",
  messages: uiMessagesToGenkitMessages(messages), // convert client messages
});

const response = genkitStreamToUIMessageStreamResponse(
  genkitStream
);

return response;

To get a ReadableStream<UIMessageChunk> instead of a Response (e.g. to wrap with createUIMessageStreamResponse() yourself):

import { genkitChunksToUIMessageStream } from "genkit-aisdk-converter";
import { createUIMessageStreamResponse } from "ai";

const stream = genkitChunksToUIMessageStream(genkitStream, options);
return createUIMessageStreamResponse(stream);

Incoming: AI SDK messages → Genkit messages

Convert messages from useChat (or AIChatAgent) to Genkit MessageData[] before calling ai.generateStream():

import { uiMessagesToGenkitMessages } from "genkit-aisdk-converter";

const genkitMessages = uiMessagesToGenkitMessages(messages, {
  ignoreIncompleteToolCalls: true, // omit tool parts still streaming input
  convertDataPart: (part) => {
    // Optional: AI SDK "data" parts (e.g. type "data-custom") are arbitrary JSON.
    // Genkit only accepts text/media, so by default they are skipped. Return
    // { text } or { media } to include them in the Genkit message.
    if (part.data?.type === "caption") return { text: part.data.text };
    return undefined;
  },
});

Handled UI part types: text, file, reasoning, tool (with ref/name/input/output and approval/denied), data (with optional convertDataPart), step-start, source-url, source-document.

API

| Export | Description | |--------|-------------| | uiMessagesToGenkitMessages(messages, options?) | AI SDK UIMessage[] → Genkit MessageData[]. | | genkitChunksToUIMessageStream(genkitStream, options?) | AsyncIterable<GenerateResponseChunk>ReadableStream<UIMessageChunk>. | | genkitStreamToUIMessageStreamResponse(genkitStream, init?, options?) | Same stream converted into a streaming Response for AI SDK clients. |

Options

UiMessagesToGenkitOptions (incoming)

  • convertDataPart?(part) – AI SDK "data" parts (e.g. data-custom) are arbitrary JSON and are skipped by default. Return { text } or { media } to include them in Genkit messages; return undefined to keep skipping.
  • ignoreIncompleteToolCalls? – When true, omit tool parts in input-streaming / input-available (aligns with convertToModelMessages).

GenkitStreamToUIMessageOptions (outgoing)

  • responsePromise? – e.g. genkitStream.response; when provided, the real Genkit finish reason is used on the final finish chunk (otherwise it defaults to "stop").
  • messageMetadata? – Attached to start and finish chunks (e.g. for tracing).
  • dataPartTypeName? – Name for custom/data chunks (default 'custom'); alphanumeric and hyphen only; produces data-<name>.
  • toolResponseToChunk? – Optional mapper to emit tool-output-error or tool-output-denied instead of tool-output-available.

Protocol mapping

  • Genkit chunks: { index, role, content: Part[] } with Part = { text } | { toolRequest } | { reasoning } | { media } | custom, etc.
  • AI SDK UI stream: starttext-start / text-delta / text-end, reasoning-start / reasoning-delta / reasoning-end, tool-input-start / tool-input-available / tool-output-available, finish-step, finish[DONE].

License

MIT · Invertase