@waniwani/sdk 0.0.2
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/LICENSE +21 -0
- package/README.md +115 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 WaniWani, Inc. and contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# @waniwani
|
|
2
|
+
|
|
3
|
+
SDK for [app.waniwani.ai](https://app.waniwani.ai) - MCP event tracking and tools.
|
|
4
|
+
|
|
5
|
+
## Warning
|
|
6
|
+
|
|
7
|
+
This is **pre-alpha** software. Here's what that means:
|
|
8
|
+
|
|
9
|
+
- Everything will break
|
|
10
|
+
- APIs will change without notice
|
|
11
|
+
- We will not apologize
|
|
12
|
+
|
|
13
|
+
If you're not comfortable with that, wait for v1.0.
|
|
14
|
+
|
|
15
|
+
## What is WaniWani?
|
|
16
|
+
|
|
17
|
+
[WaniWani](https://app.waniwani.ai) is the Shopify of MCP servers — enabling quote-based businesses that sell complex services to deploy AI agents that capture leads, qualify customers, and generate quotes.
|
|
18
|
+
|
|
19
|
+
This SDK is how you track events and interactions in your MCP server.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @waniwani
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { waniwani } from "@waniwani";
|
|
31
|
+
|
|
32
|
+
const client = waniwani({
|
|
33
|
+
apiKey: "your-api-key", // or use WANIWANI_API_KEY env var
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Track a tool call
|
|
37
|
+
await client.track({
|
|
38
|
+
eventType: "tool.called",
|
|
39
|
+
sessionId: "session-123",
|
|
40
|
+
toolName: "pricing",
|
|
41
|
+
toolType: "pricing",
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Get or create session from MCP metadata
|
|
45
|
+
const sessionId = await client.getOrCreateSession(extra?._meta);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## API
|
|
49
|
+
|
|
50
|
+
### `waniwani(config?)`
|
|
51
|
+
|
|
52
|
+
Creates a WaniWani client.
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const client = waniwani({
|
|
56
|
+
apiKey: "...", // defaults to WANIWANI_API_KEY env var
|
|
57
|
+
baseUrl: "...", // defaults to https://app.waniwani.ai
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### `client.track(event)`
|
|
62
|
+
|
|
63
|
+
Track an event. Returns `{ eventId: string }`.
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
await client.track({
|
|
67
|
+
eventType: "tool.called",
|
|
68
|
+
sessionId: "session-123",
|
|
69
|
+
toolName: "pricing",
|
|
70
|
+
toolType: "pricing",
|
|
71
|
+
metadata: { custom: "data" },
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**Event Types:**
|
|
76
|
+
|
|
77
|
+
| Event Type | Description | Additional Fields |
|
|
78
|
+
| -------------------- | -------------------------- | ---------------------------------------- |
|
|
79
|
+
| `session.started` | New session began | - |
|
|
80
|
+
| `tool.called` | MCP tool was invoked | `toolName?`, `toolType?` |
|
|
81
|
+
| `quote.requested` | Quote was requested | - |
|
|
82
|
+
| `quote.succeeded` | Quote completed | `quoteAmount?`, `quoteCurrency?` |
|
|
83
|
+
| `quote.failed` | Quote failed | - |
|
|
84
|
+
| `link.clicked` | User clicked a link | `linkUrl?` |
|
|
85
|
+
| `purchase.completed` | Purchase was completed | `purchaseAmount?`, `purchaseCurrency?` |
|
|
86
|
+
|
|
87
|
+
**Tool Types:** `pricing`, `product_info`, `availability`, `support`, `other`
|
|
88
|
+
|
|
89
|
+
**Base Event Fields:**
|
|
90
|
+
|
|
91
|
+
- `sessionId` (required): Session identifier
|
|
92
|
+
- `externalUserId?`: Your user identifier
|
|
93
|
+
- `metadata?`: Custom key-value data
|
|
94
|
+
|
|
95
|
+
### `client.getOrCreateSession(meta?)`
|
|
96
|
+
|
|
97
|
+
Extract session ID from MCP request metadata, or generate a new one. If a new session is generated, automatically tracks a `session.started` event.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
// In your MCP tool handler
|
|
101
|
+
const sessionId = await client.getOrCreateSession(extra?._meta);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Looks for session ID in: `meta["openai/sessionId"]`, `meta.sessionId`, or `meta.conversationId`.
|
|
105
|
+
|
|
106
|
+
## Configuration
|
|
107
|
+
|
|
108
|
+
| Option | Environment Variable | Default |
|
|
109
|
+
| --------- | -------------------- | -------------------------- |
|
|
110
|
+
| `apiKey` | `WANIWANI_API_KEY` | - |
|
|
111
|
+
| `baseUrl` | - | `https://app.waniwani.ai` |
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
declare class WaniWaniError extends Error {
|
|
2
|
+
status: number;
|
|
3
|
+
constructor(message: string, status: number);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
type EventType = "session.started" | "tool.called" | "quote.requested" | "quote.succeeded" | "quote.failed" | "link.clicked" | "purchase.completed";
|
|
7
|
+
type ToolType = "pricing" | "product_info" | "availability" | "support" | "other";
|
|
8
|
+
interface BaseEvent {
|
|
9
|
+
sessionId: string;
|
|
10
|
+
externalUserId?: string;
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
type TrackEvent = ({
|
|
14
|
+
eventType: "session.started";
|
|
15
|
+
} & BaseEvent) | ({
|
|
16
|
+
eventType: "tool.called";
|
|
17
|
+
toolName?: string;
|
|
18
|
+
toolType?: ToolType;
|
|
19
|
+
} & BaseEvent) | ({
|
|
20
|
+
eventType: "quote.requested";
|
|
21
|
+
} & BaseEvent) | ({
|
|
22
|
+
eventType: "quote.succeeded";
|
|
23
|
+
quoteAmount?: number;
|
|
24
|
+
quoteCurrency?: string;
|
|
25
|
+
} & BaseEvent) | ({
|
|
26
|
+
eventType: "quote.failed";
|
|
27
|
+
} & BaseEvent) | ({
|
|
28
|
+
eventType: "link.clicked";
|
|
29
|
+
linkUrl?: string;
|
|
30
|
+
} & BaseEvent) | ({
|
|
31
|
+
eventType: "purchase.completed";
|
|
32
|
+
purchaseAmount?: number;
|
|
33
|
+
purchaseCurrency?: string;
|
|
34
|
+
} & BaseEvent);
|
|
35
|
+
/**
|
|
36
|
+
* Tracking module methods for WaniWaniClient
|
|
37
|
+
*/
|
|
38
|
+
interface TrackingClient {
|
|
39
|
+
/**
|
|
40
|
+
* Track an event using the WaniWani API
|
|
41
|
+
*/
|
|
42
|
+
track: (event: TrackEvent) => Promise<{
|
|
43
|
+
eventId: string;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Extract session ID from MCP request metadata, or generate a new one.
|
|
47
|
+
* If a new session ID is generated, automatically tracks a session.started event.
|
|
48
|
+
*
|
|
49
|
+
* @param meta - The _meta object from the MCP request (extra?._meta)
|
|
50
|
+
* @returns The session ID (existing or newly generated)
|
|
51
|
+
*/
|
|
52
|
+
getOrCreateSession: (meta?: Record<string, unknown>) => Promise<string>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface WaniWaniConfig {
|
|
56
|
+
/**
|
|
57
|
+
* Your MCP environment API key
|
|
58
|
+
*
|
|
59
|
+
* Defaults to process.env.WANIWANI_API_KEY if not provided
|
|
60
|
+
*
|
|
61
|
+
* To create one, visit:
|
|
62
|
+
* https://app.waniwani.com/mcp/environments
|
|
63
|
+
*/
|
|
64
|
+
apiKey?: string;
|
|
65
|
+
/**
|
|
66
|
+
* The base URL of the WaniWani API
|
|
67
|
+
*
|
|
68
|
+
* Defaults to https://app.waniwani.ai
|
|
69
|
+
*/
|
|
70
|
+
baseUrl?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* WaniWani SDK Client
|
|
74
|
+
*
|
|
75
|
+
* Extends with each module:
|
|
76
|
+
* - TrackingClient: track(), getOrCreateSession()
|
|
77
|
+
* - Future: ToolsClient, etc.
|
|
78
|
+
*/
|
|
79
|
+
interface WaniWaniClient extends TrackingClient {
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Create a WaniWani SDK client
|
|
84
|
+
*
|
|
85
|
+
* @param config - Configuration options
|
|
86
|
+
* @returns A fully typed WaniWani client
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* import { waniwani } from "@waniwani";
|
|
91
|
+
*
|
|
92
|
+
* const client = waniwani({ apiKey: "..." });
|
|
93
|
+
*
|
|
94
|
+
* await client.track({
|
|
95
|
+
* eventType: "tool.called",
|
|
96
|
+
* sessionId: "session-123",
|
|
97
|
+
* toolName: "pricing"
|
|
98
|
+
* });
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
declare function waniwani(config?: WaniWaniConfig): WaniWaniClient;
|
|
102
|
+
|
|
103
|
+
export { type EventType, type ToolType, type TrackEvent, type WaniWaniClient, type WaniWaniConfig, WaniWaniError, waniwani };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var o=class extends Error{constructor(t,s){super(t);this.status=s;this.name="WaniWaniError"}};function f(i){let{baseUrl:a,apiKey:t}=i;function s(){if(!t)throw new Error("WANIWANI_API_KEY is not set")}return{async track(e){try{s();let n=await fetch(`${a}/api/mcp/events`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(e)}),r=await n.json();if(!n.ok)throw new o(r.message??"Request failed",n.status);return{eventId:r.data.eventId}}catch(n){throw console.error("[WaniWani] Track error:",n),n}},async getOrCreateSession(e){if(e){let r=e["openai/sessionId"]||e.sessionId||e.conversationId;if(typeof r=="string"&&r.length>0)return r}let n=crypto.randomUUID();return await this.track({eventType:"session.started",sessionId:n}),n}}}function y(i){let a=i?.baseUrl??"https://app.waniwani.ai",t=i?.apiKey??process.env.WANIWANI_API_KEY;return{...f({baseUrl:a,apiKey:t})}}export{o as WaniWaniError,y as waniwani};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/error.ts","../src/tracking/index.ts","../src/waniwani.ts"],"sourcesContent":["// WaniWani SDK - Errors\n\nexport class WaniWaniError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic status: number,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"WaniWaniError\";\n\t}\n}\n","// Tracking Module\n\nimport { WaniWaniError } from \"../error.js\";\nimport type { InternalConfig } from \"../types.js\";\nimport type { TrackEvent, TrackingClient } from \"./@types.js\";\n\n// Re-export types\nexport type {\n\tEventType,\n\tToolType,\n\tTrackEvent,\n\tTrackingClient,\n} from \"./@types.js\";\n\nexport function createTrackingClient(config: InternalConfig): TrackingClient {\n\tconst { baseUrl, apiKey } = config;\n\n\tfunction checkIfApiKeyIsSet() {\n\t\tif (!apiKey) {\n\t\t\tthrow new Error(\"WANIWANI_API_KEY is not set\");\n\t\t}\n\t}\n\n\treturn {\n\t\tasync track(event: TrackEvent): Promise<{ eventId: string }> {\n\t\t\ttry {\n\t\t\t\tcheckIfApiKeyIsSet();\n\n\t\t\t\tconst response = await fetch(`${baseUrl}/api/mcp/events`, {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t\tAuthorization: `Bearer ${apiKey}`,\n\t\t\t\t\t},\n\t\t\t\t\tbody: JSON.stringify(event),\n\t\t\t\t});\n\n\t\t\t\tconst data = await response.json();\n\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tthrow new WaniWaniError(\n\t\t\t\t\t\tdata.message ?? \"Request failed\",\n\t\t\t\t\t\tresponse.status,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn { eventId: data.data.eventId };\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\"[WaniWani] Track error:\", error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\n\t\tasync getOrCreateSession(meta?: Record<string, unknown>): Promise<string> {\n\t\t\tif (meta) {\n\t\t\t\tconst sessionId =\n\t\t\t\t\tmeta[\"openai/sessionId\"] || meta.sessionId || meta.conversationId;\n\t\t\t\tif (typeof sessionId === \"string\" && sessionId.length > 0) {\n\t\t\t\t\treturn sessionId;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst sessionId = crypto.randomUUID();\n\t\t\tawait this.track({ eventType: \"session.started\", sessionId });\n\t\t\treturn sessionId;\n\t\t},\n\t};\n}\n","// WaniWani SDK - Main Entry\n\nimport { createTrackingClient } from \"./tracking/index.js\";\nimport type { WaniWaniClient, WaniWaniConfig } from \"./types.js\";\n\n/**\n * Create a WaniWani SDK client\n *\n * @param config - Configuration options\n * @returns A fully typed WaniWani client\n *\n * @example\n * ```typescript\n * import { waniwani } from \"@waniwani\";\n *\n * const client = waniwani({ apiKey: \"...\" });\n *\n * await client.track({\n * eventType: \"tool.called\",\n * sessionId: \"session-123\",\n * toolName: \"pricing\"\n * });\n * ```\n */\nexport function waniwani(config?: WaniWaniConfig): WaniWaniClient {\n\tconst baseUrl = config?.baseUrl ?? \"https://app.waniwani.ai\";\n\tconst apiKey = config?.apiKey ?? process.env.WANIWANI_API_KEY;\n\n\tconst internalConfig = { baseUrl, apiKey };\n\n\t// Compose client from modules\n\tconst tracking = createTrackingClient(internalConfig);\n\n\treturn {\n\t\t...tracking,\n\t\t// Future modules will be spread here\n\t\t// ...tools,\n\t};\n}\n"],"mappings":"AAEO,IAAMA,EAAN,cAA4B,KAAM,CACxC,YACCC,EACOC,EACN,CACD,MAAMD,CAAO,EAFN,YAAAC,EAGP,KAAK,KAAO,eACb,CACD,ECIO,SAASC,EAAqBC,EAAwC,CAC5E,GAAM,CAAE,QAAAC,EAAS,OAAAC,CAAO,EAAIF,EAE5B,SAASG,GAAqB,CAC7B,GAAI,CAACD,EACJ,MAAM,IAAI,MAAM,6BAA6B,CAE/C,CAEA,MAAO,CACN,MAAM,MAAME,EAAiD,CAC5D,GAAI,CACHD,EAAmB,EAEnB,IAAME,EAAW,MAAM,MAAM,GAAGJ,CAAO,kBAAmB,CACzD,OAAQ,OACR,QAAS,CACR,eAAgB,mBAChB,cAAe,UAAUC,CAAM,EAChC,EACA,KAAM,KAAK,UAAUE,CAAK,CAC3B,CAAC,EAEKE,EAAO,MAAMD,EAAS,KAAK,EAEjC,GAAI,CAACA,EAAS,GACb,MAAM,IAAIE,EACTD,EAAK,SAAW,iBAChBD,EAAS,MACV,EAGD,MAAO,CAAE,QAASC,EAAK,KAAK,OAAQ,CACrC,OAASE,EAAO,CACf,cAAQ,MAAM,0BAA2BA,CAAK,EACxCA,CACP,CACD,EAEA,MAAM,mBAAmBC,EAAiD,CACzE,GAAIA,EAAM,CACT,IAAMC,EACLD,EAAK,kBAAkB,GAAKA,EAAK,WAAaA,EAAK,eACpD,GAAI,OAAOC,GAAc,UAAYA,EAAU,OAAS,EACvD,OAAOA,CAET,CAEA,IAAMA,EAAY,OAAO,WAAW,EACpC,aAAM,KAAK,MAAM,CAAE,UAAW,kBAAmB,UAAAA,CAAU,CAAC,EACrDA,CACR,CACD,CACD,CC3CO,SAASC,EAASC,EAAyC,CACjE,IAAMC,EAAUD,GAAQ,SAAW,0BAC7BE,EAASF,GAAQ,QAAU,QAAQ,IAAI,iBAO7C,MAAO,CACN,GAHgBG,EAHM,CAAE,QAAAF,EAAS,OAAAC,CAAO,CAGW,CAMpD,CACD","names":["WaniWaniError","message","status","createTrackingClient","config","baseUrl","apiKey","checkIfApiKeyIsSet","event","response","data","WaniWaniError","error","meta","sessionId","waniwani","config","baseUrl","apiKey","createTrackingClient"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@waniwani/sdk",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "WaniWani SDK - MCP event tracking and tools",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "rm -rf dist && npm run typecheck && npm run lint && tsup",
|
|
17
|
+
"dev": "tsx --watch src/index.ts",
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"lint": "biome check .",
|
|
20
|
+
"lint:fix": "biome check . --write",
|
|
21
|
+
"prepublishOnly": "npm run build",
|
|
22
|
+
"release": "npm version patch && npm publish --access public",
|
|
23
|
+
"release:minor": "npm version minor && npm publish --access public",
|
|
24
|
+
"release:major": "npm version major && npm publish --access public"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@biomejs/biome": "^2.3.13",
|
|
28
|
+
"@types/node": "^22.10.0",
|
|
29
|
+
"tsup": "^8.3.5",
|
|
30
|
+
"tsx": "^4.19.2",
|
|
31
|
+
"typescript": "^5.7.3"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/WaniWani-AI/sdk"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"sdk",
|
|
39
|
+
"mcp",
|
|
40
|
+
"waniwani",
|
|
41
|
+
"tracking",
|
|
42
|
+
"events",
|
|
43
|
+
"tools"
|
|
44
|
+
],
|
|
45
|
+
"author": "WaniWani",
|
|
46
|
+
"license": "MIT"
|
|
47
|
+
}
|