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

@kuralle-agents/commerce

v0.11.1

Published

Conversational commerce primitives for Kuralle agents: carts, idempotent orders, catalog contracts

Downloads

822

Readme

@kuralle-agents/commerce

Conversational-commerce primitives for Kuralle agents: typed carts, an idempotent create_order tool, and channel mapping helpers. Tools return data only — flows own the conversation; the messaging layer owns rendering.

What's inside

  • Money / Product / Cart / Order types — integer minor units, never floats.
  • ProductCatalog — the host-implemented product source (your backend, MCP server, or API). createInMemoryCatalog(products) for dev/tests.
  • createCartTools({ catalog }) — durable product_search, cart_add, cart_remove, cart_view tools. The cart lives in flow state (runState.state.__cart), so it persists with the conversation and is visible to flow nodes and validators.
  • createOrderTool({ submit, ledger? }) — idempotent order placement:
    • a content key (hash of session + cart lines) dedupes identical resubmissions across turns — "place my order" twice returns the same order instead of charging twice;
    • in-flight coalescing collapses concurrent submissions;
    • the durable effect log still covers replay of the same call. Provide a durable OrderLedger (Redis/Postgres/DO) in production; the default ledger is in-memory.
  • toWhatsAppProductList(productsOrCart, opts) — renders products as a WhatsApp multi-product message payload, structurally compatible with @kuralle-agents/messaging-meta's client.sendProductList.

Usage

import { defineAgent, defineFlow } from '@kuralle-agents/core';
import {
  createCartTools,
  createOrderTool,
  createInMemoryCatalog,
} from '@kuralle-agents/commerce';

const catalog = createInMemoryCatalog(products); // or your ProductCatalog impl
const cartTools = createCartTools({ catalog });
const createOrder = createOrderTool({
  submit: async ({ items, total, contentKey }) => {
    const order = await myBackend.createOrder({ items, total, idempotencyKey: contentKey });
    return { orderId: order.id };
  },
  ledger: myDurableLedger, // Redis/Postgres in production
});

const agent = defineAgent({
  id: 'shop',
  instructions: 'You help customers order from our store.',
  globalTools: { product_search: cartTools.product_search, cart_view: cartTools.cart_view },
  tools: { cart_add: cartTools.cart_add, cart_remove: cartTools.cart_remove, create_order: createOrder },
  flows: [checkoutFlow], // gate create_order behind an explicit confirm step
});

Showing products natively on WhatsApp (requires a Meta Commerce Manager catalog and retailerId on your products):

import { toWhatsAppProductList } from '@kuralle-agents/commerce';

const results = await catalog.search('chocolate cake');
await whatsapp.sendProductList(
  to,
  toWhatsAppProductList(results, {
    catalogId: META_CATALOG_ID,
    header: 'Our cakes',
    body: 'Tap to view and add to your order.',
  }),
);

Inbound WhatsApp orders (user taps "Add to cart" in the native catalog UI) arrive via parseInboundOrder from @kuralle-agents/messaging-meta/whatsapp.

Design rules honored

  • Tools return data only; confirmation wording comes from flow nodes.
  • Consequential tools (cart_add, create_order) stay flow-gated — never in globalTools.
  • create_order pairs with needsApproval or a flow confirm gate for human-in-the-loop checkout.