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

@biubiupiu/ai-sdk-tool-parser

v2.7.0

Published

▲ Also available in the Vercel AI SDK official documentation: [Custom tool call parser](https://ai-sdk.dev/docs/ai-sdk-core/middleware#custom-tool-call-parser)

Readme

AI SDK - tool call parser middleware

▲ Also available in the Vercel AI SDK official documentation: Custom tool call parser

npm npm codecov

[!NOTE] Requires AI SDK v5. For AI SDK v4, pin @ai-sdk-tool/[email protected].

Middleware that enables tool calling with models that don’t natively support OpenAI‑style tools. Works with any provider (OpenRouter, vLLM, Ollama, etc.) via AI SDK middleware.

Why This Exists

Many self‑hosted or third‑party model endpoints (vLLM, MLC‑LLM, Ollama, OpenRouter, etc.) don’t yet expose the OpenAI‑style tools parameter, forcing you to hack together tool parsing.
This project provides a flexible middleware that:

  • Parses tool calls from streaming or batch responses
  • Prebuilt protocols: JSON‑mix (Gemma/Hermes‑style) and Morph‑XML
  • Full control over the tool call system prompt

Installation

pnpm add @ai-sdk-tool/parser

Quickstart (streaming)

import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { wrapLanguageModel, stepCountIs, streamText } from "ai";
import { gemmaToolMiddleware } from "@ai-sdk-tool/parser";

const openrouter = createOpenAICompatible({
  /* ... */
});

async function main() {
  const result = streamText({
    model: wrapLanguageModel({
      model: openrouter("google/gemma-3-27b-it"),
      middleware: gemmaToolMiddleware,
    }),
    system: "You are a helpful assistant.",
    prompt: "What is the weather in my city?",
    stopWhen: stepCountIs(4),
    tools: {
      get_location: {
        /* ... */
      },
      get_weather: {
        /* ... */
      },
    },
  });

  for await (const part of result.fullStream) {
    // handle text/tool events
  }
}

main().catch(console.error);

Quickstart (generate)

import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { wrapLanguageModel, generateText } from "ai";
import { hermesToolMiddleware } from "@ai-sdk-tool/parser";

const openrouter = createOpenAICompatible({
  /* ... */
});

async function main() {
  const { text } = await generateText({
    model: wrapLanguageModel({
      model: openrouter("nousresearch/hermes-3-llama-3.1-70b"),
      middleware: hermesToolMiddleware,
    }),
    prompt: "Find weather for Seoul today",
    tools: {
      get_weather: {
        /* ... */
      },
    },
  });

  console.log(text);
}

main().catch(console.error);

Prebuilt middlewares

  • gemmaToolMiddleware — JSON‑mix format inside markdown fences (markdown code fences)
  • hermesToolMiddleware — JSON‑mix format wrapped in <tool_call> XML tags.
  • morphXmlToolMiddleware — XML format (Morph‑XML protocol).

Protocols

  • jsonMixProtocol — JSON function calls in flexible text wrappers.
  • morphXmlProtocol — XML element per call, robust to streaming.

Tool choice support

  • toolChoice: { type: "required" }: forces one tool call. Middleware sets a JSON response schema to validate calls.
  • toolChoice: { type: "tool", toolName }: forces a specific tool. Provider‑defined tools are not supported; pass only custom function tools.
  • toolChoice: { type: "none" } is not supported and will throw.

Examples

See examples/parser-core/src/* for runnable demos (streaming/non‑streaming, tool choice).

[dev] Contributor notes

  • Exported API: createToolMiddleware, gemmaToolMiddleware, hermesToolMiddleware, morphXmlToolMiddleware, jsonMixProtocol, morphXmlProtocol.
  • Debugging:
    • Set DEBUG_PARSER_MW=stream to log raw/parsed chunks during runs.
    • Set DEBUG_PARSER_MW=parse to log original matched text and parsed summary.
    • Optional DEBUG_PARSER_MW_STYLE=bg|inverse|underline|bold to change highlight style.
  • Provider options passthrough: providerOptions.toolCallMiddleware fields are merged into protocol options. Internal fields used:
    • originalTools: internal propagation of custom tool schemas.
    • toolChoice: internal fast‑path activation for required/specific tool modes.
  • Transform details: transformParams injects a system message built from protocol formatTools and clears tools since many providers strip/ignore them.

License

Licensed under Apache License 2.0. See the repository LICENSE. Include the NOTICE file in distributions.