@waniwani/sdk 0.17.1 → 0.17.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/dist/chat/embed.js +93 -93
- package/dist/chat/embed.js.map +1 -1
- package/dist/chat/index.d.ts +100 -1
- package/dist/chat/index.js +7 -7
- package/dist/chat/index.js.map +1 -1
- package/dist/legacy/index.d.ts +23 -0
- package/dist/legacy/index.js +13 -13
- package/dist/legacy/index.js.map +1 -1
- package/package.json +1 -1
package/dist/chat/index.d.ts
CHANGED
|
@@ -336,6 +336,64 @@ type DeepPartial<T> = T extends (...args: never[]) => unknown ? T : T extends ob
|
|
|
336
336
|
} : T;
|
|
337
337
|
type MessageOverrides = DeepPartial<Messages>;
|
|
338
338
|
|
|
339
|
+
/**
|
|
340
|
+
* A visitor id to apply, or a resolver that produces one. The resolver may be
|
|
341
|
+
* sync (`() => posthog.get_distinct_id()`) or async
|
|
342
|
+
* (`async () => (await sdk.ready()).id`), for analytics SDKs whose id is only
|
|
343
|
+
* available after they bootstrap.
|
|
344
|
+
*/
|
|
345
|
+
type VisitorIdInput = string | (() => string | undefined | null | Promise<string | undefined | null>);
|
|
346
|
+
|
|
347
|
+
/** Surface the widget is mounted on. */
|
|
348
|
+
type WidgetMode = "inline" | "floating";
|
|
349
|
+
interface WidgetEventBase {
|
|
350
|
+
/** Surface the widget is mounted on. */
|
|
351
|
+
mode: WidgetMode;
|
|
352
|
+
/**
|
|
353
|
+
* Conversation session id, when one exists. Assigned on the first
|
|
354
|
+
* exchange, so it is `undefined` for events that precede it.
|
|
355
|
+
*/
|
|
356
|
+
sessionId?: string;
|
|
357
|
+
/** Epoch milliseconds at emit time. */
|
|
358
|
+
timestamp: number;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Per-event discriminant and extra properties. Events in the first branch
|
|
362
|
+
* carry no `properties` object.
|
|
363
|
+
*/
|
|
364
|
+
type WidgetEventDetail = {
|
|
365
|
+
name: "chat.ready" | "chat.opened" | "chat.closed" | "message.sent" | "message.received";
|
|
366
|
+
} | {
|
|
367
|
+
name: "session.started";
|
|
368
|
+
properties: {
|
|
369
|
+
sessionId: string;
|
|
370
|
+
};
|
|
371
|
+
} | {
|
|
372
|
+
name: "thread.changed";
|
|
373
|
+
properties: {
|
|
374
|
+
threadId: string;
|
|
375
|
+
};
|
|
376
|
+
} | {
|
|
377
|
+
name: "chat.error";
|
|
378
|
+
properties: {
|
|
379
|
+
message: string;
|
|
380
|
+
};
|
|
381
|
+
} | {
|
|
382
|
+
name: "suggestion.clicked";
|
|
383
|
+
properties: {
|
|
384
|
+
text: string;
|
|
385
|
+
index: number;
|
|
386
|
+
};
|
|
387
|
+
} | {
|
|
388
|
+
name: "link.clicked";
|
|
389
|
+
properties: {
|
|
390
|
+
url: string;
|
|
391
|
+
};
|
|
392
|
+
};
|
|
393
|
+
/** Payload handed to `onEvent` subscribers. Discriminated on `name`. */
|
|
394
|
+
type WidgetEvent = WidgetEventBase & WidgetEventDetail;
|
|
395
|
+
type WidgetEventName = WidgetEventDetail["name"];
|
|
396
|
+
|
|
339
397
|
/**
|
|
340
398
|
* Built-in theme presets. `auto` follows the host's `prefers-color-scheme`
|
|
341
399
|
* and switches at runtime without re-rendering.
|
|
@@ -494,6 +552,21 @@ interface ChatBaseProps {
|
|
|
494
552
|
appearance?: ChatAppearance;
|
|
495
553
|
/** Per-slot class name overrides. See {@link ChatClassNames}. */
|
|
496
554
|
classNames?: ChatClassNames;
|
|
555
|
+
/**
|
|
556
|
+
* Override the anonymous visitor id the widget generates with one you
|
|
557
|
+
* already track (a PostHog / Amplitude / Segment distinct id, your own
|
|
558
|
+
* cookie, etc.). The chat sends it on every request, so Waniwani sessions
|
|
559
|
+
* and events correlate to the same visitor, and server-side MCP tools and
|
|
560
|
+
* flows read it back as `context.waniwani.visitorId`.
|
|
561
|
+
*
|
|
562
|
+
* A string, or a resolver that returns one — sync
|
|
563
|
+
* (`() => posthog.get_distinct_id()`) or async
|
|
564
|
+
* (`async () => (await sdk.ready()).id`), for analytics SDKs whose id is
|
|
565
|
+
* only ready after they bootstrap. A blank / failed result is ignored, so
|
|
566
|
+
* the auto-generated, `localStorage`-persisted id is kept. Leave unset to
|
|
567
|
+
* always use the auto id.
|
|
568
|
+
*/
|
|
569
|
+
visitorId?: VisitorIdInput;
|
|
497
570
|
/** Additional headers to send with chat API requests */
|
|
498
571
|
headers?: Record<string, string>;
|
|
499
572
|
/** Additional body fields to send with each chat request */
|
|
@@ -945,6 +1018,22 @@ interface WaniwaniChatProps {
|
|
|
945
1018
|
token: string;
|
|
946
1019
|
/** Agent channel ID — routes the conversation to the right agent. */
|
|
947
1020
|
channelId?: string;
|
|
1021
|
+
/**
|
|
1022
|
+
* Override the anonymous visitor id the widget generates with one you
|
|
1023
|
+
* already track (a PostHog / Amplitude / Segment distinct id, your own
|
|
1024
|
+
* cookie, etc.). The chat sends it on every request, so Waniwani sessions
|
|
1025
|
+
* and events correlate to the same visitor, and server-side MCP tools and
|
|
1026
|
+
* flows read it back as `context.waniwani.visitorId`.
|
|
1027
|
+
*
|
|
1028
|
+
* A string, or a resolver that returns one — sync
|
|
1029
|
+
* (`() => posthog.get_distinct_id()`) or async
|
|
1030
|
+
* (`async () => (await sdk.ready()).id`), for analytics SDKs whose id is only
|
|
1031
|
+
* ready after they bootstrap. Read live on each request, so updating it
|
|
1032
|
+
* applies to the next message. A blank / failed result is ignored, keeping
|
|
1033
|
+
* the auto-generated, `localStorage`-persisted id. Leave unset to always use
|
|
1034
|
+
* the auto id.
|
|
1035
|
+
*/
|
|
1036
|
+
visitorId?: VisitorIdInput;
|
|
948
1037
|
/** Additional class names applied to the root element. */
|
|
949
1038
|
className?: string;
|
|
950
1039
|
/**
|
|
@@ -954,6 +1043,16 @@ interface WaniwaniChatProps {
|
|
|
954
1043
|
* can't be serialized to the dashboard).
|
|
955
1044
|
*/
|
|
956
1045
|
overrides?: WaniwaniChatOverrides;
|
|
1046
|
+
/**
|
|
1047
|
+
* Callback fired on chat lifecycle events (`chat.ready`, `message.sent`,
|
|
1048
|
+
* `message.received`, `session.started`, `thread.changed`, `chat.error`,
|
|
1049
|
+
* `suggestion.clicked`, `link.clicked`; `chat.opened`/`chat.closed` are
|
|
1050
|
+
* floating-embed-only and never fire here). Message events never include
|
|
1051
|
+
* the message text. Use it to mirror widget activity into the host page's
|
|
1052
|
+
* analytics. Exceptions thrown by the callback are swallowed and never
|
|
1053
|
+
* break the chat.
|
|
1054
|
+
*/
|
|
1055
|
+
onEvent?: (event: WidgetEvent) => void;
|
|
957
1056
|
}
|
|
958
1057
|
declare const WaniwaniChat: react.ForwardRefExoticComponent<WaniwaniChatProps & react.RefAttributes<ChatHandle>>;
|
|
959
1058
|
|
|
@@ -969,4 +1068,4 @@ declare function mergeTheme(userTheme?: ChatTheme): Required<ChatTheme>;
|
|
|
969
1068
|
*/
|
|
970
1069
|
declare function themeToCSSProperties(theme: ChatTheme): Record<string, string>;
|
|
971
1070
|
|
|
972
|
-
export { type ChatAppearance, type ChatBaseProps, ChatCard, type ChatCardProps, ChatEmbed, type ChatEmbedMcpConfig, type ChatEmbedProps, type ChatHandle, type ChatTheme, DARK_THEME, DEFAULT_THEME, type McpAppDisplayMode, McpAppFrame, type McpAppFrameProps, type ShowToolCalls, type SuggestionsConfig, type ThemePreset, WaniwaniChat, type WaniwaniChatOverrides, type WaniwaniChatProps, type WelcomeConfig, mergeTheme, themeToCSSProperties };
|
|
1071
|
+
export { type ChatAppearance, type ChatBaseProps, ChatCard, type ChatCardProps, ChatEmbed, type ChatEmbedMcpConfig, type ChatEmbedProps, type ChatHandle, type ChatTheme, DARK_THEME, DEFAULT_THEME, type McpAppDisplayMode, McpAppFrame, type McpAppFrameProps, type ShowToolCalls, type SuggestionsConfig, type ThemePreset, WaniwaniChat, type WaniwaniChatOverrides, type WaniwaniChatProps, type WelcomeConfig, type WidgetEvent, type WidgetEventName, type WidgetMode, mergeTheme, themeToCSSProperties };
|