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-sdk-tool/parser

v4.1.13

Published

AI SDK middleware for tool call parsing

Readme


npm - parser npm downloads - parser codecov

AI SDK middleware for parsing tool calls from models that do not natively support tools.

Install

pnpm add @ai-sdk-tool/parser

AI SDK compatibility

Fact-checked from this repo CHANGELOG.md and npm release metadata (as of 2026-02-18).

| @ai-sdk-tool/parser major | AI SDK major | Maintenance status | |---|---|---| | v1.x | v4.x | Legacy (not actively maintained) | | v2.x | v5.x | Legacy (not actively maintained) | | v3.x | v6.x | Legacy (not actively maintained) | | v4.x | v6.x | Active (current latest line) |

Note: there is no separate formal EOL announcement in releases/changelog for v1-v3; "legacy" here means non-current release lines.

Package map

| Import | Purpose | |---|---| | @ai-sdk-tool/parser | Main middleware factory, preconfigured middleware, protocol exports | | @ai-sdk-tool/parser/community | Community middleware (Sijawara, UI-TARS) |

Quick start

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

const model = createOpenAICompatible({
  name: "openrouter",
  apiKey: process.env.OPENROUTER_API_KEY,
  baseURL: "https://openrouter.ai/api/v1",
})("arcee-ai/trinity-large-preview:free");

const result = streamText({
  model: wrapLanguageModel({
    model,
    middleware: morphXmlToolMiddleware,
  }),
  stopWhen: stepCountIs(4),
  prompt: "What is the weather in Seoul?",
  tools: {
    get_weather: {
      description: "Get weather by city name",
      inputSchema: z.object({ city: z.string() }),
      execute: async ({ city }) => ({ city, condition: "sunny", celsius: 23 }),
    },
  },
});

for await (const part of result.fullStream) {
  // text-delta / tool-input-start / tool-input-delta / tool-input-end / tool-call / tool-result
}

Choose middleware

Use the preconfigured middleware exports from src/preconfigured-middleware.ts:

| Middleware | Best for | |---|---| | hermesToolMiddleware | JSON-style tool payloads | | morphXmlToolMiddleware | XML-style payloads with schema-aware coercion | | yamlXmlToolMiddleware | XML tool tags + YAML bodies | | qwen3CoderToolMiddleware | Qwen/UI-TARS style <tool_call> markup |

Build custom middleware

import { createToolMiddleware, qwen3CoderProtocol } from "@ai-sdk-tool/parser";

export const myToolMiddleware = createToolMiddleware({
  protocol: qwen3CoderProtocol,
  toolSystemPromptTemplate: (tools) =>
    `Use these tools and emit <tool_call> blocks only: ${JSON.stringify(tools)}`,
});

Streaming semantics

  • Stream parsers emit tool-input-start, tool-input-delta, and tool-input-end when a tool input can be incrementally reconstructed.
  • tool-input-start.id, tool-input-end.id, and final tool-call.toolCallId are reconciled to the same ID.
  • emitRawToolCallTextOnError defaults to false; malformed tool-call markup is suppressed from text-delta unless explicitly enabled.

Configure parser error behavior through providerOptions.toolCallMiddleware:

const result = streamText({
  // ...
  providerOptions: {
    toolCallMiddleware: {
      onError: (message, metadata) => {
        console.warn(message, metadata);
      },
      emitRawToolCallTextOnError: false,
    },
  },
});

Local development

pnpm build
pnpm test
pnpm check:biome
pnpm check:types
pnpm check

Examples in this repo

  • Parser middleware examples: examples/parser-core/README.md
  • RXML examples: examples/rxml-core/README.md

Run one example from repo root:

pnpm dlx tsx examples/parser-core/src/01-stream-tool-call.ts