@waniwani/sdk 0.9.8 → 0.9.10

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.
package/README.md CHANGED
@@ -3,26 +3,28 @@
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
+ > The official SDK for [WaniWani](https://waniwani.ai). Build, ship, and measure conversational MCP apps.
7
7
 
8
- `@waniwani/sdk` is the developer-facing library that plugs into your MCP (Model Context Protocol) server and gives you **event tracking** and **multi-step conversational flows** out of the box.
8
+ `@waniwani/sdk` is the developer-facing library for your MCP (Model Context Protocol) server. It provides **event tracking** and **multi-step conversational flows**.
9
9
 
10
- - **Zero runtime dependencies** — sub-5KB bundle, safe for serverless and edge runtimes.
11
- - **Works with any MCP runtime** [Skybridge](https://github.com/alpic-ai/skybridge), [`@modelcontextprotocol/sdk`](https://www.npmjs.com/package/@modelcontextprotocol/sdk), [`@vercel/mcp-handler`](https://www.npmjs.com/package/@vercel/mcp-handler).
12
- - **Fully typed** Zod-powered state schemas, inferred node contexts, typed event properties.
13
- - **Automatic tool tracking** one line wraps your server and every tool call ships to your dashboard.
14
- - **LangGraph-inspired flows** compile a state graph into a single MCP tool that drives multi-turn conversations.
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.
15
15
 
16
- > **Status:** pre-alpha. APIs and behaviour may change between releases pin versions in production.
16
+ > **Status:** pre-alpha. APIs and behavior may change between releases. Pin versions in production.
17
17
 
18
18
  ## Install
19
19
 
20
20
  ```bash
21
- npm install @waniwani/sdk
21
+ bun add @waniwani/sdk
22
22
  # or
23
23
  pnpm add @waniwani/sdk
24
24
  # or
25
- bun add @waniwani/sdk
25
+ npm install @waniwani/sdk
26
+ # or
27
+ yarn add @waniwani/sdk
26
28
  ```
27
29
 
28
30
  Requires Node 18.17+ and an MCP server runtime.
@@ -31,35 +33,40 @@ Requires Node 18.17+ and an MCP server runtime.
31
33
 
32
34
  ### 1. Get an API key
33
35
 
34
- Sign in to [app.waniwani.ai](https://app.waniwani.ai), create an MCP environment, and copy its API key. Expose it to your server as `WANIWANI_API_KEY`:
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`:
35
37
 
36
38
  ```bash
37
39
  # .env
38
- WANIWANI_API_KEY=ww_live_...
40
+ WANIWANI_API_KEY=wwk_...
39
41
  ```
40
42
 
41
43
  ### 2. Wrap your MCP server
42
44
 
43
45
  ```ts
44
- import { waniwani } from "@waniwani/sdk";
46
+ import express from "express";
45
47
  import { withWaniwani } from "@waniwani/sdk/mcp";
46
- import { McpServer } from "skybridge/server";
48
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
49
+ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
47
50
  import "dotenv/config";
48
51
 
49
- const server = new McpServer(
50
- { name: "my-mcp-app", version: "0.0.1" },
51
- { capabilities: {} },
52
- );
52
+ const server = new McpServer({ name: "my-mcp-app", version: "0.0.1" });
53
53
 
54
54
  server.registerTool(/* ... your tools ... */);
55
55
 
56
- // One line every registered tool is now tracked automatically.
57
- withWaniwani(server, { client: waniwani() });
56
+ // One call. Every registered tool is now tracked automatically.
57
+ withWaniwani(server);
58
58
 
59
- server.run();
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);
60
67
  ```
61
68
 
62
- Every tool call produces a `tool.called` event with duration, status, input/output, and session correlation all visible in your WaniWani dashboard within seconds.
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.
63
70
 
64
71
  ### 3. Track custom events
65
72
 
@@ -111,11 +118,11 @@ export const onboardingFlow = createFlow({
111
118
  await onboardingFlow.register(server);
112
119
  ```
113
120
 
114
- The engine handles state persistence, resumption, branching, and validation. The model just calls one tool everything else is managed server-side.
121
+ The engine handles state persistence, resumption, branching, and validation. The model calls one tool and the rest is managed server-side.
115
122
 
116
123
  ## Documentation
117
124
 
118
- Full product documentation lives at **[docs.waniwani.ai](https://docs.waniwani.ai)** (powered by Mintlify):
125
+ Full product documentation lives at **[docs.waniwani.ai](https://docs.waniwani.ai)**:
119
126
 
120
127
  - [Introduction](https://docs.waniwani.ai/introduction)
121
128
  - [Quickstart](https://docs.waniwani.ai/quickstart)
@@ -132,22 +139,22 @@ The same docs are also available in this repository under [`docs/`](./docs).
132
139
  | `@waniwani/sdk` | `waniwani()` client: event tracking, identify, flush, shutdown. |
133
140
  | `@waniwani/sdk/mcp` | `withWaniwani`, `createFlow`, `createTool`, `createResource`, flow primitives. |
134
141
  | `@waniwani/sdk/mcp/react` | React hooks for WaniWani-powered widgets. |
135
- | `@waniwani/sdk/chat` | Chat UI components for embedding conversations. |
136
- | `@waniwani/sdk/kb` | Knowledge base client. |
137
142
 
138
143
  Most users only need `@waniwani/sdk` and `@waniwani/sdk/mcp`.
139
144
 
140
145
  ## Examples
141
146
 
142
- - **[Alpic x WaniWani demo](https://github.com/alpic-ai/apps-sdk-template)** a Skybridge MCP server with a full `createFlow` booking journey.
147
+ - **[Alpic x WaniWani demo](https://github.com/WaniWani-AI/alpic-x-waniwani-demo)**: a Skybridge MCP server with a full `createFlow` booking journey.
143
148
 
144
149
  ## Links
145
150
 
146
- - **Website** [waniwani.ai](https://waniwani.ai)
147
- - **Dashboard** [app.waniwani.ai](https://app.waniwani.ai)
148
- - **Docs** [docs.waniwani.ai](https://docs.waniwani.ai)
149
- - **Issues** [github.com/WaniWani-AI/sdk/issues](https://github.com/WaniWani-AI/sdk/issues)
151
+ - **Website**: [waniwani.ai](https://waniwani.ai)
152
+ - **Dashboard**: [app.waniwani.ai](https://app.waniwani.ai)
153
+ - **Docs**: [docs.waniwani.ai](https://docs.waniwani.ai)
154
+ - **Issues**: [github.com/WaniWani-AI/sdk/issues](https://github.com/WaniWani-AI/sdk/issues)
150
155
 
151
156
  ## License
152
157
 
153
- [MIT](./LICENSE) © WaniWani
158
+ [AGPL-3.0-or-later](./LICENSE) © WaniWani
159
+
160
+ "WaniWani" is a trademark of WaniWani. The license covers the code, not the name.
@@ -250,6 +250,15 @@ type ModelContextUpdate = {
250
250
  structuredContent?: Record<string, unknown>;
251
251
  };
252
252
 
253
+ /**
254
+ * Per-tool definition metadata, keyed by tool name. The chat UI caches the
255
+ * MCP `tools/list` response here so widget resolution can happen by tool
256
+ * name (spec-canonical) rather than by inspecting every tool call result.
257
+ */
258
+ type ToolDefinitionsMap = Record<string, {
259
+ _meta?: Record<string, unknown>;
260
+ }>;
261
+
253
262
  type McpAppDisplayMode = "inline" | "pip" | "fullscreen";
254
263
  interface McpAppFrameProps {
255
264
  resourceUri: string;
@@ -295,8 +304,15 @@ interface McpAppFrameProps {
295
304
  onDisplayModeChange?: (mode: McpAppDisplayMode) => void;
296
305
  /** When true, the iframe fills its container (fullscreen mode). */
297
306
  isFullscreen?: boolean;
307
+ /**
308
+ * Cached tool catalog keyed by tool name. Passed through so that
309
+ * follow-up `tools/call` requests from the widget iframe can be
310
+ * correctly classified as widget-producing (spec-canonical definition
311
+ * lookup) vs. plain (result text auto-injected).
312
+ */
313
+ toolDefinitions?: ToolDefinitionsMap;
298
314
  }
299
- declare function McpAppFrame({ resourceUri, toolInput, toolResult, resourceEndpoint, chatSessionId, isDark, className, autoHeight, onOpenLink, onFollowUp, onCallTool, onDisplayModeChange, isFullscreen, }: McpAppFrameProps): react_jsx_runtime.JSX.Element;
315
+ declare function McpAppFrame({ resourceUri, toolInput, toolResult, resourceEndpoint, chatSessionId, isDark, className, autoHeight, onOpenLink, onFollowUp, onCallTool, onDisplayModeChange, isFullscreen, toolDefinitions, }: McpAppFrameProps): react_jsx_runtime.JSX.Element;
300
316
 
301
317
  declare const ChatCard: react.ForwardRefExoticComponent<ChatCardProps & react.RefAttributes<ChatHandle>>;
302
318