@waniwani/sdk 0.12.8 → 0.12.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waniwani/sdk",
3
- "version": "0.12.8",
3
+ "version": "0.12.9",
4
4
  "description": "MCP distribution SDK. Build sales funnels, lead generation, booking, and quote apps on top of your MCP server. Event tracking, flows, widgets, knowledge base.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,145 +0,0 @@
1
- import { UIMessage } from 'ai';
2
- import { ContentBlock } from '@modelcontextprotocol/sdk/types.js';
3
-
4
- declare class WaniWaniError extends Error {
5
- status: number;
6
- constructor(message: string, status: number);
7
- }
8
-
9
- type ModelContextContentBlock = ContentBlock;
10
- type ModelContextUpdate = {
11
- content?: ModelContextContentBlock[];
12
- structuredContent?: Record<string, unknown>;
13
- };
14
-
15
- /**
16
- * Server-side geolocation extracted from platform headers (Vercel, Cloudflare).
17
- * All fields are optional — in local dev, no headers are present.
18
- */
19
- interface GeoLocation {
20
- city?: string;
21
- country?: string;
22
- countryRegion?: string;
23
- latitude?: string;
24
- longitude?: string;
25
- timezone?: string;
26
- ip?: string;
27
- }
28
- /**
29
- * Extracts geolocation from server-side request headers.
30
- *
31
- * Supports Vercel (`x-vercel-ip-*`), Cloudflare (`cf-ip*`, `cf-connecting-ip`),
32
- * and generic IP headers (`x-real-ip`, `x-forwarded-for`).
33
- *
34
- * Returns a `GeoLocation` with all fields optional (empty object in local dev).
35
- */
36
- declare function extractGeoFromHeaders(request: Request): GeoLocation;
37
-
38
- /** Client-side visitor context sent in the request body */
39
- interface ClientVisitorContext {
40
- timezone: string;
41
- language: string;
42
- languages: string[];
43
- deviceType: "mobile" | "tablet" | "desktop";
44
- referrer: string;
45
- visitorId: string;
46
- }
47
- /** Combined visitor context: server geo + client context */
48
- interface VisitorMeta {
49
- geo: GeoLocation;
50
- client: ClientVisitorContext | null;
51
- }
52
- interface BeforeRequestContext {
53
- /** The conversation messages from the client */
54
- messages: UIMessage[];
55
- /** Session identifier for conversation continuity */
56
- sessionId?: string;
57
- /** Hidden widget-provided model context for the next assistant turn */
58
- modelContext?: ModelContextUpdate;
59
- /** The original HTTP Request object */
60
- request: Request;
61
- /** Server-extracted geo location + client-provided visitor context */
62
- visitor: VisitorMeta;
63
- }
64
- type BeforeRequestResult = {
65
- /** Override messages (e.g., filtered, augmented) */
66
- messages?: UIMessage[];
67
- /** Override the system prompt for this request */
68
- systemPrompt?: string;
69
- /** Override sessionId */
70
- sessionId?: string;
71
- /** Override hidden widget-provided model context */
72
- modelContext?: ModelContextUpdate;
73
- };
74
- interface WebSearchConfig {
75
- /** Restrict web search results to these domains */
76
- includeDomains?: string[];
77
- /** Exclude these domains from web search results */
78
- excludeDomains?: string[];
79
- }
80
- interface ApiHandlerOptions {
81
- /**
82
- * Identifies this chatbar instance in analytics.
83
- * Forwarded as `waniwani/source` in MCP request metadata.
84
- */
85
- source?: string;
86
- /**
87
- * Your WaniWani API key.
88
- * Defaults to process.env.WANIWANI_API_KEY.
89
- */
90
- apiKey?: string;
91
- /**
92
- * The base URL of the WaniWani API.
93
- * Defaults to https://app.waniwani.ai.
94
- */
95
- apiUrl?: string;
96
- /**
97
- * System prompt for the assistant.
98
- * Can be overridden per-request via `beforeRequest`.
99
- */
100
- systemPrompt?: string;
101
- /**
102
- * Maximum number of tool call steps. Defaults to 5.
103
- */
104
- maxSteps?: number;
105
- /**
106
- * Hook called before each request is forwarded to the WaniWani API.
107
- * - Return void to use defaults.
108
- * - Return an object to override messages, systemPrompt, or sessionId.
109
- * - Throw to reject the request (the error message is returned as JSON).
110
- */
111
- beforeRequest?: (context: BeforeRequestContext) => Promise<BeforeRequestResult | undefined> | BeforeRequestResult | undefined;
112
- /**
113
- * Override the MCP server URL directly, bypassing config resolution.
114
- * Useful for development/testing when pointing to a local MCP server.
115
- */
116
- mcpServerUrl?: string;
117
- /**
118
- * Enable verbose debug logging for all handler steps.
119
- * Logs request details, response codes, resolved URLs, and caught errors.
120
- */
121
- debug?: boolean;
122
- /**
123
- * Enable web search as an additional tool alongside MCP tools.
124
- * Pass `true` to enable with defaults, or a config object to restrict domains.
125
- */
126
- webSearch?: boolean | WebSearchConfig;
127
- }
128
- interface ApiHandler {
129
- /** Proxies chat messages to the WaniWani API */
130
- handleChat: (request: Request) => Promise<Response>;
131
- /** Serves MCP resource content (HTML widgets) */
132
- handleResource: (url: URL) => Promise<Response>;
133
- /** Calls an MCP server tool and returns JSON */
134
- handleTool: (request: Request) => Promise<Response>;
135
- /** Routes GET sub-paths (e.g. /resource) */
136
- routeGet: (request: Request) => Promise<Response>;
137
- /** Routes POST sub-paths (e.g. /tool), defaults to chat */
138
- routePost: (request: Request) => Promise<Response>;
139
- /** Routes PATCH sub-paths (e.g. /scenarios/:id) */
140
- routePatch: (request: Request) => Promise<Response>;
141
- /** Handles CORS preflight requests */
142
- handleOptions: () => Response;
143
- }
144
-
145
- export { type ApiHandler, type ApiHandlerOptions, type BeforeRequestContext, type BeforeRequestResult, type ClientVisitorContext, type GeoLocation, type VisitorMeta, WaniWaniError, type WebSearchConfig, extractGeoFromHeaders };
@@ -1,84 +0,0 @@
1
- interface SearchResult {
2
- source: string;
3
- heading: string;
4
- content: string;
5
- score: number;
6
- metadata?: Record<string, string>;
7
- }
8
- /** A file to ingest into the knowledge base */
9
- interface KbIngestFile {
10
- /** Filename (used as chunk source identifier) */
11
- filename: string;
12
- /** Markdown content of the file */
13
- content: string;
14
- /** Arbitrary key-value metadata attached to all chunks from this file */
15
- metadata?: Record<string, string>;
16
- }
17
- /** Response from the ingest endpoint */
18
- interface KbIngestResult {
19
- /** Number of chunks created from the ingested files */
20
- chunksIngested: number;
21
- /** Number of files successfully processed */
22
- filesProcessed: number;
23
- }
24
- /** Options for the search method */
25
- interface KbSearchOptions {
26
- /** Number of results to return (1-20, default 5) */
27
- topK?: number;
28
- /** Minimum similarity score threshold (0-1, default 0.3) */
29
- minScore?: number;
30
- /** Filter results to chunks whose metadata contains all these key-value pairs (exact match) */
31
- metadata?: Record<string, string>;
32
- }
33
- /** A source entry in the knowledge base */
34
- interface KbSource {
35
- /** Source filename */
36
- source: string;
37
- /** Number of chunks from this source */
38
- chunkCount: number;
39
- /** ISO timestamp of when the source was first ingested */
40
- createdAt: string;
41
- }
42
- /** KB client for server-side knowledge base operations */
43
- interface KbClient {
44
- /**
45
- * Ingest files into the knowledge base.
46
- *
47
- * **Warning**: This is destructive — it deletes ALL existing chunks
48
- * for the environment before ingesting the new files.
49
- */
50
- ingest(files: KbIngestFile[]): Promise<KbIngestResult>;
51
- /** Search the knowledge base for relevant chunks */
52
- search(query: string, options?: KbSearchOptions): Promise<SearchResult[]>;
53
- /** List all sources in the knowledge base */
54
- sources(): Promise<KbSource[]>;
55
- }
56
-
57
- interface TrackingConfig {
58
- /** Events API V2 endpoint path. */
59
- endpointPath?: string;
60
- /** Periodic flush interval for buffered events. */
61
- flushIntervalMs?: number;
62
- /** Max events per HTTP batch send. */
63
- maxBatchSize?: number;
64
- /** Max in-memory buffer size before oldest items are dropped. */
65
- maxBufferSize?: number;
66
- /** Number of retries for retryable failures. */
67
- maxRetries?: number;
68
- /** Retry backoff base delay. */
69
- retryBaseDelayMs?: number;
70
- /** Retry backoff max delay. */
71
- retryMaxDelayMs?: number;
72
- /** Default shutdown timeout when none is provided. */
73
- shutdownTimeoutMs?: number;
74
- }
75
-
76
- interface InternalConfig {
77
- apiUrl: string;
78
- apiKey: string | undefined;
79
- tracking: Required<TrackingConfig>;
80
- }
81
-
82
- declare function createKbClient(config: InternalConfig): KbClient;
83
-
84
- export { type KbClient, type KbIngestFile, type KbIngestResult, type KbSearchOptions, type KbSource, type SearchResult, createKbClient };