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

@ag-ui/cloudflare-agents

v0.0.1

Published

AG-UI integration for Cloudflare Agents - Run AI agents on Cloudflare Workers with Durable Objects

Downloads

46

Readme

@ag-ui/cloudflare-agents

AG-UI community integration for Cloudflare Agents. Provides a WebSocket client for connecting to deployed Cloudflare Workers and a server-side adapter for converting Vercel AI SDK v5 streams into AG-UI protocol events.

Components

  • CloudflareAgentsClient -- WebSocket client that connects to deployed Cloudflare Workers and translates their events to AG-UI protocol events.
  • AgentsToAGUIAdapter -- Server-side adapter that converts Vercel AI SDK v5 StreamTextResult into AG-UI events.
  • createSSEResponse / createNDJSONResponse -- Helper functions to stream AG-UI events over HTTP as Server-Sent Events or newline-delimited JSON.

Installation

npm install @ag-ui/cloudflare-agents
# or
pnpm add @ag-ui/cloudflare-agents

Peer Dependencies

  • @ag-ui/client (>=0.0.40)
  • @ag-ui/core (>=0.0.37)
  • ai (^5.0.0) -- Vercel AI SDK v5+
  • @cloudflare/workers-types (>=4.0.0)

Usage

Client: Connect to a Deployed Agent

import { CloudflareAgentsClient } from "@ag-ui/cloudflare-agents";

const agent = new CloudflareAgentsClient({
  url: "wss://your-agent.workers.dev",
});

agent
  .runAgent({
    threadId: "thread-123",
    runId: "run-456",
    messages: [{ role: "user", content: "What's the weather?" }],
  })
  .subscribe({
    next: (event) => {
      switch (event.type) {
        case "TEXT_MESSAGE_CONTENT":
          process.stdout.write(event.delta);
          break;
        case "STATE_SNAPSHOT":
          console.log("State:", event.snapshot);
          break;
        case "TOOL_CALL_START":
          console.log("Calling tool:", event.toolCallName);
          break;
      }
    },
    complete: () => console.log("Done"),
  });

Adapter: Build an Agent with SSE Streaming

import { AgentsToAGUIAdapter, createSSEResponse } from "@ag-ui/cloudflare-agents";
import { streamText } from "ai";
import { openai } from "@ai-sdk/openai";
import { from } from "rxjs";

const adapter = new AgentsToAGUIAdapter();

export default {
  async fetch(request: Request): Promise<Response> {
    const { messages, threadId, runId } = await request.json();

    const stream = streamText({
      model: openai("gpt-4"),
      messages,
    });

    const events$ = from(
      adapter.adaptStreamToAGUI(stream, threadId, runId, messages)
    );

    return createSSEResponse(events$);
  },
};

Adapter: WebSocket Agent with Tools

import { Agent } from "agents";
import { streamText } from "ai";
import { openai } from "@ai-sdk/openai";
import { AgentsToAGUIAdapter } from "@ag-ui/cloudflare-agents";
import { z } from "zod";

export class MyAgent extends Agent {
  private adapter = new AgentsToAGUIAdapter();

  async onMessage(ws: WebSocket, raw: string | ArrayBuffer) {
    const data = typeof raw === "string" ? raw : new TextDecoder().decode(raw);
    const { messages, threadId } = JSON.parse(data);

    const stream = streamText({
      model: openai("gpt-4"),
      messages,
      tools: {
        getWeather: {
          description: "Get current weather",
          parameters: z.object({ location: z.string() }),
          execute: async ({ location }) => ({ temperature: 72, condition: "sunny" }),
        },
      },
    });

    for await (const event of this.adapter.adaptStreamToAGUI(
      stream, threadId, crypto.randomUUID(), messages
    )) {
      ws.send(JSON.stringify(event));
    }
  }
}

Supported AG-UI Events

| Event | Supported | |---|---| | RUN_STARTED / RUN_FINISHED / RUN_ERROR | Yes | | TEXT_MESSAGE_START / CONTENT / END | Yes | | TOOL_CALL_START / ARGS / END | Yes (includes streaming args via tool-input-*) | | TOOL_CALL_RESULT | Yes (including error results) | | REASONING_START / MESSAGE_START / MESSAGE_CONTENT / MESSAGE_END / END | Yes | | STATE_SNAPSHOT | Yes | | MESSAGES_SNAPSHOT | Yes (with tool calls and results) | | STEP_STARTED / STEP_FINISHED | Yes | | RAW | Yes (adapter: AI SDK raw parts; client: unknown CF event types) | | CUSTOM | Yes (adapter: source/file parts; client: CUSTOM CF events) | | STATE_DELTA | Not yet | | ACTIVITY_SNAPSHOT / ACTIVITY_DELTA | Not yet | | REASONING_ENCRYPTED_VALUE | Not yet | | Interrupt / Resume | Not yet | | Subgraph support | Not yet |

Not Yet Supported

  • STATE_DELTA -- Requires application-level state diffing (JSON Patch RFC 6902) against previous state; currently only full STATE_SNAPSHOT is emitted.
  • ACTIVITY_SNAPSHOT / ACTIVITY_DELTA -- Requires application-level activity tracking.
  • REASONING_ENCRYPTED_VALUE -- Depends on the provider exposing encrypted reasoning signatures.
  • Interrupt/resume -- Requires Cloudflare Agents SDK checkpointing support for pausing and resuming agent runs.
  • Subgraph support -- This is a LangGraph-specific concept and does not apply to the Cloudflare Agents architecture.

Requirements

  • Vercel AI SDK v5+ (uses the fullStream API)
  • Cloudflare Workers runtime (for deployment)
  • Node.js 18+ or modern browser (for the client)

License

MIT