@waniwani/sdk 0.11.11 → 0.11.12

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 +92 -93
  2. package/dist/chat/embed.js +51 -51
  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 +1 -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,91 +3,33 @@
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 MCP funnels. Build sales funnels, lead generation, booking, insurance quote, and pricing quote flows on top of your MCP server. Free hosted tier for analytics, knowledge base, and chat.
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
+ `@waniwani/sdk` turns your MCP server into a distribution surface. Build:
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
+ - **Sales funnels and lead generation** — qualify leads, capture intent, route to the right step. Multi-step conversations compiled into a single MCP tool.
11
+ - **Booking and reservation flows** collect what you need, branch on conditions, confirm.
12
+ - **Quote flows** (insurance, pricing, custom) — gather inputs, call your pricing API, return a quote, optionally render a widget.
13
+ - **Knowledge base and embedded chat** ground answers in your docs, ship a chat widget for your site.
15
14
 
16
- > **Status:** pre-alpha. APIs and behavior may change between releases. Pin versions in production.
15
+ The SDK is split into two tiers:
17
16
 
18
- ## Install
17
+ - **Open source** — `createFlow` and the `KvStore` interface. LangGraph-inspired multi-step conversations, compiled into a single MCP tool. No API key needed. Plug in any state backend (in-memory, Redis, Upstash, Cloudflare KV) — or run pure self-hosted.
18
+ - **Free tier** — add `WANIWANI_API_KEY` for hosted flow state, event tracking, funnel analytics, knowledge base, and a local playground. One env var. Same code.
19
19
 
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.
20
+ A separate [legacy section](#legacy) holds APIs we still ship for back-compat (`createTool`, `createResource`, chat-server adapters, MCP-widget React hooks) but no longer document for new code.
31
21
 
32
- ## Quick start
22
+ > **Status:** pre-alpha. APIs may change between releases. Pin versions in production.
33
23
 
34
- ### 1. Get an API key
35
-
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`:
24
+ ## Quick start open source (no API key)
37
25
 
38
26
  ```bash
39
- # .env
40
- WANIWANI_API_KEY=wwk_...
41
- ```
42
-
43
- ### 2. Wrap your MCP server
44
-
45
- ```ts
46
- import express from "express";
47
- import { withWaniwani } from "@waniwani/sdk/mcp";
48
- 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);
62
-
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);
67
- ```
68
-
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
- });
27
+ bun add @waniwani/sdk
83
28
  ```
84
29
 
85
- ### 4. Build a flow
86
-
87
- Multi-turn conversations, compiled into a single MCP tool:
88
-
89
30
  ```ts
90
- import { createFlow, END, START } from "@waniwani/sdk/mcp";
31
+ // flow.ts
32
+ import { createFlow, END, MemoryKvStore, START } from "@waniwani/sdk/mcp";
91
33
  import { z } from "zod";
92
34
 
93
35
  export const onboardingFlow = createFlow({
@@ -99,10 +41,10 @@ export const onboardingFlow = createFlow({
99
41
  useCase: z.string().describe("What they want to build"),
100
42
  },
101
43
  })
102
- .addNode("ask_email", async ({ interrupt }) =>
44
+ .addNode("ask_email", () =>
103
45
  interrupt({ email: { question: "What's your work email?" } }),
104
46
  )
105
- .addNode("ask_use_case", async ({ interrupt }) =>
47
+ .addNode("ask_use_case", () =>
106
48
  interrupt({
107
49
  useCase: {
108
50
  question: "What do you want to build?",
@@ -113,38 +55,95 @@ export const onboardingFlow = createFlow({
113
55
  .addEdge(START, "ask_email")
114
56
  .addEdge("ask_email", "ask_use_case")
115
57
  .addEdge("ask_use_case", END)
116
- .compile();
58
+ .compile({ store: new MemoryKvStore() });
117
59
 
118
60
  await onboardingFlow.register(server);
119
61
  ```
120
62
 
121
- The engine handles state persistence, resumption, branching, and validation. The model calls one tool and the rest is managed server-side.
63
+ `MemoryKvStore` is fine for local dev and tests. For self-hosted production, implement the [`KvStore`](src/mcp/server/kv/kv-store.ts) interface against Redis, Upstash, Cloudflare KV, DynamoDB anything with `get` / `set` / `delete`.
64
+
65
+ ## Quick start — free tier (with API key)
66
+
67
+ ```bash
68
+ bun add @waniwani/sdk
69
+ export WANIWANI_API_KEY=wwk_...
70
+ ```
71
+
72
+ The same flow works with zero code changes — drop the `store` argument and state lives on `app.waniwani.ai`, plus you get tracking, funnel, and the dashboard.
73
+
74
+ ```ts
75
+ const onboardingFlow = createFlow({ /* ...same config... */ })
76
+ // ...same nodes and edges...
77
+ .compile(); // no store → uses hosted flow state
78
+ ```
79
+
80
+ Want event tracking too?
81
+
82
+ ```ts
83
+ import { waniwani } from "@waniwani/sdk";
84
+ import { withWaniwani } from "@waniwani/sdk/mcp";
85
+
86
+ // Auto-track every tool call:
87
+ withWaniwani(server);
88
+
89
+ // Or track custom events:
90
+ const wani = waniwani();
91
+ await wani.track({
92
+ event: "quote.succeeded",
93
+ properties: { amount: 99, currency: "USD" },
94
+ meta: extra._meta,
95
+ });
96
+ ```
97
+
98
+ Get an API key at [app.waniwani.ai](https://app.waniwani.ai).
99
+
100
+ ## What's in each tier
101
+
102
+ | Surface | Tier | What you get |
103
+ |---|---|---|
104
+ | `createFlow`, `StateGraph`, `KvStore`, `MemoryKvStore` | **OSS** | Multi-step conversational flows, runnable with no API key |
105
+ | `WaniwaniKvStore` | Free tier | Hosted flow state on `app.waniwani.ai` |
106
+ | `withWaniwani` | Both | Tool tracking + session bridging (no-op without an API key) |
107
+ | `waniwani()`, `tracking`, `kb`, `createTrackingRoute` | Free tier | Event tracking, knowledge base, funnel routing |
108
+ | `ChatWidget`, `ChatEmbed`, themes, `embed.js` | Free tier | Embeddable chat UI |
109
+ | `useWaniwani` | Both | React hook for browser-side tracking (no-op until configured) |
110
+
111
+ ## Package entry points
112
+
113
+ | Entry point | Use it for |
114
+ |---|---|
115
+ | `@waniwani/sdk` | `waniwani()` client, `defineConfig`, `WaniWaniError` |
116
+ | `@waniwani/sdk/mcp` | `createFlow`, `KvStore`, `MemoryKvStore`, `withWaniwani`, tracking helpers |
117
+ | `@waniwani/sdk/mcp/react` | `useWaniwani` (the only non-legacy hook here) |
118
+ | `@waniwani/sdk/chat` | `ChatWidget`, `ChatBar`, `ChatCard`, `ChatEmbed`, themes |
119
+ | `@waniwani/sdk/chat/embed.js` | Self-contained `<script>` install for any website |
120
+ | `@waniwani/sdk/chat/styles.css` | Prebuilt Tailwind styles for `chat/` components |
121
+ | `@waniwani/sdk/kb` | `createKbClient` for knowledge base ingest/search |
122
122
 
123
123
  ## Documentation
124
124
 
125
- Full product documentation lives at **[docs.waniwani.ai](https://docs.waniwani.ai)**:
125
+ Full docs at **[docs.waniwani.ai](https://docs.waniwani.ai)** — same source as [`./docs/`](./docs) in this repo.
126
126
 
127
- - [Introduction](https://docs.waniwani.ai/introduction)
127
+ - [Introduction](https://docs.waniwani.ai/introduction) — tiers and pitch
128
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
129
  - [Flows](https://docs.waniwani.ai/flows/overview)
130
+ - [KV store adapters](https://docs.waniwani.ai/flows/kv-store)
131
+ - [Self-hosting](https://docs.waniwani.ai/flows/self-hosting)
132
+ - [Tracking](https://docs.waniwani.ai/tracking/overview)
133
+ - [Knowledge base](https://docs.waniwani.ai/knowledge-base/overview)
132
134
 
133
- The same docs are also available in this repository under [`docs/`](./docs).
134
-
135
- ## What's inside the package
136
-
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. |
135
+ ## Legacy
142
136
 
143
- Most users only need `@waniwani/sdk` and `@waniwani/sdk/mcp`.
137
+ The following exports are preserved for back-compat with existing customer MCPs but are no longer documented. New code should use `createFlow` instead. They will move to dedicated `@waniwani/sdk/legacy*` entry points in a future minor release.
144
138
 
145
- ## Examples
139
+ - `createTool`, `createResource`, `registerTools` from `@waniwani/sdk/mcp`
140
+ - `toNextJsHandler` from `@waniwani/sdk/next-js`
141
+ - `toExpressJsHandler` from `@waniwani/sdk/express-js`
142
+ - `createApiHandler` from `@waniwani/sdk/chat/server`
143
+ - `WidgetProvider`, `useWidgetClient`, `useDisplayMode`, `useToolOutput`, etc. from `@waniwani/sdk/mcp/react`
144
+ - `InitializeNextJsInIframe`, `LoadingWidget`, `DevModeProvider`
146
145
 
147
- - **[Alpic x WaniWani demo](https://github.com/WaniWani-AI/alpic-x-waniwani-demo)**: a Skybridge MCP server with a full `createFlow` booking journey.
146
+ See the [Legacy docs section](https://docs.waniwani.ai/legacy/tools-resources) for migration notes.
148
147
 
149
148
  ## Links
150
149