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

@muraldevkit/ag-ui-mock

v1.1.0

Published

A scripted AG-UI agent for building and testing agent UIs without a backend

Readme

@muraldevkit/ag-ui-mock

A scripted AG-UI agent for building and testing agent UIs without a backend. MockAgUiAgent extends AbstractAgent from @ag-ui/client and replays a scenario, a plain function that returns the events one run puts on the wire. Because it is a real agent, its events go through the same client checks as a live stream, and assistant-ui's AG-UI runtime (useAgUiRuntime) renders them exactly as it would a backend's reply.

The package has no React or assistant-ui dependency, so it loads in Storybook, in an application's development build and in Node test suites alike. Storybook loaders and decorators live with the chat components.

Usage

npm install --save-dev @muraldevkit/ag-ui-mock
import { MockAgUiAgent, streamingText } from '@muraldevkit/ag-ui-mock';

const agent = new MockAgUiAgent({ scenario: streamingText, streamingDelay: 40 });
// Hand `agent` to useAgUiRuntime({ agent }), or drive it directly with agent.runAgent().

@ag-ui/client is a peer dependency. The package builds its event streams with its own rxjs, but its public types use the client's, so any rxjs 7 works alongside it.

Generic scenarios

| Scenario | What it plays | | --- | --- | | textResponse | A complete reply in a single text event | | streamingText | A longer reply, one text event per word | | reasoningResponse | The model's reasoning, then a reply | | multiStepResponse | A tool call and a reply, each inside a named step | | toolInvocation | A server-side tool call (getWeather) with its result, then a reply in the same message | | clientToolInvocation | A tool the browser must run (clientToolName); once the tool's answer arrives in the next run, a reply that uses it | | errorResponse | A reply cut off by a run error while its message is still open, as when a backend fails mid-stream | | agentState | Progress reported through a state snapshot and state deltas, alongside a reply | | interruptApproval | A tool call (approvalToolName) the user must approve: the run ends on a tool_call interrupt, and the next run, whose resume input answers it, runs the tool or declines | | restoredThread | A MESSAGES_SNAPSHOT of an earlier exchange, for connectScenario |

The scenarios map holds the run scenarios any chat UI can play, for a Storybook select control. It leaves out interruptApproval, which needs a UI that answers interrupts, and restoredThread, which is a connect scenario. Product-specific scenarios belong in the application that owns the tools and data.

Writing a scenario

A scenario receives the run's input (the conversation so far, the tools the application registered, the agent state, and any resume answers) and a runIndex (0 for the first run on this agent instance). It returns any iterable of steps; the builders return arrays of steps to spread or pass to run().

import { run, text, toolCall, type Scenario } from '@muraldevkit/ag-ui-mock';

export const findDocuments: Scenario = ({ input, runIndex }) =>
	run(
		input,
		toolCall('searchDocuments', { query: 'roadmap' }, { result: { count: 2 } }),
		text(runIndex === 0 ? 'I found two documents.' : 'Still two documents.')
	);

| Builder | Produces | | --- | --- | | run(input, ...parts) | RUN_STARTED, the parts, RUN_FINISHED | | runError(input, { message, code? }, ...parts) | RUN_STARTED, the parts, RUN_ERROR | | runInterrupt(input, interrupts, ...parts) | RUN_STARTED, the parts, RUN_FINISHED with an interrupt outcome. The next run must answer every interrupt in its resume input, or the client refuses to start it | | text(content, { messageId?, split?, end? }) | One assistant text message, split per word unless split: 'none'. end: false leaves it open | | reasoning(content, { messageId?, split? }) | One reasoning message inside a reasoning span | | toolCall(name, args?, { result?, toolCallId?, parentMessageId? }) | A tool call; with result, the tool's result too. Omit result for a tool the browser answers. parentMessageId names the assistant message the call belongs to | | toolResult(toolCallId, result) | A tool result on its own, for a call made in an earlier run | | runStep(stepName, ...parts) | STEP_STARTED, the parts, STEP_FINISHED | | stateSnapshot(snapshot), stateDelta(patch) | STATE_SNAPSHOT, and STATE_DELTA with a JSON Patch | | messagesSnapshot(messages) | MESSAGES_SNAPSHOT, which replaces the conversation | | wait(ms) | A pause before the next event (timer pacing only) |

Tool arguments and results that are strings are sent as written, and anything else as JSON, the way assistant-ui encodes the results of the tools it runs. Arguments default to {}. A value JSON cannot carry (undefined, a function or a symbol) throws instead of sending an event with no content; use null for a tool that returns nothing. Generated message and tool call ids are random, so they never collide with another run's or with messages an application seeded. Write events by hand when a builder does not fit; ScenarioStep is typed as the AG-UI event union, so each event's fields are checked.

A reply that opens with a tool call should name the message it belongs to: give the call a parentMessageId, and the text that follows the same id as its messageId, as toolInvocation does. Make the id unique to the run, as the generated ones are. Without it, assistant-ui gives the reply a temporary id until the text arrives, then replaces the reply, which resets any state its components hold.

Pacing

  • Timer (default): events are emitted on setTimeout, streamingDelay milliseconds apart, plus any wait() pauses. Use it for stories people watch.
  • Manual: nothing is emitted until agent.step(count) or agent.flush() asks. wait() pauses are ignored. Use it for tests and for stories that must freeze at the same point on every load.

A run ends as soon as its scenario runs out of steps, so runAgent() resolves on the last event rather than a tick or a step() later. Each run keeps its own pacing, timer and requested events, so overlapping runs never drive or stop each other by accident.

  • step(count) emits the next count events of the oldest manually paced run in progress, and flush() emits all the rest of it. A run is in progress from the moment runAgent() is called, so calling step() right after runAgent() works even though the client subscribes a moment later. With no manual run in progress, both throw instead of holding the request for a later run. count must be a positive whole number.
  • abortRun() stops every run in progress the way aborting an HttpAgent's request does. It is what assistant-ui calls when someone presses Stop, and before it starts a run that replaces the current one. A stopped run takes no more steps, so a step() that follows drives the next run.
    • A run that is streaming gets a RUN_ERROR event with the code abort and then completes, so onRunErrorEvent fires, onRunFailed does not, and runAgent() resolves.
    • A run runAgent() has started but the client has not subscribed to yet fails with an AbortError once it does, like a request aborted before its response arrives. The client calls onRunFailed and still resolves runAgent().
  • A scenario that throws, including a generator that throws partway through, fails the run the way a broken stream would. So does a step that is neither an event nor a wait() pause, such as a builder's array yielded where the generator meant yield*.
  • A generator scenario's finally blocks run when its run ends early, whether it was stopped, detached or rejected by the client, as they do when a for...of loop is left early.

Recording and reconnecting

agent.runInputs records the inputs the runtime sent, oldest first, so tests can assert on the messages, tools and state of each run. It keeps the latest 50; set maxRunInputs to change that.

Pass a connectScenario to support connectAgent(), which a runtime calls to rejoin a thread, for example to replay its history with restoredThread. Without one, the agent does not implement connect(), like most agents, and assistant-ui keeps using abortRun() when the user leaves or switches threads. A reconnection follows the agent's pacing like any run: under manual pacing, the history does not appear until step() or flush().

Rules the AG-UI client enforces

A scenario that breaks these fails the way a malformed backend stream would.

  • A run opens with RUN_STARTED (or, for a run that fails at once, RUN_ERROR).
  • Text content and tool call arguments need an open message or tool call.
  • RUN_FINISHED is rejected while a text message, reasoning message, step or tool call is still open, so close each one first. run() does not close them for you. RUN_ERROR may arrive while one is open.
  • Nothing may follow RUN_ERROR.
  • Leave optional fields out rather than setting them to null; the client converts some null fields with a deprecation warning and fails the run on others.

A stream that ends without RUN_FINISHED is accepted by the client, but assistant-ui marks the reply as failed ("The connection ended before the answer finished.").

Browser support

The mock cannot load without @ag-ui/client, so the client sets the browser floor; the package has no browser test matrix of its own. The build adds no polyfills, and ESLint keeps two things that have broken older Safari out of the shipped code: regex lookbehind (a syntax error before Safari 16.4) and Array.prototype.at() (missing before Safari 15.4).

Scripts

npm run build -w @muraldevkit/ag-ui-mock      # ESM, CommonJS and type declarations into dist/, then scripts/smoke-test.mjs loads them
npm run lint -w @muraldevkit/ag-ui-mock
npm run test -w @muraldevkit/ag-ui-mock       # every scenario through the real AG-UI client
npm run typecheck -w @muraldevkit/ag-ui-mock