@waniwani/sdk 0.11.11 → 0.11.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +78 -112
  2. package/dist/chat/embed.js +65 -65
  3. package/dist/chat/embed.js.map +1 -1
  4. package/dist/chat/express-js/index.d.ts +8 -1
  5. package/dist/chat/express-js/index.js.map +1 -1
  6. package/dist/chat/index.d.ts +9 -22
  7. package/dist/chat/index.js +7 -7
  8. package/dist/chat/index.js.map +1 -1
  9. package/dist/chat/next-js/index.d.ts +5 -3
  10. package/dist/chat/next-js/index.js.map +1 -1
  11. package/dist/chat/server/index.js +1 -1
  12. package/dist/chat/server/index.js.map +1 -1
  13. package/dist/chat/styles.css +1 -1
  14. package/dist/{chunk-DGSC74SV.js → chunk-DP6SAQTK.js} +1 -1
  15. package/dist/chunk-DP6SAQTK.js.map +1 -0
  16. package/dist/{chunk-5OQXAEHG.js → chunk-RZKVTH7F.js} +1 -1
  17. package/dist/chunk-RZKVTH7F.js.map +1 -0
  18. package/dist/legacy/chat/express-js/index.d.ts +407 -0
  19. package/dist/legacy/chat/express-js/index.js +10 -0
  20. package/dist/legacy/chat/express-js/index.js.map +1 -0
  21. package/dist/legacy/chat/next-js/index.d.ts +368 -0
  22. package/dist/legacy/chat/next-js/index.js +10 -0
  23. package/dist/legacy/chat/next-js/index.js.map +1 -0
  24. package/dist/legacy/index.d.ts +335 -0
  25. package/dist/legacy/index.js +2 -0
  26. package/dist/legacy/index.js.map +1 -0
  27. package/dist/legacy/mcp/react.d.ts +573 -0
  28. package/dist/legacy/mcp/react.js +68 -0
  29. package/dist/legacy/mcp/react.js.map +1 -0
  30. package/dist/mcp/index.d.ts +1153 -1117
  31. package/dist/mcp/index.js +5 -5
  32. package/dist/mcp/index.js.map +1 -1
  33. package/dist/mcp/react.d.ts +170 -74
  34. package/dist/mcp/react.js +7 -7
  35. package/dist/mcp/react.js.map +1 -1
  36. package/dist/{mcp-apps-client-PUL4H54S.js → mcp-apps-client-OFYMQOI3.js} +1 -1
  37. package/dist/mcp-apps-client-OFYMQOI3.js.map +1 -0
  38. package/dist/{openai-client-QAC3ZD5W.js → openai-client-TZIOCMXP.js} +2 -2
  39. package/dist/openai-client-TZIOCMXP.js.map +1 -0
  40. package/dist/platform-LKQFC3AJ.js +3 -0
  41. package/package.json +34 -21
  42. package/dist/chunk-5OQXAEHG.js.map +0 -1
  43. package/dist/chunk-DGSC74SV.js.map +0 -1
  44. package/dist/evals/index.d.ts +0 -156
  45. package/dist/evals/index.js +0 -2
  46. package/dist/evals/index.js.map +0 -1
  47. package/dist/evals/scorers.d.ts +0 -92
  48. package/dist/evals/scorers.js +0 -8
  49. package/dist/evals/scorers.js.map +0 -1
  50. package/dist/mcp-apps-client-PUL4H54S.js.map +0 -1
  51. package/dist/openai-client-QAC3ZD5W.js.map +0 -1
  52. package/dist/platform-GKYYQBCS.js +0 -3
  53. /package/dist/{platform-GKYYQBCS.js.map → platform-LKQFC3AJ.js.map} +0 -0
package/README.md CHANGED
@@ -3,148 +3,114 @@
3
3
  [![npm](https://img.shields.io/npm/v/@waniwani/sdk.svg)](https://www.npmjs.com/package/@waniwani/sdk)
4
4
  [![license](https://img.shields.io/npm/l/@waniwani/sdk.svg)](./LICENSE)
5
5
 
6
- > The official SDK for [WaniWani](https://waniwani.ai). Build, ship, and measure conversational MCP apps.
6
+ > Open-source SDK for building **MCP funnels**: sales funnels, lead generation, booking, and quote flows that run as a single MCP tool inside ChatGPT, Claude, Cursor, and any MCP-capable client.
7
7
 
8
- `@waniwani/sdk` is the developer-facing library for your MCP (Model Context Protocol) server. It provides **event tracking** and **multi-step conversational flows**.
8
+ An **MCP funnel** is a multi-step conversation, hosted on your MCP server, that drives a user or agent from intent to outcome (a qualified lead, a booking, a quote, a purchase). One typed state graph compiles to one MCP tool. MIT licensed, bring your own store, optional hosted tier.
9
9
 
10
- - **Zero runtime dependencies.** Sub-5KB core bundle, safe for serverless and edge runtimes.
11
- - **Works with any MCP runtime.** [`@modelcontextprotocol/sdk`](https://www.npmjs.com/package/@modelcontextprotocol/sdk), [Skybridge](https://github.com/alpic-ai/skybridge), [`@vercel/mcp-handler`](https://www.npmjs.com/package/@vercel/mcp-handler).
12
- - **Fully typed.** Zod state schemas, inferred node contexts, typed event properties.
13
- - **Automatic tool tracking.** One call to `withWaniwani(server)` and every tool invocation is tracked.
14
- - **LangGraph-inspired flows.** Compile a state graph into a single MCP tool that drives multi-turn conversations.
10
+ ## Why this exists
15
11
 
16
- > **Status:** pre-alpha. APIs and behavior may change between releases. Pin versions in production.
12
+ - **ChatGPT, Claude, and Cursor are the new browsers. MCP is the store.** One edit to your messaging deploys to every MCP-capable client and your own site.
13
+ - **Conversational funnels are the new web forms.** They are where money will be made in the AI-distribution era. Recreating a real funnel inside MCP is harder than it looks.
14
+ - **LLMs are not built to replicate forms.** Left to themselves, they rush through structured collection: they skip fields, paraphrase questions, and break validation. A real funnel needs deterministic order, typed fields, validation, branching, and resumable state across tool calls.
15
+ - **Generic agent builders are not shaped for funnels.** LangChain and LangGraph are general-purpose. They expose every primitive, leaving you to re-invent funnel ergonomics (interrupts, re-ask on error, auto-skip pre-filled fields, widget cards, deterministic step order) on every project.
16
+ - **`createFlow` is the missing abstraction.** A typed state graph (Zod-typed state, named nodes, direct and conditional edges, interrupts, widget signals) compiles to a single MCP tool. Funnel-shaped by design, not by convention.
17
+ - **Production-validated.** Forked out of internal distribution MCPs we shipped for paying customers (insurance quoting, pet care, lead capture, booking). Open-sourced once we hit the same pattern enough times.
17
18
 
18
- ## Install
19
+ ## What you can build today
19
20
 
20
- ```bash
21
- bun add @waniwani/sdk
22
- # or
23
- pnpm add @waniwani/sdk
24
- # or
25
- npm install @waniwani/sdk
26
- # or
27
- yarn add @waniwani/sdk
28
- ```
29
-
30
- Requires Node 18.17+ and an MCP server runtime.
31
-
32
- ## Quick start
21
+ - **[Sales funnel MCP](https://docs.waniwani.ai/guides/sales-funnel)**. Qualify intent, capture lead data, branch on stage, push to CRM.
22
+ - **[Lead generation MCP](https://docs.waniwani.ai/guides/lead-generation)**. Collect email, role, use case. Webhook to your CRM.
23
+ - **[Booking MCP](https://docs.waniwani.ai/guides/booking)**. Pick a service, check availability, pick a slot, confirm.
24
+ - **[Insurance or pricing quote MCP](https://docs.waniwani.ai/guides/insurance-quote)**. Collect details, validate, call your pricing API, return widget cards.
33
25
 
34
- ### 1. Get an API key
26
+ Any other multi-step MCP tool where order, validation, and resumability matter.
35
27
 
36
- Sign in to [app.waniwani.ai](https://app.waniwani.ai), create an MCP environment, and copy its API key. Keys are prefixed with `wwk_` and shown in full only once. Expose it to your server as `WANIWANI_API_KEY`:
28
+ ## 30-second example
37
29
 
38
30
  ```bash
39
- # .env
40
- WANIWANI_API_KEY=wwk_...
31
+ bun add @waniwani/sdk @modelcontextprotocol/sdk zod
41
32
  ```
42
33
 
43
- ### 2. Wrap your MCP server
44
-
45
34
  ```ts
46
- import express from "express";
47
- import { withWaniwani } from "@waniwani/sdk/mcp";
35
+ // hello.ts
48
36
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
49
- import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
50
- import "dotenv/config";
51
-
52
- const server = new McpServer({ name: "my-mcp-app", version: "0.0.1" });
53
-
54
- server.registerTool(/* ... your tools ... */);
55
-
56
- // One call. Every registered tool is now tracked automatically.
57
- withWaniwani(server);
58
-
59
- // Connect the Streamable HTTP transport
60
- const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
61
- await server.connect(transport);
37
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
38
+ import { createFlow, END, MemoryKvStore, START } from "@waniwani/sdk/mcp";
39
+ import { z } from "zod";
62
40
 
63
- const app = express();
64
- app.use(express.json());
65
- app.post("/mcp", (req, res) => transport.handleRequest(req, res, req.body));
66
- app.listen(3000);
41
+ const flow = createFlow({
42
+ id: "hello",
43
+ title: "Hello World",
44
+ description: "Say hello and ask a question.",
45
+ state: { name: z.string().describe("Your name") },
46
+ })
47
+ .addNode({
48
+ id: "ask",
49
+ run: ({ interrupt }) =>
50
+ interrupt({ name: { question: "What's your name?" } }),
51
+ })
52
+ .addNode({
53
+ id: "greet",
54
+ run: () => ({ greeted: true }),
55
+ })
56
+ .addEdge(START, "ask")
57
+ .addEdge("ask", "greet")
58
+ .addEdge("greet", END)
59
+ .compile({ store: new MemoryKvStore() });
60
+
61
+ const server = new McpServer({ name: "hello-mcp", version: "1.0.0" });
62
+ await flow.register(server);
63
+ await server.connect(new StdioServerTransport());
67
64
  ```
68
65
 
69
- Every tool call produces a `tool.called` event with duration, status, input/output, and session correlation, all visible in your WaniWani dashboard within seconds.
70
-
71
- ### 3. Track custom events
72
-
73
- ```ts
74
- import { waniwani } from "@waniwani/sdk";
75
-
76
- const wani = waniwani();
77
-
78
- await wani.track({
79
- event: "quote.succeeded",
80
- properties: { amount: 99, currency: "USD" },
81
- meta: extra._meta, // correlates the event with the current MCP session
82
- });
66
+ ```bash
67
+ bun run hello.ts
83
68
  ```
84
69
 
85
- ### 4. Build a flow
70
+ That is a complete MCP server with one flow-driven tool, runnable over stdio. Connect it to ChatGPT, Claude, or any MCP client.
86
71
 
87
- Multi-turn conversations, compiled into a single MCP tool:
72
+ For production, swap `MemoryKvStore` for a real backend (Redis, Upstash, Cloudflare KV, DynamoDB, anything with `get` / `set` / `delete`), or set `WANIWANI_API_KEY` for hosted state plus tracking, funnel analytics, knowledge base, and a chat widget. Same code.
88
73
 
89
- ```ts
90
- import { createFlow, END, START } from "@waniwani/sdk/mcp";
91
- import { z } from "zod";
74
+ ## How WaniWani compares
92
75
 
93
- export const onboardingFlow = createFlow({
94
- id: "onboarding",
95
- title: "User Onboarding",
96
- description: "Use when a new user wants to get started.",
97
- state: {
98
- email: z.string().describe("Work email"),
99
- useCase: z.string().describe("What they want to build"),
100
- },
101
- })
102
- .addNode("ask_email", async ({ interrupt }) =>
103
- interrupt({ email: { question: "What's your work email?" } }),
104
- )
105
- .addNode("ask_use_case", async ({ interrupt }) =>
106
- interrupt({
107
- useCase: {
108
- question: "What do you want to build?",
109
- suggestions: ["Analytics", "Support", "Lead capture"],
110
- },
111
- }),
112
- )
113
- .addEdge(START, "ask_email")
114
- .addEdge("ask_email", "ask_use_case")
115
- .addEdge("ask_use_case", END)
116
- .compile();
117
-
118
- await onboardingFlow.register(server);
119
- ```
76
+ **vs. LangChain / LangGraph.** General-purpose agent graphs. WaniWani is funnel-shaped: interrupts, re-ask on validation, auto-skip pre-filled fields, widget delegation, typed state via Zod. Smaller surface, sharper fit for MCP funnels.
120
77
 
121
- The engine handles state persistence, resumption, branching, and validation. The model calls one tool and the rest is managed server-side.
78
+ **vs. hand-rolling on the raw MCP SDK.** You would serialize state through the model on every turn. WaniWani persists state server-side under the session id, so the model carries nothing between calls.
122
79
 
123
- ## Documentation
80
+ **vs. closed-source platform SDKs.** MIT licensed. The flow engine has zero runtime dependency on `app.waniwani.ai`. Bring any KV backend. The hosted tier is opt-in via `WANIWANI_API_KEY` and unlocks tracking, KB, chat widget, and managed flow state without changing your code.
124
81
 
125
- Full product documentation lives at **[docs.waniwani.ai](https://docs.waniwani.ai)**:
82
+ ## Two tiers
126
83
 
127
- - [Introduction](https://docs.waniwani.ai/introduction)
128
- - [Quickstart](https://docs.waniwani.ai/quickstart)
129
- - [Setup](https://docs.waniwani.ai/setup/installation)
130
- - [Event Tracking](https://docs.waniwani.ai/tracking/overview)
131
- - [Flows](https://docs.waniwani.ai/flows/overview)
84
+ | Surface | Tier | What you get |
85
+ |---|---|---|
86
+ | `createFlow`, `StateGraph`, `KvStore`, `MemoryKvStore` | **OSS** | Multi-step conversational flows, runnable with no API key |
87
+ | `WaniwaniKvStore` | Free tier | Hosted, encrypted-at-rest flow state on `app.waniwani.ai` |
88
+ | `withWaniwani`, `useWaniwani` | Both | Tool tracking, session bridging, browser hook (no-op without a key) |
89
+ | `waniwani()`, `tracking`, `kb` | Free tier | Event tracking, funnel analytics, knowledge base |
90
+ | `ChatWidget`, `ChatEmbed`, `embed.js` | Free tier | Embeddable chat UI |
132
91
 
133
- The same docs are also available in this repository under [`docs/`](./docs).
92
+ Get a free key at [app.waniwani.ai](https://app.waniwani.ai).
134
93
 
135
- ## What's inside the package
94
+ ## Documentation
136
95
 
137
- | Entry point | What it gives you |
138
- | ------------------------- | ------------------------------------------------------------------------------ |
139
- | `@waniwani/sdk` | `waniwani()` client: event tracking, identify, flush, shutdown. |
140
- | `@waniwani/sdk/mcp` | `withWaniwani`, `createFlow`, `createTool`, `createResource`, flow primitives. |
141
- | `@waniwani/sdk/mcp/react` | React hooks for WaniWani-powered widgets. |
96
+ Full docs at **[docs.waniwani.ai](https://docs.waniwani.ai)**. Same source as [`./docs/`](./docs) in this repo.
142
97
 
143
- Most users only need `@waniwani/sdk` and `@waniwani/sdk/mcp`.
98
+ **Build something:**
99
+ - [Sales funnel MCP](https://docs.waniwani.ai/guides/sales-funnel)
100
+ - [Lead generation MCP](https://docs.waniwani.ai/guides/lead-generation)
101
+ - [Booking MCP](https://docs.waniwani.ai/guides/booking)
102
+ - [Insurance or pricing quote MCP](https://docs.waniwani.ai/guides/insurance-quote)
144
103
 
145
- ## Examples
104
+ **Learn the engine:**
105
+ - [Quickstart](https://docs.waniwani.ai/quickstart)
106
+ - [Flows overview](https://docs.waniwani.ai/flows/overview)
107
+ - [KV store adapters](https://docs.waniwani.ai/flows/kv-store)
108
+ - [Self-hosting](https://docs.waniwani.ai/deployment/self-hosting)
146
109
 
147
- - **[Alpic x WaniWani demo](https://github.com/WaniWani-AI/alpic-x-waniwani-demo)**: a Skybridge MCP server with a full `createFlow` booking journey.
110
+ **Add the platform:**
111
+ - [Tracking](https://docs.waniwani.ai/tracking/overview)
112
+ - [Knowledge base](https://docs.waniwani.ai/knowledge-base/overview)
113
+ - [Chat widget](https://docs.waniwani.ai/chat/embed)
148
114
 
149
115
  ## Links
150
116
 
@@ -157,4 +123,4 @@ Most users only need `@waniwani/sdk` and `@waniwani/sdk/mcp`.
157
123
 
158
124
  [MIT](./LICENSE) © WaniWani
159
125
 
160
- "WaniWani" is a trademark of WaniWani. The license covers the code, not the name.
126
+ "WaniWani" is a trademark of WaniWani Inc. The license covers the code, not the name.