@waniwani/sdk 0.18.0 → 0.19.1

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.
@@ -143,7 +143,7 @@ interface KbClient {
143
143
  * first-class names at runtime (the widget transport passes these through
144
144
  * verbatim instead of namespacing them as custom widget events).
145
145
  */
146
- declare const EVENT_TYPES: readonly ["session.started", "page.viewed", "tool.called", "quote.requested", "quote.succeeded", "quote.failed", "link.clicked", "purchase.completed", "widget_render", "user.identified", "price_shown", "prices_compared", "option_selected", "lead_qualified", "converted"];
146
+ declare const EVENT_TYPES: readonly ["session.started", "page.viewed", "tool.called", "link.clicked", "widget_render", "user.identified", "price_shown", "prices_compared", "option_selected", "lead_qualified", "converted"];
147
147
  type EventType = (typeof EVENT_TYPES)[number];
148
148
  /**
149
149
  * Properties for `page.viewed` — emitted once when the chat widget initializes
@@ -172,17 +172,9 @@ interface ToolCalledProperties {
172
172
  /** Retrieval traces for kb.search() calls made inside this tool handler. */
173
173
  kbSearch?: KbSearchTrace[];
174
174
  }
175
- interface QuoteSucceededProperties {
176
- amount?: number;
177
- currency?: string;
178
- }
179
175
  interface LinkClickedProperties {
180
176
  url?: string;
181
177
  }
182
- interface PurchaseCompletedProperties {
183
- amount?: number;
184
- currency?: string;
185
- }
186
178
  interface PriceShownProperties {
187
179
  amount: number;
188
180
  currency: string;
@@ -269,19 +261,9 @@ type TrackEvent = ({
269
261
  } & BaseTrackEvent) | ({
270
262
  event: "tool.called";
271
263
  properties?: ToolCalledProperties;
272
- } & BaseTrackEvent) | ({
273
- event: "quote.requested";
274
- } & BaseTrackEvent) | ({
275
- event: "quote.succeeded";
276
- properties?: QuoteSucceededProperties;
277
- } & BaseTrackEvent) | ({
278
- event: "quote.failed";
279
264
  } & BaseTrackEvent) | ({
280
265
  event: "link.clicked";
281
266
  properties?: LinkClickedProperties;
282
- } & BaseTrackEvent) | ({
283
- event: "purchase.completed";
284
- properties?: PurchaseCompletedProperties;
285
267
  } & BaseTrackEvent) | ({
286
268
  event: "user.identified";
287
269
  } & BaseTrackEvent) | ({
@@ -310,11 +292,7 @@ interface LegacyTrackEvent extends TrackingContext {
310
292
  properties?: Record<string, unknown>;
311
293
  toolName?: string;
312
294
  toolType?: ToolCalledProperties["type"];
313
- quoteAmount?: number;
314
- quoteCurrency?: string;
315
295
  linkUrl?: string;
316
- purchaseAmount?: number;
317
- purchaseCurrency?: string;
318
296
  }
319
297
  /**
320
298
  * Public track input accepted by `client.track()`.
@@ -435,6 +413,21 @@ interface ScopedWaniWaniClient {
435
413
  * `sessionId` later). `undefined` when the host provided no session id.
436
414
  */
437
415
  readonly sessionId?: string;
416
+ /**
417
+ * The anonymous visitor id, resolved from the request meta. Present on the
418
+ * web chat surface (a persisted per-device id threaded through as
419
+ * `waniwani/visitorId`); `undefined` on hosts that do not supply one, such
420
+ * as Claude. Ingest accepts it as an identity in its own right, so use it
421
+ * to correlate events before a session or user id exists.
422
+ */
423
+ readonly visitorId?: string;
424
+ /**
425
+ * The external user id, resolved from the request meta (e.g. `openai/userId`
426
+ * for ChatGPT's anonymous users, or a host-provided `externalUserId`). Read
427
+ * it alongside `sessionId`/`visitorId` — whichever the current host provides.
428
+ * `undefined` when the host supplied no user id.
429
+ */
430
+ readonly externalUserId?: string;
438
431
  /**
439
432
  * Track an event — request meta is automatically merged. Also exposes the
440
433
  * revenue helpers flat (`track.priceShown()`, `track.converted()`, …), which
@@ -1436,6 +1429,14 @@ type DeepPartial<T> = T extends (...args: never[]) => unknown ? T : T extends ob
1436
1429
  } : T;
1437
1430
  type MessageOverrides = DeepPartial<Messages>;
1438
1431
 
1432
+ /**
1433
+ * A visitor id to apply, or a resolver that produces one. The resolver may be
1434
+ * sync (`() => posthog.get_distinct_id()`) or async
1435
+ * (`async () => (await sdk.ready()).id`), for analytics SDKs whose id is only
1436
+ * available after they bootstrap.
1437
+ */
1438
+ type VisitorIdInput = string | (() => string | undefined | null | Promise<string | undefined | null>);
1439
+
1439
1440
  /**
1440
1441
  * Built-in theme presets. `auto` follows the host's `prefers-color-scheme`
1441
1442
  * and switches at runtime without re-rendering.
@@ -1538,6 +1539,15 @@ interface WelcomeConfig {
1538
1539
  /** Suggestion cards shown in the welcome screen. Disappear after the first message. */
1539
1540
  suggestions?: string[];
1540
1541
  }
1542
+ /** Where a suggestion pill came from. */
1543
+ /**
1544
+ * Every place a suggestion pill can come from. The single source of truth:
1545
+ * {@link SuggestionOrigin} derives from it, and runtime validation reads it,
1546
+ * so adding an origin is a one-line change.
1547
+ */
1548
+ declare const SUGGESTION_ORIGINS: readonly ["channel", "page", "flow", "followup"];
1549
+ /** Where a suggestion pill came from. */
1550
+ type SuggestionOrigin = (typeof SUGGESTION_ORIGINS)[number];
1541
1551
  interface SuggestionsConfig {
1542
1552
  /**
1543
1553
  * Initial suggestions to show before the user sends their first message.
@@ -1545,8 +1555,14 @@ interface SuggestionsConfig {
1545
1555
  */
1546
1556
  initial?: string[];
1547
1557
  /**
1548
- * Enable AI-generated suggestions after each response.
1549
- * Defaults to `true` when suggestions config is provided.
1558
+ * Which providers may fill the pill row. Omitted, this defaults to
1559
+ * `["channel", "page", "followup"]`: starter prompts and generated
1560
+ * follow-ups render, flow-driven pills stay opt-in.
1561
+ */
1562
+ origins?: SuggestionOrigin[];
1563
+ /**
1564
+ * @deprecated Use `origins`. `true` maps to every origin, `false` to none.
1565
+ * Will be removed in a future minor release.
1550
1566
  */
1551
1567
  dynamic?: boolean;
1552
1568
  }
@@ -1594,6 +1610,21 @@ interface ChatBaseProps {
1594
1610
  appearance?: ChatAppearance;
1595
1611
  /** Per-slot class name overrides. See {@link ChatClassNames}. */
1596
1612
  classNames?: ChatClassNames;
1613
+ /**
1614
+ * Override the anonymous visitor id the widget generates with one you
1615
+ * already track (a PostHog / Amplitude / Segment distinct id, your own
1616
+ * cookie, etc.). The chat sends it on every request, so Waniwani sessions
1617
+ * and events correlate to the same visitor, and server-side MCP tools and
1618
+ * flows read it back as `context.waniwani.visitorId`.
1619
+ *
1620
+ * A string, or a resolver that returns one — sync
1621
+ * (`() => posthog.get_distinct_id()`) or async
1622
+ * (`async () => (await sdk.ready()).id`), for analytics SDKs whose id is
1623
+ * only ready after they bootstrap. A blank / failed result is ignored, so
1624
+ * the auto-generated, `localStorage`-persisted id is kept. Leave unset to
1625
+ * always use the auto id.
1626
+ */
1627
+ visitorId?: VisitorIdInput;
1597
1628
  /** Additional headers to send with chat API requests */
1598
1629
  headers?: Record<string, string>;
1599
1630
  /** Additional body fields to send with each chat request */
@@ -1613,8 +1644,11 @@ interface ChatBaseProps {
1613
1644
  /** Callback fired when a response is received */
1614
1645
  onResponseReceived?: () => void;
1615
1646
  /**
1616
- * Enable AI-generated suggestions after each response.
1617
- * `true` enables with defaults (3 suggestions), object allows config, `false`/undefined disables.
1647
+ * Suggestion pill configuration. Unset: no suggestions. An object sets
1648
+ * starter prompts (`initial`) and which origins may fill the per-turn
1649
+ * pill row (`origins`); `origins: ["flow"]` (or any list including
1650
+ * `"flow"`) opts into flow-driven pills. `true` enables every origin with
1651
+ * defaults; `false` hides the pill row entirely.
1618
1652
  */
1619
1653
  suggestions?: boolean | SuggestionsConfig;
1620
1654
  /**