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

@skroyc/ag-ui-middleware-callbacks

v2.0.3

Published

AG-UI backend, adapter, and producer primitives for LangChain.js

Downloads

493

Readme

@skroyc/ag-ui-middleware-callbacks

AG-UI backend, adapter, and producer primitives for LangChain.js.

Status

The frozen MVP contract is recorded in docs/ContractFreeze.md. The current shipped package now goes further and includes the extracted adapter boundary described in docs/TechSpec.md.

Current implementation status:

  • published runtime surface: programmatic adapter, backend wrapper, run-scoped publisher, and low-level producers
  • validated example set: CLI verifier plus GUI-backed default backend example and advanced custom-host example under example/, both reusing the same adapter semantics
  • createAGUIAgent: still present in source for transition work, but no longer treated as public package API

Install

bun install @skroyc/ag-ui-middleware-callbacks

Public Imports

Prefer explicit subpath imports:

import { AGUICallbackHandler } from "@skroyc/ag-ui-middleware-callbacks/callbacks";
import { createAGUIAdapter } from "@skroyc/ag-ui-middleware-callbacks/adapter";
import { createAGUIBackend } from "@skroyc/ag-ui-middleware-callbacks/backend";
import { createAGUIMiddleware } from "@skroyc/ag-ui-middleware-callbacks/middleware";
import { createAGUIRunPublisher } from "@skroyc/ag-ui-middleware-callbacks/publication";

The root export remains intentionally minimal:

import {
	AGUICallbackHandler,
	createAGUIMiddleware,
} from "@skroyc/ag-ui-middleware-callbacks";

Programmatic Adapter Path

Use the adapter subpath when your host wants to own auth, routing, or transport but still reuse the package's canonical run orchestration:

import { createAgent } from "langchain";
import { createAGUIAdapter } from "@skroyc/ag-ui-middleware-callbacks/adapter";

const adapter = createAGUIAdapter({
  agentFactory: ({ input, middleware }) =>
    createAgent({
      model,
      tools,
      middleware: [middleware],
    }),
});

const events = await adapter.stream(input, { signal });

for await (const event of events) {
  console.log(event);
}

Default Backend Path

Use the backend subpath for the batteries-included serving path:

import { createAgent } from "langchain";
import { createAGUIBackend } from "@skroyc/ag-ui-middleware-callbacks/backend";

const backend = createAGUIBackend({
  agentFactory: ({ middleware }) =>
    createAgent({
      model,
      tools,
      middleware: [middleware],
    }),
});

export function handle(request: Request) {
  return backend.handle(request);
}

handle(request) expects a strict AG-UI RunAgentInput JSON payload and returns a streamed text/event-stream response. Internally, the backend now wraps createAGUIAdapter() rather than owning run orchestration itself.

Low-Level Example

import { AGUICallbackHandler } from "@skroyc/ag-ui-middleware-callbacks/callbacks";
import { createAGUIMiddleware } from "@skroyc/ag-ui-middleware-callbacks/middleware";

const publish = (event: unknown) => {
	console.log(event);
};

const middleware = createAGUIMiddleware({
	publish,
	emitStateSnapshots: "initial",
	errorDetailLevel: "message",
});

const callbacks = [
	new AGUICallbackHandler({
		publish,
		reasoningEventMode: "reasoning",
	}),
];

Notes

  • Reasoning events can be emitted as legacy THINKING_* or newer REASONING_* families.
  • New adapter-facing code should prefer REASONING_*; THINKING_* remains a compatibility mode.
  • Thinking/reasoning content is derived from LangChain content blocks after the response is available; callback-only concurrent reasoning streaming is not currently possible.
  • The backend contract is agentFactory({ input, middleware }), not the older frozen { agent } shape. This is intentional because LangChain middleware is attached at agent construction time.
  • Repo-level package builds should use bun run --filter @skroyc/ag-ui-middleware-callbacks build.