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

@xpert-ai/plugin-dangling-tool-call

v0.0.1

Published

`@xpert-ai/plugin-dangling-tool-call` repairs dangling tool calls in XpertAI agent message history before the next model invocation.

Readme

Dangling Tool Call Middleware

@xpert-ai/plugin-dangling-tool-call repairs dangling tool calls in XpertAI agent message history before the next model invocation.

A dangling tool call means an AIMessage contains one or more tool_calls, but the history is missing the matching ToolMessage for at least one tool_call.id.

What It Does

  • scans request.messages inside wrapModelCall
  • detects tool_call.id values that do not have a matching ToolMessage.tool_call_id
  • inserts a synthetic error ToolMessage immediately after the source AIMessage
  • passes the patched message list to the remaining model middleware chain

What It Does Not Do

  • retry tools
  • re-run interrupted work
  • delete original tool_calls
  • modify existing ToolMessage entries
  • persist patched messages back into thread history

Why It Exists

Dangling tool calls typically appear when a tool run is interrupted:

  • the user stops the session
  • the request is cancelled or times out
  • the tool execution path exits before writing its result

Without a repair step, later model calls may receive an invalid tool-call transcript and fail protocol validation or continue from a broken conversation state.

Agent Behavior

When the middleware finds a missing tool result, it inserts:

ToolMessage(
  tool_call_id="<original id>",
  name="<tool name or unknown>",
  status="error",
  content="[Tool call was interrupted and did not return a result.]"
)

This makes the failure explicit without pretending the tool succeeded.

Recommended Order

Place DanglingToolCallMiddleware early in the agent's middleware list, before other wrapModelCall middlewares that depend on structurally valid message history.

In Xpert, wrapModelCall middlewares are composed with reduceRight, so items earlier in the workflow middleware list receive the request first.

Example

Before:

HumanMessage("Read the file")
AIMessage(tool_calls=[{ "name": "read_file", "id": "call_1" }])
HumanMessage("Continue")

After patching:

HumanMessage("Read the file")
AIMessage(tool_calls=[{ "name": "read_file", "id": "call_1" }])
ToolMessage(
  tool_call_id="call_1",
  name="read_file",
  status="error",
  content="[Tool call was interrupted and did not return a result.]"
)
HumanMessage("Continue")

Validation Commands

NX_DAEMON=false pnpm -C /path/to/xpert-plugins/xpertai exec jest middlewares/dangling-tool-call/src/lib/dangling-tool-call.middleware.spec.ts --config middlewares/dangling-tool-call/jest.config.cjs --runInBand
NX_DAEMON=false pnpm -C /path/to/xpert-plugins/xpertai exec tsc -b middlewares/dangling-tool-call/tsconfig.lib.json