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

@the-chocolate-factory/sdk

v0.2.0

Published

Official SDK for the Chocolate Factory AI Platform – embed agents, stream responses, and build AI-powered experiences in any framework

Readme

🍫 Chocolate Factory SDK

The official JavaScript/TypeScript SDK for the Chocolate Factory AI platform.

Embed AI agents into any web application in minutes — beautiful chat widgets, streaming responses, tool execution display, and a clean programmatic API for backend automation.


Features

  • 💬 Chat Widget – drop a polished floating chat panel into any page with one line
  • 🌊 Streaming – real-time token-by-token responses with live typing indicators
  • 🛠 Tool Execution Display – animated pills that show agent tool calls as they happen
  • Agent Execution – call any agent as a function (run) or async generator (stream)
  • 🎨 Fully Themeable – CSS custom properties, colour picker, font, radius, z-index
  • 📦 Framework-agnostic – works with React, Vue, Svelte, Angular, plain HTML, or Node.js
  • 🔒 Zero dependencies – no third-party runtime deps; ships as ESM + UMD

Installation

npm install @the-chocolate-factory/sdk
# or
pnpm add @the-chocolate-factory/sdk
# or
yarn add @the-chocolate-factory/sdk

CDN (no bundler)

<script src="https://unpkg.com/@the-chocolate-factory/sdk/dist/index.js"></script>

Quick Start

1. Embed a chat widget

import ChocolateFactory from "@the-chocolate-factory/sdk";

const cf = new ChocolateFactory({
  apiKey: "agk_xxx",           // Agent Key from Chocolate Factory
  agentId: "support-agent",    // Your agent ID
  baseUrl: "https://cf.example.com",
});

cf.chat.mount("#app");         // That's it 🎉

2. Customise the look

cf.chat.mount("#app", {
  title: "Acme Support",
  avatarUrl: "/acme-bot.png",
  welcomeMessage: "Hi! I'm here to help with your order.",
  theme: {
    primaryColor: "#7c3aed",
    borderRadius: 12,
  },
  position: "bottom-right",
});

3. HTML attribute API (zero JS needed)

<cf-chat-widget
  api-key="agk_xxx"
  agent-id="support-agent"
  base-url="https://cf.example.com"
  title="Support Bot"
  primary-color="#3b82f6"
></cf-chat-widget>

<script src="https://unpkg.com/@the-chocolate-factory/sdk/dist/index.js"></script>
<script>ChocolateFactory.registerChatWidget();</script>

4. Call an agent as a function

const result = await cf.agent.run({
  message: "Analyze this customer",
  vars: { customer: customerData },
});
console.log(result.text);

5. Stream an agent response

for await (const chunk of cf.agent.stream({ message: "Write a summary" })) {
  process.stdout.write(chunk);
}

5b. Call an agent from Node.js (API routes, server components, scripts)

The main @the-chocolate-factory/sdk entry point bundles the browser-only chat widget (a custom element that extends HTMLElement), so importing it in Node.js throws ReferenceError: HTMLElement is not defined. Use the /server entry point instead — it only exports AgentClient, ChatClient, and shared types, with no DOM dependency:

import { AgentClient } from "@the-chocolate-factory/sdk/server";

const agent = new AgentClient({
  apiKey: process.env.CF_API_KEY!,
  agentId: "support-agent",
  baseUrl: process.env.CF_BASE_URL!,
});

const result = await agent.run({ message: "Summarize this ticket" });
console.log(result.text);

6. Programmatic chat with events

const chat = cf.chat;

chat.on("message-chunk", (e) => appendToken(e.chunk ?? ""));
chat.on("message-end",   (e) => console.log("Done:", e.message));
chat.on("tool-start",    (e) => showBadge(e.tool?.name ?? ""));

await chat.send({ text: "What's my order status?" });

API Reference

new ChocolateFactory(config)

| Option | Type | Required | Description | |---|---|---|---| | apiKey | string | ✅ | Agent Key (agk_…) | | agentId | string | ✅ | Target agent ID | | baseUrl | string | ✅ | Your Chocolate Factory deployment URL | | agentPayload | Record<string, string \| number \| boolean> | – | Headers forwarded to MCP integrations |

cf.chatChatClient

| Method | Description | |---|---| | .send(options) | Send a message and stream the response | | .on(event, listener) | Subscribe to a chat event | | .off(event, listener) | Unsubscribe | | .mount(selector, options?) | Mount the chat widget | | .messages | Current message history | | .clearHistory() | Wipe local history |

cf.agentAgentClient

| Method | Description | |---|---| | .run(options) | Execute the agent, return { text, usage, finishReason } | | .stream(options) | Execute the agent, return an async generator of text chunks |


Documentation

Full docs in the docs/ folder:


Examples

| Example | Location | |---|---| | Vanilla HTML widget | examples/chat-widget/ | | Node.js agent execute | examples/agent-execute/ | | Node.js agent stream | examples/agent-stream/ |


Package output

dist/
  index.esm.js   ← ES Module (import) – full SDK incl. chat widget, browser only
  index.js       ← UMD (require / <script>) – full SDK incl. chat widget, browser only
  index.d.ts     ← TypeScript declarations
  server.esm.js  ← ES Module (import) – AgentClient + ChatClient only, Node-safe
  server.cjs     ← CommonJS (require) – AgentClient + ChatClient only, Node-safe
  server.d.ts    ← TypeScript declarations
  *.d.ts         ← Per-module declarations
  *.map          ← Source maps

Building from source

pnpm install
pnpm build

License

MIT